From aca8c8b8ee1950fa7aa0fb531ade27b76b029910 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Wed, 8 Jan 2025 10:37:18 +0100 Subject: [PATCH] chore: remove some `allow(dead_code)` annotations and associated dead code (#4472) We have quite a few `allow(dead_code)` annotations. While it's OK to use in situations where the Cargo-feature combination explodes and makes it hard to reason about when something is actually used or not, in other situations it can be avoided, and show actual, dead code. --- .../src/linked_chunk/builder.rs | 4 +--- .../matrix-sdk-common/src/linked_chunk/mod.rs | 1 - .../src/linked_chunk/updates.rs | 3 +++ .../src/olm/group_sessions/inbound.rs | 21 ---------------- .../matrix-sdk-indexeddb/src/safe_encode.rs | 18 -------------- .../src/state_store/migrations.rs | 1 - crates/matrix-sdk-sqlite/src/crypto_store.rs | 7 +++--- .../src/event_cache_store.rs | 24 ------------------- .../matrix-sdk/src/sliding_sync/list/mod.rs | 16 ++++++------- .../src/test_json/keys_query_sets.rs | 3 --- 10 files changed, 14 insertions(+), 84 deletions(-) diff --git a/crates/matrix-sdk-common/src/linked_chunk/builder.rs b/crates/matrix-sdk-common/src/linked_chunk/builder.rs index 81459e2d605..6ba403f3e60 100644 --- a/crates/matrix-sdk-common/src/linked_chunk/builder.rs +++ b/crates/matrix-sdk-common/src/linked_chunk/builder.rs @@ -31,7 +31,6 @@ use super::{ /// which will get resolved later when re-building the full data structure. This /// allows using chunks that references other chunks that aren't known yet. struct TemporaryChunk { - id: ChunkIdentifier, previous: Option, next: Option, content: ChunkContent, @@ -79,7 +78,7 @@ impl LinkedChunkBuilder { next: Option, content: Gap, ) { - let chunk = TemporaryChunk { id, previous, next, content: ChunkContent::Gap(content) }; + let chunk = TemporaryChunk { previous, next, content: ChunkContent::Gap(content) }; self.chunks.insert(id, chunk); } @@ -96,7 +95,6 @@ impl LinkedChunkBuilder { items: impl IntoIterator, ) { let chunk = TemporaryChunk { - id, previous, next, content: ChunkContent::Items(items.into_iter().collect()), diff --git a/crates/matrix-sdk-common/src/linked_chunk/mod.rs b/crates/matrix-sdk-common/src/linked_chunk/mod.rs index 3294f58845f..b8f14589ad4 100644 --- a/crates/matrix-sdk-common/src/linked_chunk/mod.rs +++ b/crates/matrix-sdk-common/src/linked_chunk/mod.rs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#![allow(dead_code)] #![allow(rustdoc::private_intra_doc_links)] //! A linked chunk is the underlying data structure that holds all events. diff --git a/crates/matrix-sdk-common/src/linked_chunk/updates.rs b/crates/matrix-sdk-common/src/linked_chunk/updates.rs index e05944e989e..c14ee4ab09e 100644 --- a/crates/matrix-sdk-common/src/linked_chunk/updates.rs +++ b/crates/matrix-sdk-common/src/linked_chunk/updates.rs @@ -138,6 +138,7 @@ impl ObservableUpdates { } /// Subscribe to updates by using a [`Stream`]. + #[cfg(test)] pub(super) fn subscribe(&mut self) -> UpdatesSubscriber { // A subscriber is a new update reader, it needs its own token. let token = self.new_reader_token(); @@ -264,6 +265,7 @@ impl UpdatesInner { } /// Return the number of updates in the buffer. + #[cfg(test)] fn len(&self) -> usize { self.updates.len() } @@ -302,6 +304,7 @@ pub(super) struct UpdatesSubscriber { impl UpdatesSubscriber { /// Create a new [`Self`]. + #[cfg(test)] fn new(updates: Weak>>, token: ReaderToken) -> Self { Self { updates, token } } diff --git a/crates/matrix-sdk-crypto/src/olm/group_sessions/inbound.rs b/crates/matrix-sdk-crypto/src/olm/group_sessions/inbound.rs index c42d7ba889d..1608498a76f 100644 --- a/crates/matrix-sdk-crypto/src/olm/group_sessions/inbound.rs +++ b/crates/matrix-sdk-crypto/src/olm/group_sessions/inbound.rs @@ -221,27 +221,6 @@ impl InboundGroupSession { Self::try_from(exported_session) } - #[allow(dead_code)] - fn from_backup( - room_id: &RoomId, - backup: BackedUpRoomKey, - ) -> Result { - // We're using this session only to get the session id, the session - // config doesn't matter here. - let session = InnerSession::import(&backup.session_key, SessionConfig::default()); - let session_id = session.session_id(); - - Self::from_export(&ExportedRoomKey { - algorithm: backup.algorithm, - room_id: room_id.to_owned(), - sender_key: backup.sender_key, - session_id, - forwarding_curve25519_key_chain: vec![], - session_key: backup.session_key, - sender_claimed_keys: backup.sender_claimed_keys, - }) - } - /// Store the group session as a base64 encoded string. /// /// # Arguments diff --git a/crates/matrix-sdk-indexeddb/src/safe_encode.rs b/crates/matrix-sdk-indexeddb/src/safe_encode.rs index 4121b5aa430..7f8917fe40a 100644 --- a/crates/matrix-sdk-indexeddb/src/safe_encode.rs +++ b/crates/matrix-sdk-indexeddb/src/safe_encode.rs @@ -1,6 +1,5 @@ //! Helpers for wasm32/browser environments -#![allow(dead_code)] use base64::{ alphabet, engine::{general_purpose, GeneralPurpose}, @@ -51,23 +50,6 @@ pub trait SafeEncode { .encode(store_cipher.hash_key(table_name, self.as_encoded_string().as_bytes())) } - /// encode self into a JsValue, internally using `as_encoded_string` - /// to escape the value of self, and append the given counter - fn encode_with_counter(&self, i: usize) -> JsValue { - format!("{}{KEY_SEPARATOR}{i:016x}", self.as_encoded_string()).into() - } - - /// encode self into a JsValue, internally using `as_secure_string` - /// to escape the value of self, and append the given counter - fn encode_with_counter_secure( - &self, - table_name: &str, - store_cipher: &StoreCipher, - i: usize, - ) -> JsValue { - format!("{}{KEY_SEPARATOR}{i:016x}", self.as_secure_string(table_name, store_cipher)).into() - } - /// Encode self into a IdbKeyRange for searching all keys that are /// prefixed with this key, followed by `KEY_SEPARATOR`. Internally /// uses `as_encoded_string` to ensure the given key is escaped properly. diff --git a/crates/matrix-sdk-indexeddb/src/state_store/migrations.rs b/crates/matrix-sdk-indexeddb/src/state_store/migrations.rs index 5d86dcf61a6..01c0a0a20db 100644 --- a/crates/matrix-sdk-indexeddb/src/state_store/migrations.rs +++ b/crates/matrix-sdk-indexeddb/src/state_store/migrations.rs @@ -51,7 +51,6 @@ const CURRENT_META_DB_VERSION: u32 = 2; /// Sometimes Migrations can't proceed without having to drop existing /// data. This allows you to configure, how these cases should be handled. -#[allow(dead_code)] #[derive(Clone, Debug, PartialEq, Eq)] pub enum MigrationConflictStrategy { /// Just drop the data, we don't care that we have to sync again diff --git a/crates/matrix-sdk-sqlite/src/crypto_store.rs b/crates/matrix-sdk-sqlite/src/crypto_store.rs index 236b6b7fcb4..fe6ce5e88a1 100644 --- a/crates/matrix-sdk-sqlite/src/crypto_store.rs +++ b/crates/matrix-sdk-sqlite/src/crypto_store.rs @@ -1420,8 +1420,7 @@ mod tests { struct TestDb { // Needs to be kept alive because the Drop implementation for TempDir deletes the // directory. - #[allow(dead_code)] - dir: TempDir, + _dir: TempDir, database: SqliteCryptoStore, } @@ -1440,14 +1439,14 @@ mod tests { let database = SqliteCryptoStore::open(tmpdir.path(), None).await.expect("Can't open the test store"); - TestDb { dir: tmpdir, database } + TestDb { _dir: tmpdir, database } } /// Test that we didn't regress in our storage layer by loading data from a /// pre-filled database, or in other words use a test vector for this. #[async_test] async fn test_open_test_vector_store() { - let TestDb { dir: _, database } = get_test_db().await; + let TestDb { _dir: _, database } = get_test_db().await; let account = database .load_account() diff --git a/crates/matrix-sdk-sqlite/src/event_cache_store.rs b/crates/matrix-sdk-sqlite/src/event_cache_store.rs index fd7657684ef..88c9d1801bb 100644 --- a/crates/matrix-sdk-sqlite/src/event_cache_store.rs +++ b/crates/matrix-sdk-sqlite/src/event_cache_store.rs @@ -14,8 +14,6 @@ //! A sqlite-based backend for the [`EventCacheStore`]. -#![allow(dead_code)] // Most of the unused code may be used soonish. - use std::{borrow::Cow, fmt, path::Path, sync::Arc}; use async_trait::async_trait; @@ -143,28 +141,6 @@ impl SqliteEventCacheStore { row.get::<_, String>(3)?, )) } - - async fn load_chunk_with_id( - &self, - room_id: &RoomId, - chunk_id: ChunkIdentifier, - ) -> Result> { - let hashed_room_id = self.encode_key(keys::LINKED_CHUNKS, room_id); - - let this = self.clone(); - - self - .acquire() - .await? - .with_transaction(move |txn| -> Result<_> { - let (id, previous, next, chunk_type) = txn.query_row( - "SELECT id, previous, next, type FROM linked_chunks WHERE room_id = ? AND chunk_id = ?", - (&hashed_room_id, chunk_id.index()), - Self::map_row_to_chunk - )?; - txn.rebuild_chunk(&this, &hashed_room_id, previous, id, next, chunk_type.as_str()) - }).await - } } trait TransactionExtForLinkedChunks { diff --git a/crates/matrix-sdk/src/sliding_sync/list/mod.rs b/crates/matrix-sdk/src/sliding_sync/list/mod.rs index a3b3ec3b0f4..1471dfc7bf9 100644 --- a/crates/matrix-sdk/src/sliding_sync/list/mod.rs +++ b/crates/matrix-sdk/src/sliding_sync/list/mod.rs @@ -204,20 +204,18 @@ impl SlidingSyncList { pub(super) fn invalidate_sticky_data(&self) { let _ = self.inner.sticky.write().unwrap().data_mut(); } -} - -#[cfg(any(test, feature = "testing"))] -#[allow(dead_code)] -impl SlidingSyncList { - /// Set the maximum number of rooms. - pub(super) fn set_maximum_number_of_rooms(&self, maximum_number_of_rooms: Option) { - self.inner.maximum_number_of_rooms.set(maximum_number_of_rooms); - } /// Get the sync-mode. + #[cfg(feature = "testing")] pub fn sync_mode(&self) -> SlidingSyncMode { self.inner.sync_mode.read().unwrap().clone() } + + /// Set the maximum number of rooms. + #[cfg(test)] + pub(super) fn set_maximum_number_of_rooms(&self, maximum_number_of_rooms: Option) { + self.inner.maximum_number_of_rooms.set(maximum_number_of_rooms); + } } #[derive(Debug)] diff --git a/testing/matrix-sdk-test/src/test_json/keys_query_sets.rs b/testing/matrix-sdk-test/src/test_json/keys_query_sets.rs index 1ee8591162c..9e0e43a7a8b 100644 --- a/testing/matrix-sdk-test/src/test_json/keys_query_sets.rs +++ b/testing/matrix-sdk-test/src/test_json/keys_query_sets.rs @@ -36,7 +36,6 @@ use crate::{ /// devices are properly signed by `@good` (i.e were self-verified by @good) pub struct KeyDistributionTestData {} -#[allow(dead_code)] impl KeyDistributionTestData { pub const MASTER_KEY_PRIVATE_EXPORT: &'static str = "9kquJqAtEUoTXljh5W2QSsCm4FH9WvWzIkDkIMUsM2k"; @@ -529,7 +528,6 @@ impl IdentityChangeDataSet { /// The `/keys/query` responses were generated using a local synapse. pub struct VerificationViolationTestData {} -#[allow(dead_code)] impl VerificationViolationTestData { /// Secret part of Alice's master cross-signing key. /// @@ -1130,7 +1128,6 @@ impl VerificationViolationTestData { /// For user @malo, that performed an identity change with the same device. pub struct MaloIdentityChangeDataSet {} -#[allow(dead_code)] impl MaloIdentityChangeDataSet { pub fn user_id() -> &'static UserId { user_id!("@malo:localhost")