Use `self` accessors for accessing maps in views

This was missed by a prior change

PiperOrigin-RevId: 599822201
pull/15497/head
Alyssa Haroldsen 1 year ago committed by Copybara-Service
parent 7d508b41df
commit 457ed9b44f
  1. 1
      rust/test/nested.proto
  2. 3
      rust/test/shared/simple_nested_test.rs
  3. 10
      src/google/protobuf/compiler/rust/accessors/map.cc

@ -39,6 +39,7 @@ message Outer {
optional InnerEnum inner_enum = 17;
repeated int32 repeated_int32 = 18 [packed = true];
repeated InnerSubMsg repeated_inner_submsg = 19;
map<string, string> string_map = 20;
message SuperInner {
message DuperInner {

@ -75,6 +75,9 @@ fn test_nested_view_lifetimes() {
let repeated_inner_submsg = outer_msg.inner().repeated_inner_submsg();
assert_that!(repeated_inner_submsg, empty());
let string_map = outer_msg.inner().string_map();
assert_that!(string_map.len(), eq(0));
}
#[test]

@ -26,14 +26,16 @@ void Map::InMsgImpl(Context& ctx, const FieldDescriptor& field,
ctx.Emit({{"field", RsSafeName(field.name())},
{"Key", RsTypePath(ctx, key_type)},
{"Value", RsTypePath(ctx, value_type)},
{"view_lifetime", ViewLifetime(accessor_case)},
{"view_self", ViewReceiver(accessor_case)},
{"getter_thunk", ThunkName(ctx, field, "get")},
{"getter_mut_thunk", ThunkName(ctx, field, "get_mut")},
{"getter",
[&] {
if (ctx.is_upb()) {
ctx.Emit({}, R"rs(
pub fn $field$(&self)
-> $pb$::MapView<'_, $Key$, $Value$> {
pub fn $field$($view_self$)
-> $pb$::MapView<$view_lifetime$, $Key$, $Value$> {
unsafe {
$getter_thunk$(self.raw_msg())
.map_or_else(
@ -44,8 +46,8 @@ void Map::InMsgImpl(Context& ctx, const FieldDescriptor& field,
})rs");
} else {
ctx.Emit({}, R"rs(
pub fn $field$(&self)
-> $pb$::MapView<'_, $Key$, $Value$> {
pub fn $field$($view_self$)
-> $pb$::MapView<$view_lifetime$, $Key$, $Value$> {
unsafe {
$pb$::MapView::from_raw($pbi$::Private,
$getter_thunk$(self.raw_msg()))

Loading…
Cancel
Save