Skip to content

Commit

Permalink
Minimize the scope of unsafe blocks in gencode
Browse files Browse the repository at this point in the history
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
  • Loading branch information
buchgr authored and copybara-github committed Nov 16, 2023
1 parent ba7067c commit 24dfcac
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,12 @@ void SingularString::InMsgImpl(Context<FieldDescriptor> 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",
Expand Down

0 comments on commit 24dfcac

Please # to comment.