From a59fdc08bbda5afd6c5c76243f285d2c13cbe471 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 25 Oct 2022 10:58:51 +0200 Subject: [PATCH] chore: Fix clippy lints Automated with cargo clippy --fix. --- crates/matrix-sdk-base/src/media.rs | 4 ++-- crates/matrix-sdk-crypto/src/gossiping/mod.rs | 2 +- crates/matrix-sdk-crypto/src/machine.rs | 8 ++++---- crates/matrix-sdk-crypto/src/olm/account.rs | 2 +- crates/matrix-sdk-crypto/src/verification/mod.rs | 7 +++---- crates/matrix-sdk-crypto/src/verification/sas/helpers.rs | 4 ++-- crates/matrix-sdk-indexeddb/src/crypto_store.rs | 6 +++--- crates/matrix-sdk-indexeddb/src/safe_encode.rs | 2 +- crates/matrix-sdk-indexeddb/src/state_store.rs | 4 ++-- crates/matrix-sdk-sled/src/crypto_store.rs | 2 +- crates/matrix-sdk-sled/src/state_store.rs | 4 ++-- crates/matrix-sdk/src/error.rs | 2 +- 12 files changed, 23 insertions(+), 24 deletions(-) diff --git a/crates/matrix-sdk-base/src/media.rs b/crates/matrix-sdk-base/src/media.rs index c2018e89a..32356e989 100644 --- a/crates/matrix-sdk-base/src/media.rs +++ b/crates/matrix-sdk-base/src/media.rs @@ -60,7 +60,7 @@ pub struct MediaThumbnailSize { impl UniqueKey for MediaThumbnailSize { fn unique_key(&self) -> String { - format!("{}{}{}x{}", self.method, UNIQUE_SEPARATOR, self.width, self.height) + format!("{}{UNIQUE_SEPARATOR}{}x{}", self.method, self.width, self.height) } } @@ -85,7 +85,7 @@ pub struct MediaRequest { impl UniqueKey for MediaRequest { fn unique_key(&self) -> String { - format!("{}{}{}", self.source.unique_key(), UNIQUE_SEPARATOR, self.format.unique_key()) + format!("{}{UNIQUE_SEPARATOR}{}", self.source.unique_key(), self.format.unique_key()) } } /// Trait for media event content. diff --git a/crates/matrix-sdk-crypto/src/gossiping/mod.rs b/crates/matrix-sdk-crypto/src/gossiping/mod.rs index db598e9c2..3ce5c27de 100644 --- a/crates/matrix-sdk-crypto/src/gossiping/mod.rs +++ b/crates/matrix-sdk-crypto/src/gossiping/mod.rs @@ -96,7 +96,7 @@ impl SecretInfo { info.session_id(), &info.algorithm(), ), - SecretInfo::SecretRequest(ref sname) => format!("secretName:{:}", sname), + SecretInfo::SecretRequest(ref sname) => format!("secretName:{sname:}"), } } } diff --git a/crates/matrix-sdk-crypto/src/machine.rs b/crates/matrix-sdk-crypto/src/machine.rs index 6c6edad6f..fbdec2bf2 100644 --- a/crates/matrix-sdk-crypto/src/machine.rs +++ b/crates/matrix-sdk-crypto/src/machine.rs @@ -1981,7 +1981,7 @@ pub(crate) mod tests { if let AnyToDeviceEvent::Dummy(e) = event { assert_eq!(&e.sender, alice.user_id()); } else { - panic!("Wrong event type found {:?}", event); + panic!("Wrong event type found {event:?}"); } } @@ -2019,7 +2019,7 @@ pub(crate) mod tests { assert_eq!(&event.sender, alice.user_id()); assert!(event.content.session_key.is_empty()); } else { - panic!("expected RoomKeyEvent found {:?}", event); + panic!("expected RoomKeyEvent found {event:?}"); } let session = @@ -2298,7 +2298,7 @@ pub(crate) mod tests { // Bob verifies that the MAC is valid and also sends a "done" message. let msgs = bob.verification_machine.outgoing_messages(); - eprintln!("{:?}", msgs); + eprintln!("{msgs:?}"); assert!(msgs.len() == 1); let event = msgs.first().map(|r| outgoing_request_to_event(bob.user_id(), r)).unwrap(); @@ -2319,7 +2319,7 @@ pub(crate) mod tests { assert!(!alice_sas.is_done()); assert!(!bob_device.is_verified()); // Alices receives the done message - eprintln!("{:?}", event); + eprintln!("{event:?}"); alice.handle_verification_event(&event).await; assert!(alice_sas.is_done()); diff --git a/crates/matrix-sdk-crypto/src/olm/account.rs b/crates/matrix-sdk-crypto/src/olm/account.rs index 943098cd8..1de7f31cb 100644 --- a/crates/matrix-sdk-crypto/src/olm/account.rs +++ b/crates/matrix-sdk-crypto/src/olm/account.rs @@ -138,7 +138,7 @@ impl OlmMessageHash { let sha = Sha256::new() .chain_update(sender_key.as_bytes()) .chain_update([message_type as u8]) - .chain_update(&ciphertext) + .chain_update(ciphertext) .finalize(); Self { sender_key, hash: encode(sha.as_slice()) } diff --git a/crates/matrix-sdk-crypto/src/verification/mod.rs b/crates/matrix-sdk-crypto/src/verification/mod.rs index 7799b1d17..b5018afa0 100644 --- a/crates/matrix-sdk-crypto/src/verification/mod.rs +++ b/crates/matrix-sdk-crypto/src/verification/mod.rs @@ -100,7 +100,7 @@ pub fn format_emojis(emojis: [Emoji; 7]) -> String { // Hack to make terminals behave properly when one of the above is printed. let emoji = if VARIATION_SELECTOR_EMOJIS.contains(&emoji) { - format!("{} ", emoji) + format!("{emoji} ") } else { emoji.to_owned() }; @@ -109,13 +109,12 @@ pub fn format_emojis(emojis: [Emoji; 7]) -> String { // monospace characters. let placeholder = ".".repeat(EMOJI_WIDTH); - format!("{:^12}", placeholder).replace(&placeholder, &emoji) + format!("{placeholder:^12}").replace(&placeholder, &emoji) }; let emoji_string = emojis.iter().map(|e| center_emoji(e)).collect::>().join(""); - let description = - descriptions.iter().map(|d| format!("{:^12}", d)).collect::>().join(""); + let description = descriptions.iter().map(|d| format!("{d:^12}")).collect::>().join(""); format!("{emoji_string}\n{description}") } diff --git a/crates/matrix-sdk-crypto/src/verification/sas/helpers.rs b/crates/matrix-sdk-crypto/src/verification/sas/helpers.rs index da617e73a..860f797bb 100644 --- a/crates/matrix-sdk-crypto/src/verification/sas/helpers.rs +++ b/crates/matrix-sdk-crypto/src/verification/sas/helpers.rs @@ -62,7 +62,7 @@ pub fn calculate_commitment(public_key: Curve25519PublicKey, content: &StartCont Base64::new( Sha256::new() .chain_update(public_key.to_base64()) - .chain_update(&content_string) + .chain_update(content_string) .finalize() .as_slice() .to_owned(), @@ -228,7 +228,7 @@ pub fn receive_mac_event( if let Some(key) = ids.other_device.keys().get(&key_id) { let calculated_mac = Base64::parse( - sas.calculate_mac_invalid_base64(&key.to_base64(), &format!("{}{}", info, key_id)), + sas.calculate_mac_invalid_base64(&key.to_base64(), &format!("{info}{key_id}")), ) .expect("Can't base64-decode SAS MAC"); diff --git a/crates/matrix-sdk-indexeddb/src/crypto_store.rs b/crates/matrix-sdk-indexeddb/src/crypto_store.rs index b453a918b..b0d469359 100644 --- a/crates/matrix-sdk-indexeddb/src/crypto_store.rs +++ b/crates/matrix-sdk-indexeddb/src/crypto_store.rs @@ -140,7 +140,7 @@ impl IndexeddbCryptoStore { prefix: &str, store_cipher: Option>, ) -> Result { - let name = format!("{:0}::matrix-sdk-crypto", prefix); + let name = format!("{prefix:0}::matrix-sdk-crypto"); // Open my_db v1 let mut db_req: OpenDbRequest = IdbDatabase::open_f64(&name, 1.1)?; @@ -232,7 +232,7 @@ impl IndexeddbCryptoStore { /// Open a new `IndexeddbCryptoStore` with given name and passphrase pub async fn open_with_passphrase(prefix: &str, passphrase: &str) -> Result { - let name = format!("{:0}::matrix-sdk-crypto-meta", prefix); + let name = format!("{prefix:0}::matrix-sdk-crypto-meta"); let mut db_req: OpenDbRequest = IdbDatabase::open_f64(&name, 1.0)?; db_req.set_on_upgrade_needed(Some(|evt: &IdbVersionChangeEvent| -> Result<(), JsValue> { @@ -907,7 +907,7 @@ impl IndexeddbCryptoStore { if let Some(inner) = request { tx.object_store(KEYS::SECRET_REQUESTS_BY_INFO)? - .delete(&self.encode_key(KEYS::KEY_REQUEST, &inner.info.as_key()))?; + .delete(&self.encode_key(KEYS::KEY_REQUEST, inner.info.as_key()))?; } tx.object_store(KEYS::UNSENT_SECRET_REQUESTS)?.delete(&jskey)?; diff --git a/crates/matrix-sdk-indexeddb/src/safe_encode.rs b/crates/matrix-sdk-indexeddb/src/safe_encode.rs index 55bfe4df4..e26486088 100644 --- a/crates/matrix-sdk-indexeddb/src/safe_encode.rs +++ b/crates/matrix-sdk-indexeddb/src/safe_encode.rs @@ -61,7 +61,7 @@ pub trait SafeEncode { /// 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!("{}{}{:016x}", self.as_encoded_string(), KEY_SEPARATOR, i).into() + format!("{}{KEY_SEPARATOR}{i:016x}", self.as_encoded_string()).into() } /// encode self into a JsValue, internally using `as_secure_string` diff --git a/crates/matrix-sdk-indexeddb/src/state_store.rs b/crates/matrix-sdk-indexeddb/src/state_store.rs index 8f45dbbf0..62a8890d0 100644 --- a/crates/matrix-sdk-indexeddb/src/state_store.rs +++ b/crates/matrix-sdk-indexeddb/src/state_store.rs @@ -191,7 +191,7 @@ fn create_stores(db: &IdbDatabase) -> Result<(), JsValue> { async fn backup(source: &IdbDatabase, meta: &IdbDatabase) -> Result<()> { let now = JsDate::now(); - let backup_name = format!("backup-{}-{}", source.name(), now); + let backup_name = format!("backup-{}-{now}", source.name()); let mut db_req: OpenDbRequest = IdbDatabase::open_f64(&backup_name, source.version())?; db_req.set_on_upgrade_needed(Some(move |evt: &IdbVersionChangeEvent| -> Result<(), JsValue> { @@ -257,7 +257,7 @@ impl IndexeddbStateStoreBuilder { .unwrap_or(MigrationConflictStrategy::BackupAndDrop); let name = self.name.clone().unwrap_or_else(|| "state".to_owned()); - let meta_name = format!("{}::{}", name, KEYS::INTERNAL_STATE); + let meta_name = format!("{name}::{}", KEYS::INTERNAL_STATE); let mut db_req: OpenDbRequest = IdbDatabase::open_f64(&meta_name, KEYS::CURRENT_META_DB_VERSION)?; diff --git a/crates/matrix-sdk-sled/src/crypto_store.rs b/crates/matrix-sdk-sled/src/crypto_store.rs index 7beceea3d..1c244154c 100644 --- a/crates/matrix-sdk-sled/src/crypto_store.rs +++ b/crates/matrix-sdk-sled/src/crypto_store.rs @@ -792,7 +792,7 @@ impl CryptoStore for SledCryptoStore { let key = self.encode_key(INBOUND_GROUP_TABLE_NAME, (room_id, session_id)); let pickle = self .inbound_group_sessions - .get(&key) + .get(key) .map_err(CryptoStoreError::backend)? .map(|p| self.deserialize_value(&p)); diff --git a/crates/matrix-sdk-sled/src/state_store.rs b/crates/matrix-sdk-sled/src/state_store.rs index 88a11edbf..46ad8cff5 100644 --- a/crates/matrix-sdk-sled/src/state_store.rs +++ b/crates/matrix-sdk-sled/src/state_store.rs @@ -690,7 +690,7 @@ impl SledStateStore { let make_room_version = |room_id| { self.room_info - .get(&self.encode_key(ROOM_INFO, room_id)) + .get(self.encode_key(ROOM_INFO, room_id)) .ok() .flatten() .map(|r| self.deserialize_value::(&r)) @@ -1577,7 +1577,7 @@ mod migration { if let Err(SledStoreError::MigrationConflict { .. }) = res { // all good } else { - panic!("Didn't raise the expected error: {:?}", res); + panic!("Didn't raise the expected error: {res:?}"); } assert_eq!(std::fs::read_dir(folder.path())?.count(), 1); Ok(()) diff --git a/crates/matrix-sdk/src/error.rs b/crates/matrix-sdk/src/error.rs index ad28e05de..e1e6c565d 100644 --- a/crates/matrix-sdk/src/error.rs +++ b/crates/matrix-sdk/src/error.rs @@ -319,7 +319,7 @@ impl From for Error { _ => Self::UnknownError(anyhow::anyhow!(e).into()), #[cfg(all(not(feature = "eyre"), not(feature = "anyhow")))] _ => { - let e: Box = format!("{:?}", e).into(); + let e: Box = format!("{e:?}").into(); Self::UnknownError(e) } }