Cleanup mutable thunk usage in singular_message

PiperOrigin-RevId: 588482350
pull/14922/head
Hong Shin 12 months ago committed by Copybara-Service
parent a74c3bbaa4
commit 69c75b4987
  1. 6
      src/google/protobuf/compiler/rust/accessors/singular_message.cc
  2. 5
      src/google/protobuf/compiler/rust/naming.cc

@ -27,7 +27,7 @@ void SingularMessage::InMsgImpl(Context<FieldDescriptor> field) const {
{"prefix", prefix},
{"field", field.desc().name()},
{"getter_thunk", Thunk(field, "get")},
{"getter_mut_thunk", Thunk(field, "mutable")},
{"getter_mut_thunk", Thunk(field, "get_mut")},
{"clearer_thunk", Thunk(field, "clear")},
{
"view_body",
@ -91,7 +91,7 @@ void SingularMessage::InExternC(Context<FieldDescriptor> field) const {
field.Emit(
{
{"getter_thunk", Thunk(field, "get")},
{"getter_mut_thunk", Thunk(field, "mutable")},
{"getter_mut_thunk", Thunk(field, "get_mut")},
{"clearer_thunk", Thunk(field, "clear")},
{"getter_mut",
[&] {
@ -130,7 +130,7 @@ void SingularMessage::InThunkCc(Context<FieldDescriptor> field) const {
field.Emit({{"QualifiedMsg",
cpp::QualifiedClassName(field.desc().containing_type())},
{"getter_thunk", Thunk(field, "get")},
{"getter_mut_thunk", Thunk(field, "mutable")},
{"getter_mut_thunk", Thunk(field, "get_mut")},
{"clearer_thunk", Thunk(field, "clear")},
{"field", cpp::FieldName(&field.desc())}},
R"cc(

@ -84,7 +84,10 @@ std::string Thunk(Context<T> field, absl::string_view op) {
if (field.is_upb() && op == "get") {
// upb getter is simply the field name (no "get" in the name).
format = "_$1";
} else if (field.is_upb() && (op == "case")) {
} else if (field.is_upb() && op == "get_mut") {
// same as above, with with `mutable` prefix
format = "_mutable_$1";
} else if (field.is_upb() && op == "case") {
// some upb functions are in the order x_op compared to has/set/clear which
// are in the other order e.g. op_x.
format = "_$1_$0";

Loading…
Cancel
Save