diff --git a/rust/test/shared/accessors_test.rs b/rust/test/shared/accessors_test.rs index a0d21890fe..ccc71d1a1b 100644 --- a/rust/test/shared/accessors_test.rs +++ b/rust/test/shared/accessors_test.rs @@ -229,11 +229,9 @@ fn test_optional_bytes_accessors() { } #[test] -#[should_panic = "b/285309454"] -#[allow(unreachable_code)] fn test_singular_msg_field() { let msg = TestAllTypes::new(); // TODO("b/285309454"): fetch the inner integer `bb` // call should look like msg.optional_nested_message().bb() - match msg.optional_nested_message() {} + let _msg: unittest_proto::proto2_unittest::TestAllTypesView = msg.optional_nested_message(); } diff --git a/src/google/protobuf/compiler/rust/accessors/singular_message.cc b/src/google/protobuf/compiler/rust/accessors/singular_message.cc index f10221f950..c10fb086f7 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_message.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_message.cc @@ -50,8 +50,8 @@ class SingularMessage final : public AccessorGenerator { }, R"rs( // inMsgImpl - pub fn $field$(&self) -> std::convert::Infallible { - todo!("b/285309454") + pub fn r#$field$(&self) -> $Msg$View { + $Msg$View { msg: self.msg, _phantom: std::marker::PhantomData } } )rs"); } diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index 2cd69f4940..a42c550c09 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -301,8 +301,9 @@ void MessageGenerator::GenerateRs(Context msg) { } #[derive(Debug, Copy, Clone)] + #[allow(dead_code)] pub struct $Msg$View<'a> { - _msg: $pbi$::RawMessage, + msg: $pbi$::RawMessage, _phantom: $Phantom$<&'a ()>, } @@ -310,35 +311,43 @@ void MessageGenerator::GenerateRs(Context msg) { type Proxied = $Msg$; fn as_view(&self) -> $pb$::View<'a, $Msg$> { - todo!("b/285309454") + *self + } + fn into_view<'shorter>(self) -> $pb$::View<'shorter, $Msg$> where 'a: 'shorter { + self } - fn into_view<'shorter>(self) -> $pb$::View<'shorter, $Msg$> where 'a: 'shorter { todo!("b/285309454") } } impl<'a> $pb$::SettableValue<$Msg$> for $Msg$View<'a> { fn set_on(self, _private: $pb$::__internal::Private, _mutator: $pb$::Mut<$Msg$>) { - todo!("b/285309454") + todo!() } } - #[derive(Debug)] + #[derive(Debug, Copy, Clone)] + #[allow(dead_code)] pub struct $Msg$Mut<'a> { + msg: $pbi$::RawMessage, _phantom: $Phantom$<&'a mut ()>, } + unsafe impl Sync for $Msg$Mut<'_> {} + impl<'a> $pb$::MutProxy<'a> for $Msg$Mut<'a> { fn as_mut(&mut self) -> $pb$::Mut<'_, $Msg$> { - todo!("b/285309454") + $Msg$Mut { msg: self.msg, _phantom: self._phantom } } - fn into_mut<'shorter>(self) -> $pb$::Mut<'shorter, $Msg$> where 'a : 'shorter { todo!("b/285309454") } + fn into_mut<'shorter>(self) -> $pb$::Mut<'shorter, $Msg$> where 'a : 'shorter { self } } impl<'a> $pb$::ViewProxy<'a> for $Msg$Mut<'a> { type Proxied = $Msg$; fn as_view(&self) -> $pb$::View<'_, $Msg$> { - todo!("b/285309454") + $Msg$View { msg: self.msg, _phantom: std::marker::PhantomData } + } + fn into_view<'shorter>(self) -> $pb$::View<'shorter, $Msg$> where 'a: 'shorter { + $Msg$View { msg: self.msg, _phantom: std::marker::PhantomData } } - fn into_view<'shorter>(self) -> $pb$::View<'shorter, $Msg$> where 'a: 'shorter { todo!("b/285309454") } } impl $Msg$ {