Fix a bunch of references to std in rust gencode

PiperOrigin-RevId: 676464323
pull/18412/head
Derek Benson 2 months ago committed by Copybara-Service
parent d372c4aeb1
commit f57a2c09a8
  1. 2
      src/google/protobuf/compiler/rust/enum.cc
  2. 2
      src/google/protobuf/compiler/rust/generator.cc
  3. 62
      src/google/protobuf/compiler/rust/message.cc

@ -258,7 +258,7 @@ void GenerateEnumDefinition(Context& ctx, const EnumDescriptor& desc) {
impl $std$::convert::TryFrom<i32> for $name$ { impl $std$::convert::TryFrom<i32> for $name$ {
type Error = $pb$::UnknownEnumValue<Self>; type Error = $pb$::UnknownEnumValue<Self>;
fn try_from(val: i32) -> Result<$name$, Self::Error> { fn try_from(val: i32) -> $Result$<$name$, Self::Error> {
if <Self as $pbi$::Enum>::is_known(val) { if <Self as $pbi$::Enum>::is_known(val) {
Ok(Self(val)) Ok(Self(val))
} else { } else {

@ -175,9 +175,9 @@ bool RustGenerator::Generate(const FileDescriptor* file,
{"pbr", "::__pb::__runtime"}, {"pbr", "::__pb::__runtime"},
{"NonNull", "::__std::ptr::NonNull"}, {"NonNull", "::__std::ptr::NonNull"},
{"Phantom", "::__std::marker::PhantomData"}, {"Phantom", "::__std::marker::PhantomData"},
{"Result", "::__std::result::Result"},
}); });
ctx.Emit({{"kernel", KernelRsName(ctx.opts().kernel)}}, R"rs( ctx.Emit({{"kernel", KernelRsName(ctx.opts().kernel)}}, R"rs(
extern crate protobuf_$kernel$ as __pb; extern crate protobuf_$kernel$ as __pb;
extern crate std as __std; extern crate std as __std;

@ -153,7 +153,7 @@ void MessageClearAndParse(Context& ctx, const Descriptor& msg) {
//~ This swap causes the old self.inner.arena to be moved into `msg` //~ This swap causes the old self.inner.arena to be moved into `msg`
//~ which we immediately drop, which will release any previous //~ which we immediately drop, which will release any previous
//~ message that was held here. //~ message that was held here.
std::mem::swap(self, &mut msg); $std$::mem::swap(self, &mut msg);
Ok(()) Ok(())
} }
Err(_) => Err($pb$::ParseError) Err(_) => Err($pb$::ParseError)
@ -208,7 +208,7 @@ void CppMessageExterns(Context& ctx, const Descriptor& msg) {
{"map_size_info_thunk", ThunkName(ctx, msg, "size_info")}}, {"map_size_info_thunk", ThunkName(ctx, msg, "size_info")}},
R"rs( R"rs(
fn $new_thunk$() -> $pbr$::RawMessage; 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_new_thunk$() -> $pbr$::RawRepeatedField;
fn $repeated_free_thunk$(raw: $pbr$::RawRepeatedField); fn $repeated_free_thunk$(raw: $pbr$::RawRepeatedField);
fn $repeated_len_thunk$(raw: $pbr$::RawRepeatedField) -> usize; 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 $pb$::Message for $Msg$ {}
impl std::default::Default for $Msg$ { impl $std$::default::Default for $Msg$ {
fn default() -> Self { fn default() -> Self {
Self::new() Self::new()
} }
} }
impl $pb$::Parse for $Msg$ { impl $pb$::Parse for $Msg$ {
fn parse(serialized: &[u8]) -> Result<Self, $pb$::ParseError> { fn parse(serialized: &[u8]) -> $Result$<Self, $pb$::ParseError> {
Self::parse(serialized) Self::parse(serialized)
} }
} }
impl std::fmt::Debug for $Msg$ { impl $std$::fmt::Debug for $Msg$ {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut $std$::fmt::Formatter<'_>) -> $std$::fmt::Result {
$Msg::debug$ $Msg::debug$
} }
} }
@ -874,7 +874,7 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
} }
impl $pb$::Serialize for $Msg$ { impl $pb$::Serialize for $Msg$ {
fn serialize(&self) -> Result<Vec<u8>, $pb$::SerializeError> { fn serialize(&self) -> $Result$<Vec<u8>, $pb$::SerializeError> {
$pb$::AsView::as_view(self).serialize() $pb$::AsView::as_view(self).serialize()
} }
} }
@ -886,7 +886,7 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
} }
impl $pb$::ClearAndParse for $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$ $Msg::clear_and_parse$
} }
} }
@ -924,14 +924,14 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
type Message = $Msg$; type Message = $Msg$;
} }
impl std::fmt::Debug for $Msg$View<'_> { impl $std$::fmt::Debug for $Msg$View<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut $std$::fmt::Formatter<'_>) -> $std$::fmt::Result {
$Msg::debug$ $Msg::debug$
} }
} }
impl $pb$::Serialize for $Msg$View<'_> { impl $pb$::Serialize for $Msg$View<'_> {
fn serialize(&self) -> Result<Vec<u8>, $pb$::SerializeError> { fn serialize(&self) -> $Result$<Vec<u8>, $pb$::SerializeError> {
$Msg::serialize$ $Msg::serialize$
} }
} }
@ -998,14 +998,14 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
type Message = $Msg$; type Message = $Msg$;
} }
impl std::fmt::Debug for $Msg$Mut<'_> { impl $std$::fmt::Debug for $Msg$Mut<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut $std$::fmt::Formatter<'_>) -> $std$::fmt::Result {
$Msg::debug$ $Msg::debug$
} }
} }
impl $pb$::Serialize for $Msg$Mut<'_> { impl $pb$::Serialize for $Msg$Mut<'_> {
fn serialize(&self) -> Result<Vec<u8>, $pb$::SerializeError> { fn serialize(&self) -> $Result$<Vec<u8>, $pb$::SerializeError> {
$pb$::AsView::as_view(self).serialize() $pb$::AsView::as_view(self).serialize()
} }
} }
@ -1111,7 +1111,7 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
$raw_arena_getter_for_message$ $raw_arena_getter_for_message$
pub fn parse(data: &[u8]) -> Result<Self, $pb$::ParseError> { pub fn parse(data: &[u8]) -> $Result$<Self, $pb$::ParseError> {
let mut msg = Self::new(); let mut msg = Self::new();
$pb$::ClearAndParse::clear_and_parse(&mut msg, data).map(|_| msg) $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( ctx.Emit({{"Msg", RsSafeName(msg.name())}}, R"rs(
impl<'a> $Msg$Mut<'a> { impl<'a> $Msg$Mut<'a> {
pub unsafe fn __unstable_wrap_cpp_grant_permission_to_break( 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 { Self {
inner: $pbr$::MutatorMessageRef::wrap_raw( inner: $pbr$::MutatorMessageRef::wrap_raw(
$pbr$::RawMessage::new(*msg as *mut _).unwrap()) $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 _ self.raw_msg().as_ptr() as *mut _
} }
} }
impl<'a> $Msg$View<'a> { impl<'a> $Msg$View<'a> {
pub fn __unstable_wrap_cpp_grant_permission_to_break( 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()) 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 _ self.msg.as_ptr() as *const _
} }
} }
impl $pb$::OwnedMessageInterop for $Msg$ { 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() } } Self { inner: $pbr$::MessageInner { msg: $pbr$::RawMessage::new(msg as *mut _).unwrap() } }
} }
fn __unstable_leak_raw_message(self) -> *mut std::ffi::c_void { fn __unstable_leak_raw_message(self) -> *mut $std$::ffi::c_void {
let s = std::mem::ManuallyDrop::new(self); let s = $std$::mem::ManuallyDrop::new(self);
s.raw_msg().as_ptr() as *mut _ s.raw_msg().as_ptr() as *mut _
} }
} }
impl<'a> $pb$::MessageMutInterop<'a> for $Msg$Mut<'a> { impl<'a> $pb$::MessageMutInterop<'a> for $Msg$Mut<'a> {
unsafe fn __unstable_wrap_raw_message_mut( 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 { Self {
inner: $pbr$::MutatorMessageRef::wrap_raw( inner: $pbr$::MutatorMessageRef::wrap_raw(
$pbr$::RawMessage::new(*msg as *mut _).unwrap()) $pbr$::RawMessage::new(*msg as *mut _).unwrap())
} }
} }
unsafe fn __unstable_wrap_raw_message_mut_unchecked_lifetime( unsafe fn __unstable_wrap_raw_message_mut_unchecked_lifetime(
msg: *mut std::ffi::c_void) -> Self { msg: *mut $std$::ffi::c_void) -> Self {
Self { Self {
inner: $pbr$::MutatorMessageRef::wrap_raw( inner: $pbr$::MutatorMessageRef::wrap_raw(
$pbr$::RawMessage::new(msg as *mut _).unwrap()) $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 _ self.raw_msg().as_ptr() as *mut _
} }
} }
impl<'a> $pb$::MessageViewInterop<'a> for $Msg$View<'a> { impl<'a> $pb$::MessageViewInterop<'a> for $Msg$View<'a> {
unsafe fn __unstable_wrap_raw_message( 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()) Self::new($pbi$::Private, $pbr$::RawMessage::new(*msg as *mut _).unwrap())
} }
unsafe fn __unstable_wrap_raw_message_unchecked_lifetime( 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()) 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 _ 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> { impl<'a> $pb$::MessageViewInterop<'a> for $Msg$View<'a> {
unsafe fn __unstable_wrap_raw_message( 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()) Self::new($pbi$::Private, $pbr$::RawMessage::new(*msg as *mut _).unwrap())
} }
unsafe fn __unstable_wrap_raw_message_unchecked_lifetime( 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()) 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 _ self.msg.as_ptr() as *const _
} }
} }

Loading…
Cancel
Save