Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid name conflict of rust Option with message Option #18531

Merged
merged 1 commit into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/google/protobuf/compiler/rust/accessors/map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>;");
}
}},
},
Expand Down
4 changes: 2 additions & 2 deletions src/google/protobuf/compiler/rust/enum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()) };
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/google/protobuf/compiler/rust/generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/google/protobuf/compiler/rust/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/google/protobuf/compiler/rust/oneof.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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$
Expand Down
Loading