Skip to content

Commit

Permalink
Cleanup mutable thunk usage in singular_message
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 588482350
  • Loading branch information
honglooker authored and copybara-github committed Dec 6, 2023
1 parent a74c3bb commit 69c75b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
[&] {
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion src/google/protobuf/compiler/rust/naming.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 69c75b4

Please sign in to comment.