Add `unsafe` keyword to unsafe block in rust code (#18264)

Closes #18264

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/18264 from tempoz:tempoz-fix-unsafe-block-rust aca540fac9
PiperOrigin-RevId: 676912529
pull/18456/head
Zoey Greer 5 months ago committed by Copybara-Service
parent ac29f8c0cd
commit 3bc5991d11
  1. 15
      src/google/protobuf/compiler/rust/message.cc

@ -285,23 +285,38 @@ void UpbGeneratedMessageTraitImpls(Context& ctx, const Descriptor& msg) {
unsafe impl $pbr$::AssociatedMiniTable for $Msg$ { unsafe impl $pbr$::AssociatedMiniTable for $Msg$ {
#[inline(always)] #[inline(always)]
fn mini_table() -> *const $pbr$::upb_MiniTable { fn mini_table() -> *const $pbr$::upb_MiniTable {
// This is unsafe only for Rust 1.80 and below and thus can be dropped
// once our MSRV is 1.81+
#[allow(unused_unsafe)]
unsafe {
$std$::ptr::addr_of!($minitable$) $std$::ptr::addr_of!($minitable$)
} }
} }
}
unsafe impl $pbr$::AssociatedMiniTable for $Msg$View<'_> { unsafe impl $pbr$::AssociatedMiniTable for $Msg$View<'_> {
#[inline(always)] #[inline(always)]
fn mini_table() -> *const $pbr$::upb_MiniTable { fn mini_table() -> *const $pbr$::upb_MiniTable {
// This is unsafe only for Rust 1.80 and below and thus can be dropped
// once our MSRV is 1.81+
#[allow(unused_unsafe)]
unsafe {
$std$::ptr::addr_of!($minitable$) $std$::ptr::addr_of!($minitable$)
} }
} }
}
unsafe impl $pbr$::AssociatedMiniTable for $Msg$Mut<'_> { unsafe impl $pbr$::AssociatedMiniTable for $Msg$Mut<'_> {
#[inline(always)] #[inline(always)]
fn mini_table() -> *const $pbr$::upb_MiniTable { fn mini_table() -> *const $pbr$::upb_MiniTable {
// This is unsafe only for Rust 1.80 and below and thus can be dropped
// once our MSRV is 1.81+
#[allow(unused_unsafe)]
unsafe {
$std$::ptr::addr_of!($minitable$) $std$::ptr::addr_of!($minitable$)
} }
} }
}
)rs"); )rs");
} }
} }

Loading…
Cancel
Save