Avoid name conflict of rust Option with message Option

Functions like `map_get` return a rust Option, which
might conflict with a `message Option` defined in the
current proto file. Use `::__std::option::Option` to
disambiguate rust Option and message Option.

PiperOrigin-RevId: 680333636
pull/18531/head
Protobuf Team Bot 2 months ago committed by Copybara-Service
parent a746c47377
commit 390e37b447
  1. 2
      src/google/protobuf/compiler/rust/accessors/map.cc
  2. 2
      src/google/protobuf/compiler/rust/accessors/repeated_field.cc
  3. 2
      src/google/protobuf/compiler/rust/accessors/singular_message.cc
  4. 4
      src/google/protobuf/compiler/rust/enum.cc
  5. 1
      src/google/protobuf/compiler/rust/generator.cc
  6. 4
      src/google/protobuf/compiler/rust/message.cc
  7. 2
      src/google/protobuf/compiler/rust/oneof.cc

@ -155,7 +155,7 @@ void Map::InExternC(Context& ctx, const FieldDescriptor& field) const {
if (ctx.is_upb()) {
ctx.Emit({}, R"rs(
fn $getter_thunk$(raw_msg: $pbr$::RawMessage)
-> Option<$pbr$::RawMap>;
-> $Option$<$pbr$::RawMap>;
fn $getter_mut_thunk$(raw_msg: $pbr$::RawMessage,
arena: $pbr$::RawArena) -> $pbr$::RawMap;
)rs");

@ -179,7 +179,7 @@ void RepeatedField::InExternC(Context& ctx,
fn $getter_thunk$(
raw_msg: $pbr$::RawMessage,
size: *const usize,
) -> Option<$pbr$::RawRepeatedField>;
) -> $Option$<$pbr$::RawRepeatedField>;
)rs");
} else {
ctx.Emit(R"rs(

@ -203,7 +203,7 @@ void SingularMessage::InExternC(Context& ctx,
} else {
// upb kernel may return NULL for a submsg, we can detect this
// in terra rust if the option returned is None
ctx.Emit({}, "Option<$pbr$::RawMessage>;");
ctx.Emit({}, "$Option$<$pbr$::RawMessage>;");
}
}},
},

@ -98,7 +98,7 @@ void EnumProxiedInMapValue(Context& ctx, const EnumDescriptor& desc) {
unsafe { $pbr$::$map_insert_thunk$(map.as_raw($pbi$::Private), $to_ffi_key_expr$, value.into_proxied($pbi$::Private).0) }
}
fn map_get<'a>(map: $pb$::MapView<'a, $key_t$, Self>, key: $pb$::View<'_, $key_t$>) -> Option<$pb$::View<'a, Self>> {
fn map_get<'a>(map: $pb$::MapView<'a, $key_t$, Self>, key: $pb$::View<'_, $key_t$>) -> $Option$<$pb$::View<'a, Self>> {
let key = $to_ffi_key_expr$;
let mut value = $std$::mem::MaybeUninit::uninit();
let found = unsafe { $pbr$::$map_get_thunk$(map.as_raw($pbi$::Private), key, value.as_mut_ptr()) };
@ -127,7 +127,7 @@ void EnumProxiedInMapValue(Context& ctx, const EnumDescriptor& desc) {
}
}
fn map_iter_next<'a>(iter: &mut $pb$::MapIter<'a, $key_t$, Self>) -> Option<($pb$::View<'a, $key_t$>, $pb$::View<'a, Self>)> {
fn map_iter_next<'a>(iter: &mut $pb$::MapIter<'a, $key_t$, Self>) -> $Option$<($pb$::View<'a, $key_t$>, $pb$::View<'a, Self>)> {
// SAFETY:
// - The `MapIter` API forbids the backing map from being mutated for 'a,
// and guarantees that it's the correct key and value types.

@ -176,6 +176,7 @@ bool RustGenerator::Generate(const FileDescriptor* file,
{"NonNull", "::__std::ptr::NonNull"},
{"Phantom", "::__std::marker::PhantomData"},
{"Result", "::__std::result::Result"},
{"Option", "::__std::option::Option"},
});
ctx.Emit({{"kernel", KernelRsName(ctx.opts().kernel)}}, R"rs(

@ -634,7 +634,7 @@ void MessageProxiedInMapValue(Context& ctx, const Descriptor& msg) {
}
}
fn map_get<'a>(map: $pb$::MapView<'a, $key_t$, Self>, key: $pb$::View<'_, $key_t$>) -> Option<$pb$::View<'a, Self>> {
fn map_get<'a>(map: $pb$::MapView<'a, $key_t$, Self>, key: $pb$::View<'_, $key_t$>) -> $Option$<$pb$::View<'a, Self>> {
use $pbr$::MapNodeSizeInfoIndexForType;
let key = $key_expr$;
let mut value = $std$::mem::MaybeUninit::uninit();
@ -675,7 +675,7 @@ void MessageProxiedInMapValue(Context& ctx, const Descriptor& msg) {
}
}
fn map_iter_next<'a>(iter: &mut $pb$::MapIter<'a, $key_t$, Self>) -> Option<($pb$::View<'a, $key_t$>, $pb$::View<'a, Self>)> {
fn map_iter_next<'a>(iter: &mut $pb$::MapIter<'a, $key_t$, Self>) -> $Option$<($pb$::View<'a, $key_t$>, $pb$::View<'a, Self>)> {
use $pbr$::MapNodeSizeInfoIndexForType;
// SAFETY:
// - The `MapIter` API forbids the backing map from being mutated for 'a,

@ -188,7 +188,7 @@ void GenerateOneofDefinition(Context& ctx, const OneofDescriptor& oneof) {
//~ This try_from is not a TryFrom impl so that it isn't
//~ committed to as part of our public api.
#[allow(dead_code)]
pub(crate) fn try_from(v: u32) -> Option<$case_enum_name$> {
pub(crate) fn try_from(v: u32) -> $Option$<$case_enum_name$> {
match v {
0 => Some($case_enum_name$::not_set),
$try_from_cases$

Loading…
Cancel
Save