Skip to content

Commit

Permalink
Fix a bunch of references to std in rust gencode
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 676464323
  • Loading branch information
dbenson24 authored and copybara-github committed Sep 19, 2024
1 parent d372c4a commit f57a2c0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/google/protobuf/compiler/rust/enum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ void GenerateEnumDefinition(Context& ctx, const EnumDescriptor& desc) {
impl $std$::convert::TryFrom<i32> for $name$ {
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) {
Ok(Self(val))
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/google/protobuf/compiler/rust/generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
62 changes: 31 additions & 31 deletions src/google/protobuf/compiler/rust/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<Self, $pb$::ParseError> {
fn parse(serialized: &[u8]) -> $Result$<Self, $pb$::ParseError> {
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$
}
}
Expand All @@ -874,7 +874,7 @@ void GenerateRs(Context& ctx, const Descriptor& 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()
}
}
Expand All @@ -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$
}
}
Expand Down Expand Up @@ -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<Vec<u8>, $pb$::SerializeError> {
fn serialize(&self) -> $Result$<Vec<u8>, $pb$::SerializeError> {
$Msg::serialize$
}
}
Expand Down Expand Up @@ -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<Vec<u8>, $pb$::SerializeError> {
fn serialize(&self) -> $Result$<Vec<u8>, $pb$::SerializeError> {
$pb$::AsView::as_view(self).serialize()
}
}
Expand Down Expand Up @@ -1111,7 +1111,7 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
$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();
$pb$::ClearAndParse::clear_and_parse(&mut msg, data).map(|_| msg)
}
Expand Down Expand Up @@ -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 _
}
}
Expand Down Expand Up @@ -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 _
}
}
Expand Down

0 comments on commit f57a2c0

Please sign in to comment.