From f57a2c09a83c49265ae462e32f93bb308ee2fb9f Mon Sep 17 00:00:00 2001 From: Derek Benson Date: Thu, 19 Sep 2024 10:15:02 -0700 Subject: [PATCH] Fix a bunch of references to std in rust gencode PiperOrigin-RevId: 676464323 --- src/google/protobuf/compiler/rust/enum.cc | 2 +- .../protobuf/compiler/rust/generator.cc | 2 +- src/google/protobuf/compiler/rust/message.cc | 62 +++++++++---------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/google/protobuf/compiler/rust/enum.cc b/src/google/protobuf/compiler/rust/enum.cc index e28fd2c1da..f8b654301f 100644 --- a/src/google/protobuf/compiler/rust/enum.cc +++ b/src/google/protobuf/compiler/rust/enum.cc @@ -258,7 +258,7 @@ void GenerateEnumDefinition(Context& ctx, const EnumDescriptor& desc) { impl $std$::convert::TryFrom for $name$ { type Error = $pb$::UnknownEnumValue; - fn try_from(val: i32) -> Result<$name$, Self::Error> { + fn try_from(val: i32) -> $Result$<$name$, Self::Error> { if ::is_known(val) { Ok(Self(val)) } else { diff --git a/src/google/protobuf/compiler/rust/generator.cc b/src/google/protobuf/compiler/rust/generator.cc index b5b4a12e12..459c9d0842 100644 --- a/src/google/protobuf/compiler/rust/generator.cc +++ b/src/google/protobuf/compiler/rust/generator.cc @@ -175,9 +175,9 @@ bool RustGenerator::Generate(const FileDescriptor* file, {"pbr", "::__pb::__runtime"}, {"NonNull", "::__std::ptr::NonNull"}, {"Phantom", "::__std::marker::PhantomData"}, + {"Result", "::__std::result::Result"}, }); - ctx.Emit({{"kernel", KernelRsName(ctx.opts().kernel)}}, R"rs( extern crate protobuf_$kernel$ as __pb; extern crate std as __std; diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index 4ece6ac672..91b0a45e4c 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -153,7 +153,7 @@ void MessageClearAndParse(Context& ctx, const Descriptor& msg) { //~ This swap causes the old self.inner.arena to be moved into `msg` //~ which we immediately drop, which will release any previous //~ message that was held here. - std::mem::swap(self, &mut msg); + $std$::mem::swap(self, &mut msg); Ok(()) } Err(_) => Err($pb$::ParseError) @@ -208,7 +208,7 @@ void CppMessageExterns(Context& ctx, const Descriptor& msg) { {"map_size_info_thunk", ThunkName(ctx, msg, "size_info")}}, R"rs( fn $new_thunk$() -> $pbr$::RawMessage; - fn $placement_new_thunk$(ptr: *mut std::ffi::c_void, m: $pbr$::RawMessage); + fn $placement_new_thunk$(ptr: *mut $std$::ffi::c_void, m: $pbr$::RawMessage); fn $repeated_new_thunk$() -> $pbr$::RawRepeatedField; fn $repeated_free_thunk$(raw: $pbr$::RawRepeatedField); fn $repeated_len_thunk$(raw: $pbr$::RawRepeatedField) -> usize; @@ -848,20 +848,20 @@ void GenerateRs(Context& ctx, const Descriptor& msg) { impl $pb$::Message for $Msg$ {} - impl std::default::Default for $Msg$ { + impl $std$::default::Default for $Msg$ { fn default() -> Self { Self::new() } } impl $pb$::Parse for $Msg$ { - fn parse(serialized: &[u8]) -> Result { + fn parse(serialized: &[u8]) -> $Result$ { Self::parse(serialized) } } - impl std::fmt::Debug for $Msg$ { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + impl $std$::fmt::Debug for $Msg$ { + fn fmt(&self, f: &mut $std$::fmt::Formatter<'_>) -> $std$::fmt::Result { $Msg::debug$ } } @@ -874,7 +874,7 @@ void GenerateRs(Context& ctx, const Descriptor& msg) { } impl $pb$::Serialize for $Msg$ { - fn serialize(&self) -> Result, $pb$::SerializeError> { + fn serialize(&self) -> $Result$, $pb$::SerializeError> { $pb$::AsView::as_view(self).serialize() } } @@ -886,7 +886,7 @@ void GenerateRs(Context& ctx, const Descriptor& msg) { } impl $pb$::ClearAndParse for $Msg$ { - fn clear_and_parse(&mut self, data: &[u8]) -> Result<(), $pb$::ParseError> { + fn clear_and_parse(&mut self, data: &[u8]) -> $Result$<(), $pb$::ParseError> { $Msg::clear_and_parse$ } } @@ -924,14 +924,14 @@ void GenerateRs(Context& ctx, const Descriptor& msg) { type Message = $Msg$; } - impl std::fmt::Debug for $Msg$View<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + impl $std$::fmt::Debug for $Msg$View<'_> { + fn fmt(&self, f: &mut $std$::fmt::Formatter<'_>) -> $std$::fmt::Result { $Msg::debug$ } } impl $pb$::Serialize for $Msg$View<'_> { - fn serialize(&self) -> Result, $pb$::SerializeError> { + fn serialize(&self) -> $Result$, $pb$::SerializeError> { $Msg::serialize$ } } @@ -998,14 +998,14 @@ void GenerateRs(Context& ctx, const Descriptor& msg) { type Message = $Msg$; } - impl std::fmt::Debug for $Msg$Mut<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + impl $std$::fmt::Debug for $Msg$Mut<'_> { + fn fmt(&self, f: &mut $std$::fmt::Formatter<'_>) -> $std$::fmt::Result { $Msg::debug$ } } impl $pb$::Serialize for $Msg$Mut<'_> { - fn serialize(&self) -> Result, $pb$::SerializeError> { + fn serialize(&self) -> $Result$, $pb$::SerializeError> { $pb$::AsView::as_view(self).serialize() } } @@ -1111,7 +1111,7 @@ void GenerateRs(Context& ctx, const Descriptor& msg) { $raw_arena_getter_for_message$ - pub fn parse(data: &[u8]) -> Result { + pub fn parse(data: &[u8]) -> $Result$ { let mut msg = Self::new(); $pb$::ClearAndParse::clear_and_parse(&mut msg, data).map(|_| msg) } @@ -1201,68 +1201,68 @@ void GenerateRs(Context& ctx, const Descriptor& msg) { ctx.Emit({{"Msg", RsSafeName(msg.name())}}, R"rs( impl<'a> $Msg$Mut<'a> { pub unsafe fn __unstable_wrap_cpp_grant_permission_to_break( - msg: &'a mut *mut std::ffi::c_void) -> Self { + msg: &'a mut *mut $std$::ffi::c_void) -> Self { Self { inner: $pbr$::MutatorMessageRef::wrap_raw( $pbr$::RawMessage::new(*msg as *mut _).unwrap()) } } - pub fn __unstable_cpp_repr_grant_permission_to_break(self) -> *mut std::ffi::c_void { + pub fn __unstable_cpp_repr_grant_permission_to_break(self) -> *mut $std$::ffi::c_void { self.raw_msg().as_ptr() as *mut _ } } impl<'a> $Msg$View<'a> { pub fn __unstable_wrap_cpp_grant_permission_to_break( - msg: &'a *const std::ffi::c_void) -> Self { + msg: &'a *const $std$::ffi::c_void) -> Self { Self::new($pbi$::Private, $pbr$::RawMessage::new(*msg as *mut _).unwrap()) } - pub fn __unstable_cpp_repr_grant_permission_to_break(self) -> *const std::ffi::c_void { + pub fn __unstable_cpp_repr_grant_permission_to_break(self) -> *const $std$::ffi::c_void { self.msg.as_ptr() as *const _ } } impl $pb$::OwnedMessageInterop for $Msg$ { - unsafe fn __unstable_take_ownership_of_raw_message(msg: *mut std::ffi::c_void) -> Self { + unsafe fn __unstable_take_ownership_of_raw_message(msg: *mut $std$::ffi::c_void) -> Self { Self { inner: $pbr$::MessageInner { msg: $pbr$::RawMessage::new(msg as *mut _).unwrap() } } } - fn __unstable_leak_raw_message(self) -> *mut std::ffi::c_void { - let s = std::mem::ManuallyDrop::new(self); + fn __unstable_leak_raw_message(self) -> *mut $std$::ffi::c_void { + let s = $std$::mem::ManuallyDrop::new(self); s.raw_msg().as_ptr() as *mut _ } } impl<'a> $pb$::MessageMutInterop<'a> for $Msg$Mut<'a> { unsafe fn __unstable_wrap_raw_message_mut( - msg: &'a mut *mut std::ffi::c_void) -> Self { + msg: &'a mut *mut $std$::ffi::c_void) -> Self { Self { inner: $pbr$::MutatorMessageRef::wrap_raw( $pbr$::RawMessage::new(*msg as *mut _).unwrap()) } } unsafe fn __unstable_wrap_raw_message_mut_unchecked_lifetime( - msg: *mut std::ffi::c_void) -> Self { + msg: *mut $std$::ffi::c_void) -> Self { Self { inner: $pbr$::MutatorMessageRef::wrap_raw( $pbr$::RawMessage::new(msg as *mut _).unwrap()) } } - fn __unstable_as_raw_message_mut(&mut self) -> *mut std::ffi::c_void { + fn __unstable_as_raw_message_mut(&mut self) -> *mut $std$::ffi::c_void { self.raw_msg().as_ptr() as *mut _ } } impl<'a> $pb$::MessageViewInterop<'a> for $Msg$View<'a> { unsafe fn __unstable_wrap_raw_message( - msg: &'a *const std::ffi::c_void) -> Self { + msg: &'a *const $std$::ffi::c_void) -> Self { Self::new($pbi$::Private, $pbr$::RawMessage::new(*msg as *mut _).unwrap()) } unsafe fn __unstable_wrap_raw_message_unchecked_lifetime( - msg: *const std::ffi::c_void) -> Self { + msg: *const $std$::ffi::c_void) -> Self { Self::new($pbi$::Private, $pbr$::RawMessage::new(msg as *mut _).unwrap()) } - fn __unstable_as_raw_message(&self) -> *const std::ffi::c_void { + fn __unstable_as_raw_message(&self) -> *const $std$::ffi::c_void { self.msg.as_ptr() as *const _ } } @@ -1299,14 +1299,14 @@ void GenerateRs(Context& ctx, const Descriptor& msg) { impl<'a> $pb$::MessageViewInterop<'a> for $Msg$View<'a> { unsafe fn __unstable_wrap_raw_message( - msg: &'a *const std::ffi::c_void) -> Self { + msg: &'a *const $std$::ffi::c_void) -> Self { Self::new($pbi$::Private, $pbr$::RawMessage::new(*msg as *mut _).unwrap()) } unsafe fn __unstable_wrap_raw_message_unchecked_lifetime( - msg: *const std::ffi::c_void) -> Self { + msg: *const $std$::ffi::c_void) -> Self { Self::new($pbi$::Private, $pbr$::RawMessage::new(msg as *mut _).unwrap()) } - fn __unstable_as_raw_message(&self) -> *const std::ffi::c_void { + fn __unstable_as_raw_message(&self) -> *const $std$::ffi::c_void { self.msg.as_ptr() as *const _ } }