From ba2fe1d38797d90e58fcb9fa59b6ee048e3bcdd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Tue, 7 Oct 2025 15:00:17 +0200 Subject: [PATCH] fix(crypto): Make impl Stream return type not use any lifetime MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With Rust 2024, by default `impl` return types use any generic that is in scope, so in these cases the lifetime of `self`. But since the return type is actually owned, the returned impl shouldn't use any lifetime, which is what `use<>` does. Signed-off-by: Kévin Commaille --- .../src/store/crypto_store_wrapper.rs | 7 ++++--- crates/matrix-sdk-crypto/src/store/mod.rs | 12 +++++++----- crates/matrix-sdk-crypto/src/verification/qrcode.rs | 2 +- .../matrix-sdk-crypto/src/verification/requests.rs | 2 +- crates/matrix-sdk-crypto/src/verification/sas/mod.rs | 2 +- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/crates/matrix-sdk-crypto/src/store/crypto_store_wrapper.rs b/crates/matrix-sdk-crypto/src/store/crypto_store_wrapper.rs index ecc776790..bc0dbbff7 100644 --- a/crates/matrix-sdk-crypto/src/store/crypto_store_wrapper.rs +++ b/crates/matrix-sdk-crypto/src/store/crypto_store_wrapper.rs @@ -335,14 +335,14 @@ impl CryptoStoreWrapper { /// logged and items will be dropped. pub fn room_keys_withheld_received_stream( &self, - ) -> impl Stream> { + ) -> impl Stream> + use<> { let stream = BroadcastStream::new(self.room_keys_withheld_received_sender.subscribe()); Self::filter_errors_out_of_stream(stream, "room_keys_withheld_received_stream") } /// Receive notifications of gossipped secrets being received and stored in /// the secret inbox as a [`Stream`]. - pub fn secrets_stream(&self) -> impl Stream { + pub fn secrets_stream(&self) -> impl Stream + use<> { let stream = BroadcastStream::new(self.secrets_broadcaster.subscribe()); Self::filter_errors_out_of_stream(stream, "secrets_stream") } @@ -360,7 +360,8 @@ impl CryptoStoreWrapper { /// device and user identity streams. pub(super) fn identities_stream( &self, - ) -> impl Stream, IdentityChanges, DeviceChanges)> { + ) -> impl Stream, IdentityChanges, DeviceChanges)> + use<> + { let stream = BroadcastStream::new(self.identities_broadcaster.subscribe()); Self::filter_errors_out_of_stream(stream, "identities_stream") } diff --git a/crates/matrix-sdk-crypto/src/store/mod.rs b/crates/matrix-sdk-crypto/src/store/mod.rs index 772ab3f2a..0361ad27d 100644 --- a/crates/matrix-sdk-crypto/src/store/mod.rs +++ b/crates/matrix-sdk-crypto/src/store/mod.rs @@ -1151,7 +1151,7 @@ impl Store { /// logged and items will be dropped. pub fn room_keys_withheld_received_stream( &self, - ) -> impl Stream> { + ) -> impl Stream> + use<> { self.inner.store.room_keys_withheld_received_stream() } @@ -1185,7 +1185,7 @@ impl Store { /// } /// # }); /// ``` - pub fn user_identities_stream(&self) -> impl Stream { + pub fn user_identities_stream(&self) -> impl Stream + use<> { let verification_machine = self.inner.verification_machine.to_owned(); let this = self.clone(); @@ -1243,7 +1243,7 @@ impl Store { /// } /// # }); /// ``` - pub fn devices_stream(&self) -> impl Stream { + pub fn devices_stream(&self) -> impl Stream + use<> { let verification_machine = self.inner.verification_machine.to_owned(); self.inner.store.identities_stream().map(move |(own_identity, identities, devices)| { @@ -1265,7 +1265,9 @@ impl Store { /// /// The stream will terminate once all references to the underlying /// `CryptoStoreWrapper` are dropped. - pub fn identities_stream_raw(&self) -> impl Stream { + pub fn identities_stream_raw( + &self, + ) -> impl Stream + use<> { self.inner.store.identities_stream().map(|(_, identities, devices)| (identities, devices)) } @@ -1318,7 +1320,7 @@ impl Store { /// } /// # }); /// ``` - pub fn secrets_stream(&self) -> impl Stream { + pub fn secrets_stream(&self) -> impl Stream + use<> { self.inner.store.secrets_stream() } diff --git a/crates/matrix-sdk-crypto/src/verification/qrcode.rs b/crates/matrix-sdk-crypto/src/verification/qrcode.rs index e1763181f..b3fd47418 100644 --- a/crates/matrix-sdk-crypto/src/verification/qrcode.rs +++ b/crates/matrix-sdk-crypto/src/verification/qrcode.rs @@ -681,7 +681,7 @@ impl QrVerification { /// Listen for changes in the QrCode verification process. /// /// The changes are presented as a stream of [`QrVerificationState`] values. - pub fn changes(&self) -> impl Stream { + pub fn changes(&self) -> impl Stream + use<> { self.state.subscribe().map(|s| (&s).into()) } diff --git a/crates/matrix-sdk-crypto/src/verification/requests.rs b/crates/matrix-sdk-crypto/src/verification/requests.rs index edb4761d7..fa816a7aa 100644 --- a/crates/matrix-sdk-crypto/src/verification/requests.rs +++ b/crates/matrix-sdk-crypto/src/verification/requests.rs @@ -881,7 +881,7 @@ impl VerificationRequest { /// /// The changes are presented as a stream of [`VerificationRequestState`] /// values. - pub fn changes(&self) -> impl Stream { + pub fn changes(&self) -> impl Stream + use<> { self.inner.subscribe().map(|s| (&s).into()) } diff --git a/crates/matrix-sdk-crypto/src/verification/sas/mod.rs b/crates/matrix-sdk-crypto/src/verification/sas/mod.rs index 5387c5a18..670775690 100644 --- a/crates/matrix-sdk-crypto/src/verification/sas/mod.rs +++ b/crates/matrix-sdk-crypto/src/verification/sas/mod.rs @@ -745,7 +745,7 @@ impl Sas { /// } /// # anyhow::Ok(()) }; /// ``` - pub fn changes(&self) -> impl Stream { + pub fn changes(&self) -> impl Stream + use<> { self.inner.subscribe().map(|s| (&s).into()) }