From 24dfcacc687de419f14b5645a69c685d20746749 Mon Sep 17 00:00:00 2001 From: Jakob Buchgraber Date: Thu, 16 Nov 2023 04:24:14 -0800 Subject: [PATCH] Minimize the scope of unsafe blocks in gencode Before this change we would generate nested unsafe blocks that led to compiler warnings. This change minimizes each unsafe block and thereby avoids the nesting and compiler warnings. It's generally a best practice to keep unsafe blocks minimal to avoid the situation where a currently safe function is marked unsafe at a later point and all existing callsides don't need to be updated. PiperOrigin-RevId: 582993146 --- .../protobuf/compiler/rust/accessors/singular_string.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/google/protobuf/compiler/rust/accessors/singular_string.cc b/src/google/protobuf/compiler/rust/accessors/singular_string.cc index cff20e0b44..f3ae1e2f49 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_string.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_string.cc @@ -52,14 +52,12 @@ void SingularString::InMsgImpl(Context field) const { {"transform_view", transform_view}}, R"rs( pub fn $field$_opt(&self) -> $pb$::Optional<&$proxied_type$> { - unsafe { - let view = $getter_thunk$(self.inner.msg).as_ref(); + let view = unsafe { $getter_thunk$(self.inner.msg).as_ref() }; $pb$::Optional::new( $transform_view$ , - $hazzer_thunk$(self.inner.msg) + unsafe { $hazzer_thunk$(self.inner.msg) } ) } - } )rs"); }}, {"field_mutator_getter",