From 3bc5991d11759c7b85e8b36aec81ddba49e721c9 Mon Sep 17 00:00:00 2001 From: Zoey Greer Date: Fri, 20 Sep 2024 11:29:26 -0700 Subject: [PATCH] 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 aca540fac90f10ea74aa40caa315a83b5b9d5104 PiperOrigin-RevId: 676912529 --- src/google/protobuf/compiler/rust/message.cc | 21 +++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index 318ba2c369..235f8ffc3d 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -285,21 +285,36 @@ void UpbGeneratedMessageTraitImpls(Context& ctx, const Descriptor& msg) { unsafe impl $pbr$::AssociatedMiniTable for $Msg$ { #[inline(always)] fn mini_table() -> *const $pbr$::upb_MiniTable { - $std$::ptr::addr_of!($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$) + } } } unsafe impl $pbr$::AssociatedMiniTable for $Msg$View<'_> { #[inline(always)] fn mini_table() -> *const $pbr$::upb_MiniTable { - $std$::ptr::addr_of!($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$) + } } } unsafe impl $pbr$::AssociatedMiniTable for $Msg$Mut<'_> { #[inline(always)] fn mini_table() -> *const $pbr$::upb_MiniTable { - $std$::ptr::addr_of!($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$) + } } } )rs");