diff --git a/rust/macros.rs b/rust/macros.rs index 3109eff06a..4f8334933e 100644 --- a/rust/macros.rs +++ b/rust/macros.rs @@ -19,11 +19,11 @@ /// ``` macro_rules! impl_forwarding_settable_value { ($proxied:ty, $self:ident => $self_forwarding_expr:expr) => { - fn set_on( + fn set_on<'b>( $self, _private: $crate::__internal::Private, - mutator: $crate::Mut<'_, $proxied>, - ) { + mutator: $crate::Mut<'b, $proxied>, + ) where $proxied: 'b { ($self_forwarding_expr).set_on(Private, mutator) } diff --git a/rust/map.rs b/rust/map.rs index 51bbdba89a..6244fb3d76 100644 --- a/rust/map.rs +++ b/rust/map.rs @@ -78,7 +78,9 @@ macro_rules! impl_scalar_map_keys { } impl<'a, V: [< MapWith $t:camel KeyOps >]> SettableValue> for MapView<'a, $t, V> { - fn set_on(self, _private: Private, mut mutator: Mut<'_, Map<$t, V>>) { + fn set_on<'b>(self, _private: Private, mut mutator: Mut<'b, Map<$t, V>>) + where + Map<$t, V>: 'b { mutator.copy_from(self); } } diff --git a/rust/optional.rs b/rust/optional.rs index 3c49d7f7c7..ba9955b62c 100644 --- a/rust/optional.rs +++ b/rust/optional.rs @@ -589,7 +589,10 @@ mod tests { } impl SettableValue for View<'_, VtableProxied> { - fn set_on(self, _private: Private, mutator: Mut) { + fn set_on<'a>(self, _private: Private, mutator: Mut<'a, VtableProxied>) + where + VtableProxied: 'a, + { SettableValue::::set_on(self.val(), Private, mutator) } @@ -603,7 +606,10 @@ mod tests { } impl SettableValue for i32 { - fn set_on(self, _private: Private, mutator: Mut) { + fn set_on<'a>(self, _private: Private, mutator: Mut<'a, VtableProxied>) + where + VtableProxied: 'a, + { (mutator.vtable.set)(mutator.msg, self) } diff --git a/rust/primitive.rs b/rust/primitive.rs index dd2fec18d4..839dfc0ce8 100644 --- a/rust/primitive.rs +++ b/rust/primitive.rs @@ -116,7 +116,7 @@ macro_rules! impl_singular_primitives { } impl SettableValue<$t> for $t { - fn set_on(self, _private: Private, mutator: Mut<'_, $t>) { + fn set_on<'a>(self, _private: Private, mutator: Mut<'a, $t>) where $t: 'a { match mutator { PrimitiveMut::Singular(s) => { unsafe { (s.inner).set(self) }; diff --git a/rust/proxied.rs b/rust/proxied.rs index 437ba9948d..c3da62d639 100644 --- a/rust/proxied.rs +++ b/rust/proxied.rs @@ -239,7 +239,9 @@ where { /// Consumes `self` to set the given mutator to its value. #[doc(hidden)] - fn set_on(self, _private: Private, mutator: Mut<'_, T>); + fn set_on<'a>(self, _private: Private, mutator: Mut<'a, T>) + where + T: 'a; /// Consumes `self` and `absent_mutator` to set the given empty field to /// a value. @@ -352,25 +354,37 @@ mod tests { } impl SettableValue for MyProxiedView<'_> { - fn set_on(self, _private: Private, mutator: Mut) { + fn set_on<'a>(self, _private: Private, mutator: Mut<'a, MyProxied>) + where + MyProxied: 'a, + { mutator.my_proxied_ref.val = self.my_proxied_ref.val.clone(); } } impl SettableValue for String { - fn set_on(self, _private: Private, mutator: Mut) { + fn set_on<'a>(self, _private: Private, mutator: Mut<'a, MyProxied>) + where + MyProxied: 'a, + { mutator.my_proxied_ref.val = self; } } impl SettableValue for &'_ str { - fn set_on(self, _private: Private, mutator: Mut) { + fn set_on<'a>(self, _private: Private, mutator: Mut<'a, MyProxied>) + where + MyProxied: 'a, + { mutator.my_proxied_ref.val.replace_range(.., self); } } impl SettableValue for Cow<'_, str> { - fn set_on(self, _private: Private, mutator: Mut) { + fn set_on<'a>(self, _private: Private, mutator: Mut<'a, MyProxied>) + where + MyProxied: 'a, + { match self { Cow::Owned(x) => >::set_on(x, Private, mutator), Cow::Borrowed(x) => <&str as SettableValue>::set_on(x, Private, mutator), diff --git a/rust/repeated.rs b/rust/repeated.rs index 1abb7152ba..defab4452f 100644 --- a/rust/repeated.rs +++ b/rust/repeated.rs @@ -138,7 +138,9 @@ macro_rules! impl_repeated_primitives { } impl <'a> SettableValue> for RepeatedView<'a, $t> { - fn set_on(self, _private: Private, mut mutator: Mut<'_, Repeated<$t>>) { + fn set_on<'b> (self, _private: Private, mut mutator: Mut<'b, Repeated<$t>>) + where + Repeated<$t>: 'b { mutator.copy_from(self); } } diff --git a/rust/string.rs b/rust/string.rs index 401dfc3c34..aece6ba824 100644 --- a/rust/string.rs +++ b/rust/string.rs @@ -185,7 +185,10 @@ impl<'msg> MutProxy<'msg> for BytesMut<'msg> { } impl SettableValue<[u8]> for &'_ [u8] { - fn set_on(self, _private: Private, mutator: BytesMut<'_>) { + fn set_on<'a>(self, _private: Private, mutator: Mut<'a, [u8]>) + where + [u8]: 'a, + { // SAFETY: this is a `bytes` field with no restriction on UTF-8. unsafe { mutator.inner.set(self) } } @@ -695,7 +698,10 @@ impl<'msg> MutProxy<'msg> for ProtoStrMut<'msg> { } impl SettableValue for &'_ ProtoStr { - fn set_on(self, _private: Private, mutator: ProtoStrMut<'_>) { + fn set_on<'b>(self, _private: Private, mutator: Mut<'b, ProtoStr>) + where + ProtoStr: 'b, + { // SAFETY: A `ProtoStr` has the same UTF-8 validity requirement as the runtime. unsafe { mutator.bytes.inner.set(self.as_bytes()) } } diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index a3968b6e52..d317fed9c4 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -367,7 +367,9 @@ void GenerateRs(Context msg) { } impl<'a> $pb$::SettableValue<$Msg$> for $Msg$View<'a> { - fn set_on(self, _private: $pb$::__internal::Private, _mutator: $pb$::Mut<$Msg$>) { + fn set_on<'b>(self, _private: $pb$::__internal::Private, _mutator: $pb$::Mut<'b, $Msg$>) + where + $Msg$: 'b { todo!() } }