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
pull/15517/head
Alyssa Haroldsen 10 months ago committed by Copybara-Service
parent 022730e43c
commit 02c675e99e
  1. 25
      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()) }
)
}

Loading…
Cancel
Save