From 02c675e99efa0767342ba5c40760521b519e79ac Mon Sep 17 00:00:00 2001 From: Alyssa Haroldsen Date: Thu, 25 Jan 2024 11:48:22 -0800 Subject: [PATCH] Remove the space before a comma in singular_string This is done by specifying suffix punctuation to chomp with WithVars. If we delete the space on line 64 without also doing the rest of this change, the result is that the comma is not emitted at all. PiperOrigin-RevId: 601516987 --- .../rust/accessors/singular_string.cc | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/google/protobuf/compiler/rust/accessors/singular_string.cc b/src/google/protobuf/compiler/rust/accessors/singular_string.cc index 9b2a1026c1..bf742df517 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_string.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_string.cc @@ -29,17 +29,18 @@ void SingularString::InMsgImpl(Context& ctx, const FieldDescriptor& field, {"setter_thunk", ThunkName(ctx, field, "set")}, {"clearer_thunk", ThunkName(ctx, field, "clear")}, {"proxied_type", RsTypePath(ctx, field)}, - {"transform_view", - [&] { - if (field.type() == FieldDescriptor::TYPE_STRING) { - ctx.Emit(R"rs( - // SAFETY: The runtime doesn't require ProtoStr to be UTF-8. - unsafe { $pb$::ProtoStr::from_utf8_unchecked(view) } - )rs"); - } else { - ctx.Emit("view"); - } - }}, + io::Printer::Sub("transform_view", + [&] { + if (field.type() == FieldDescriptor::TYPE_STRING) { + ctx.Emit(R"rs( + // SAFETY: The runtime doesn't require ProtoStr to be UTF-8. + unsafe { $pb$::ProtoStr::from_utf8_unchecked(view) } + )rs"); + } else { + ctx.Emit("view"); + } + }) + .WithSuffix(""), // This lets `$transform_view$,` work. {"transform_field_entry", [&] { if (field.type() == FieldDescriptor::TYPE_STRING) { @@ -62,7 +63,7 @@ void SingularString::InMsgImpl(Context& ctx, const FieldDescriptor& field, pub fn $field$_opt($view_self$) -> $pb$::Optional<&$view_lifetime$ $proxied_type$> { let view = unsafe { $getter_thunk$(self.raw_msg()).as_ref() }; $pb$::Optional::new( - $transform_view$ , + $transform_view$, unsafe { $hazzer_thunk$(self.raw_msg()) } ) }