From 77e78e9d661c652765513e021b4ec17179ed6cab Mon Sep 17 00:00:00 2001 From: Zoey Greer Date: Mon, 9 Sep 2024 19:16:20 -0400 Subject: [PATCH 1/2] resolve compilation error about `unsafe` block --- src/google/protobuf/compiler/rust/message.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index cacaa18302a1..55020f9e5760 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -287,21 +287,27 @@ 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$) + 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$) + 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$) + unsafe { + $std$::ptr::addr_of!($minitable$) + } } } )rs"); From aca540fac90f10ea74aa40caa315a83b5b9d5104 Mon Sep 17 00:00:00 2001 From: Zoey Greer Date: Wed, 18 Sep 2024 14:31:20 -0400 Subject: [PATCH 2/2] address reveiew comment --- src/google/protobuf/compiler/rust/message.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index 55020f9e5760..244734493902 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -287,6 +287,9 @@ void UpbGeneratedMessageTraitImpls(Context& ctx, const Descriptor& msg) { unsafe impl $pbr$::AssociatedMiniTable for $Msg$ { #[inline(always)] 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$) } @@ -296,6 +299,9 @@ void UpbGeneratedMessageTraitImpls(Context& ctx, const Descriptor& msg) { unsafe impl $pbr$::AssociatedMiniTable for $Msg$View<'_> { #[inline(always)] 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$) } @@ -305,6 +311,9 @@ void UpbGeneratedMessageTraitImpls(Context& ctx, const Descriptor& msg) { unsafe impl $pbr$::AssociatedMiniTable for $Msg$Mut<'_> { #[inline(always)] 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$) }