diff --git a/src/google/protobuf/compiler/rust/accessors/map.cc b/src/google/protobuf/compiler/rust/accessors/map.cc index a485a5dbd11d..2952df9ec7e0 100644 --- a/src/google/protobuf/compiler/rust/accessors/map.cc +++ b/src/google/protobuf/compiler/rust/accessors/map.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"); diff --git a/src/google/protobuf/compiler/rust/accessors/repeated_field.cc b/src/google/protobuf/compiler/rust/accessors/repeated_field.cc index 5477e77025f6..e47678ad3ac7 100644 --- a/src/google/protobuf/compiler/rust/accessors/repeated_field.cc +++ b/src/google/protobuf/compiler/rust/accessors/repeated_field.cc @@ -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( diff --git a/src/google/protobuf/compiler/rust/accessors/singular_message.cc b/src/google/protobuf/compiler/rust/accessors/singular_message.cc index 8fc11874f803..b3df063b46a8 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_message.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_message.cc @@ -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>;"); } }}, }, diff --git a/src/google/protobuf/compiler/rust/enum.cc b/src/google/protobuf/compiler/rust/enum.cc index f8b654301f27..7e35ff2e058d 100644 --- a/src/google/protobuf/compiler/rust/enum.cc +++ b/src/google/protobuf/compiler/rust/enum.cc @@ -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. diff --git a/src/google/protobuf/compiler/rust/generator.cc b/src/google/protobuf/compiler/rust/generator.cc index 58acef279926..ecadf48fb0bd 100644 --- a/src/google/protobuf/compiler/rust/generator.cc +++ b/src/google/protobuf/compiler/rust/generator.cc @@ -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( diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index 7f0dec216d55..18efb64c043d 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -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, diff --git a/src/google/protobuf/compiler/rust/oneof.cc b/src/google/protobuf/compiler/rust/oneof.cc index 83881b3513e3..a7e40c219ffb 100644 --- a/src/google/protobuf/compiler/rust/oneof.cc +++ b/src/google/protobuf/compiler/rust/oneof.cc @@ -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$