diff --git a/rust/test/nested.proto b/rust/test/nested.proto index e26f998ba1..7ca2873840 100644 --- a/rust/test/nested.proto +++ b/rust/test/nested.proto @@ -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_map = 20; message SuperInner { message DuperInner { diff --git a/rust/test/shared/simple_nested_test.rs b/rust/test/shared/simple_nested_test.rs index c56312427a..59ab4f0814 100644 --- a/rust/test/shared/simple_nested_test.rs +++ b/rust/test/shared/simple_nested_test.rs @@ -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] diff --git a/src/google/protobuf/compiler/rust/accessors/map.cc b/src/google/protobuf/compiler/rust/accessors/map.cc index 9a4031ea86..124f42d095 100644 --- a/src/google/protobuf/compiler/rust/accessors/map.cc +++ b/src/google/protobuf/compiler/rust/accessors/map.cc @@ -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()))