From d6d4e0d7379bc3d05c7d7064a25b402cb0270651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Klocek?= Date: Tue, 21 May 2024 15:05:06 +0200 Subject: [PATCH] [rust] Fix Clippy warnings Summary: Fixed all remaining Clippy warnings for the workspace Depends on D12178 Test Plan: No more Clippy warnings when running `cargo check` or `cargo clippy` Reviewers: varun Reviewed By: varun Subscribers: ashoat, tomek Differential Revision: https://phab.comm.dev/D12179 --- keyserver/addons/rust-node-addon/src/identity_client/login.rs | 1 + keyserver/addons/rust-node-addon/src/identity_client/mod.rs | 1 + .../rust-node-addon/src/identity_client/register_user.rs | 1 + native/native_rust_library/src/backup.rs | 4 ++-- native/native_rust_library/src/identity/login.rs | 1 + native/native_rust_library/src/identity/registration.rs | 1 + native/native_rust_library/src/identity/x3dh.rs | 1 + native/native_rust_library/src/lib.rs | 1 + services/blob/src/service.rs | 2 +- services/commtest/src/identity/mod.rs | 2 +- services/commtest/tests/identity_access_tokens_tests.rs | 2 +- services/commtest/tests/identity_one_time_key_tests.rs | 4 ++-- services/identity/src/database.rs | 1 + services/identity/src/grpc_services/authenticated.rs | 1 + services/identity/src/grpc_services/shared.rs | 4 ++-- services/identity/src/regex.rs | 4 ++++ services/identity/src/siwe.rs | 1 + shared/comm-lib/src/lib.rs | 3 +++ 18 files changed, 26 insertions(+), 9 deletions(-) diff --git a/keyserver/addons/rust-node-addon/src/identity_client/login.rs b/keyserver/addons/rust-node-addon/src/identity_client/login.rs index 1deaf364b0..6434a195b4 100644 --- a/keyserver/addons/rust-node-addon/src/identity_client/login.rs +++ b/keyserver/addons/rust-node-addon/src/identity_client/login.rs @@ -9,6 +9,7 @@ use tracing::debug; #[napi] #[instrument(skip_all)] +#[allow(clippy::too_many_arguments)] pub async fn login_user( username: String, password: String, diff --git a/keyserver/addons/rust-node-addon/src/identity_client/mod.rs b/keyserver/addons/rust-node-addon/src/identity_client/mod.rs index 526e60596a..593b6ea31d 100644 --- a/keyserver/addons/rust-node-addon/src/identity_client/mod.rs +++ b/keyserver/addons/rust-node-addon/src/identity_client/mod.rs @@ -212,6 +212,7 @@ mod tests { use super::CODE_VERSION; #[test] + #[allow(clippy::assertions_on_constants)] fn test_code_version_exists() { assert!(CODE_VERSION > 0); } diff --git a/keyserver/addons/rust-node-addon/src/identity_client/register_user.rs b/keyserver/addons/rust-node-addon/src/identity_client/register_user.rs index 25de312362..7834b1273f 100644 --- a/keyserver/addons/rust-node-addon/src/identity_client/register_user.rs +++ b/keyserver/addons/rust-node-addon/src/identity_client/register_user.rs @@ -4,6 +4,7 @@ use tracing::{debug, warn}; #[napi] #[instrument(skip_all)] +#[allow(clippy::too_many_arguments)] pub async fn register_user( username: String, password: String, diff --git a/native/native_rust_library/src/backup.rs b/native/native_rust_library/src/backup.rs index d33dade103..2ef08bbf83 100644 --- a/native/native_rust_library/src/backup.rs +++ b/native/native_rust_library/src/backup.rs @@ -296,10 +296,10 @@ pub async fn create_userkeys_compaction( } pub async fn create_siwe_backup_msg_compaction( - backup_id: &String, + backup_id: &str, siwe_backup_msg: String, ) -> Result<(), Box> { - let siwe_backup_msg_file = get_siwe_backup_message_path(&backup_id)?; + let siwe_backup_msg_file = get_siwe_backup_message_path(backup_id)?; tokio::fs::write(siwe_backup_msg_file, siwe_backup_msg).await?; Ok(()) diff --git a/native/native_rust_library/src/identity/login.rs b/native/native_rust_library/src/identity/login.rs index 6f858c40ed..9a2c795bda 100644 --- a/native/native_rust_library/src/identity/login.rs +++ b/native/native_rust_library/src/identity/login.rs @@ -13,6 +13,7 @@ use super::{IdentityAuthResult, LogInPasswordUserInfo, LogInWalletUserInfo}; use crate::utils::jsi_callbacks::handle_string_result_as_callback; use crate::{Error, CODE_VERSION, DEVICE_TYPE, IDENTITY_SOCKET_ADDR, RUNTIME}; +#[allow(clippy::too_many_arguments)] pub mod ffi { use crate::identity::{ DeviceKeys, LogInPasswordUserInfo, LogInWalletUserInfo, diff --git a/native/native_rust_library/src/identity/registration.rs b/native/native_rust_library/src/identity/registration.rs index 26992c1e76..a878eeae76 100644 --- a/native/native_rust_library/src/identity/registration.rs +++ b/native/native_rust_library/src/identity/registration.rs @@ -19,6 +19,7 @@ use super::{ RegisterReservedWalletUserInfo, RegisterWalletUserInfo, }; +#[allow(clippy::too_many_arguments)] pub mod ffi { use crate::identity::{ DeviceKeys, RegisterPasswordUserInfo, RegisterReservedPasswordUserInfo, diff --git a/native/native_rust_library/src/identity/x3dh.rs b/native/native_rust_library/src/identity/x3dh.rs index 261af7b927..52c3e850ed 100644 --- a/native/native_rust_library/src/identity/x3dh.rs +++ b/native/native_rust_library/src/identity/x3dh.rs @@ -86,6 +86,7 @@ pub mod ffi { }); } + #[allow(clippy::too_many_arguments)] pub fn refresh_user_prekeys( auth_user_id: String, auth_device_id: String, diff --git a/native/native_rust_library/src/lib.rs b/native/native_rust_library/src/lib.rs index a4a072b0e5..b00dde03ba 100644 --- a/native/native_rust_library/src/lib.rs +++ b/native/native_rust_library/src/lib.rs @@ -41,6 +41,7 @@ use backup::ffi::*; use identity::ffi::*; use utils::future_manager::ffi::*; +#[allow(clippy::too_many_arguments)] #[cxx::bridge] mod ffi { diff --git a/services/blob/src/service.rs b/services/blob/src/service.rs index 0e3a42743d..8d68195aac 100644 --- a/services/blob/src/service.rs +++ b/services/blob/src/service.rs @@ -168,7 +168,7 @@ impl BlobService { if let Some(invite_secret) = blob_hash.strip_prefix(INVITE_LINK_BLOB_HASH_PREFIX) { - Self::validate_invite_link_blob_hash(&invite_secret)?; + Self::validate_invite_link_blob_hash(invite_secret)?; } let mut upload_session = diff --git a/services/commtest/src/identity/mod.rs b/services/commtest/src/identity/mod.rs index 241171e631..fdc6413e0d 100644 --- a/services/commtest/src/identity/mod.rs +++ b/services/commtest/src/identity/mod.rs @@ -37,7 +37,7 @@ impl SigningCapableAccount { } /// signs message, returns signature - pub fn sign_message(&mut self, message: &str) -> String { + pub fn sign_message(&self, message: &str) -> String { let signature: Signature = self.signing_key.sign(message.as_bytes()); base64::engine::general_purpose::STANDARD_NO_PAD .encode(signature.to_bytes()) diff --git a/services/commtest/tests/identity_access_tokens_tests.rs b/services/commtest/tests/identity_access_tokens_tests.rs index 45f155515b..dd186924be 100644 --- a/services/commtest/tests/identity_access_tokens_tests.rs +++ b/services/commtest/tests/identity_access_tokens_tests.rs @@ -43,7 +43,7 @@ async fn refresh_token_test() { .await .expect("Couldn't connect to identity service"); - let mut account = SigningCapableAccount::new(); + let account = SigningCapableAccount::new(); let client_keys = account.public_keys(); let user = register_user_device(Some(&client_keys), None).await; diff --git a/services/commtest/tests/identity_one_time_key_tests.rs b/services/commtest/tests/identity_one_time_key_tests.rs index d7b88293f7..9857f82b4e 100644 --- a/services/commtest/tests/identity_one_time_key_tests.rs +++ b/services/commtest/tests/identity_one_time_key_tests.rs @@ -81,8 +81,8 @@ async fn max_hundred_keys_in_ddb() { (0..20).map(|_| generate_random_olm_key()).collect(); if request_num == 0 { - expected_first_retrieved_content_key = content_keys.get(0).cloned(); - expected_first_retrieved_notif_key = notif_keys.get(0).cloned(); + expected_first_retrieved_content_key = content_keys.first().cloned(); + expected_first_retrieved_notif_key = notif_keys.first().cloned(); expected_second_retrieved_content_key = content_keys.get(5).cloned(); expected_second_retrieved_notif_key = notif_keys.get(5).cloned(); } diff --git a/services/identity/src/database.rs b/services/identity/src/database.rs index 0bb210b7ab..9e97ab3b83 100644 --- a/services/identity/src/database.rs +++ b/services/identity/src/database.rs @@ -207,6 +207,7 @@ impl DatabaseClient { Ok(user_id) } + #[allow(clippy::too_many_arguments)] pub async fn add_wallet_user_to_users_table( &self, flattened_device_key_upload: FlattenedDeviceKeyUpload, diff --git a/services/identity/src/grpc_services/authenticated.rs b/services/identity/src/grpc_services/authenticated.rs index 33dd565e56..11afb67aa1 100644 --- a/services/identity/src/grpc_services/authenticated.rs +++ b/services/identity/src/grpc_services/authenticated.rs @@ -677,6 +677,7 @@ impl IdentityClientService for AuthenticatedService { } } +#[allow(dead_code)] enum DeviceListItemKind { Any, Primary, diff --git a/services/identity/src/grpc_services/shared.rs b/services/identity/src/grpc_services/shared.rs index e1f3bc4e09..9507d70b8c 100644 --- a/services/identity/src/grpc_services/shared.rs +++ b/services/identity/src/grpc_services/shared.rs @@ -1,6 +1,6 @@ use grpc_clients::error::unsupported_version; -use tonic::{IntoRequest, Request, Status}; -use tracing::{trace, Instrument}; +use tonic::{Request, Status}; +use tracing::trace; use crate::constants::{request_metadata, MIN_SUPPORTED_NATIVE_VERSION}; diff --git a/services/identity/src/regex.rs b/services/identity/src/regex.rs index dfa1888b37..197ed265ce 100644 --- a/services/identity/src/regex.rs +++ b/services/identity/src/regex.rs @@ -29,11 +29,13 @@ mod tests { )); } + #[allow(clippy::bool_assert_comparison)] #[test] fn test_invalid_username_too_short() { assert_eq!(is_valid_username(""), false); } + #[allow(clippy::bool_assert_comparison)] #[test] fn test_invalid_username_too_long() { assert_eq!( @@ -42,11 +44,13 @@ mod tests { ); } + #[allow(clippy::bool_assert_comparison)] #[test] fn test_invalid_username_first_char_non_alphanumeric() { assert_eq!(is_valid_username("-asdf"), false); } + #[allow(clippy::bool_assert_comparison)] #[test] fn test_invalid_username_invalid_symbol() { assert_eq!(is_valid_username("asdf$"), false); diff --git a/services/identity/src/siwe.rs b/services/identity/src/siwe.rs index 45680da02d..fcdd895149 100644 --- a/services/identity/src/siwe.rs +++ b/services/identity/src/siwe.rs @@ -121,6 +121,7 @@ mod tests { )); } + #[allow(clippy::bool_assert_comparison)] #[test] fn test_invalid_ethereum_address() { // Shorter than 42 characters diff --git a/shared/comm-lib/src/lib.rs b/shared/comm-lib/src/lib.rs index e8bd3b2f59..3405698540 100644 --- a/shared/comm-lib/src/lib.rs +++ b/shared/comm-lib/src/lib.rs @@ -11,6 +11,7 @@ pub mod http; pub mod shared; pub mod tools; +#[allow(unused_imports)] mod reexports { #[cfg(feature = "blob-client")] pub use {bytes, reqwest}; @@ -30,4 +31,6 @@ mod reexports { pub use ddb::Error as DynamoDBError; } } + +#[allow(unused_imports)] pub use reexports::*;