From 752d40512e1a7576c7f48b562feab2942462b874 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Mon, 7 Jul 2025 12:05:05 +0200 Subject: [PATCH] context: Avoid clippy errors error: variables can be used directly in the `format!` string --> cryptoki/src/context/general_purpose.rs:161:9 | 161 | write!(f, "Function::{:?}", self) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args = note: `-D clippy::uninlined-format-args` implied by `-D clippy::all` = help: to override `-D clippy::all` add `#[allow(clippy::uninlined_format_args)]` Many similar also lived in tests Signed-off-by: Jakub Jelen --- cryptoki/src/context/general_purpose.rs | 2 +- cryptoki/tests/basic.rs | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/cryptoki/src/context/general_purpose.rs b/cryptoki/src/context/general_purpose.rs index be7ead9d..6177c3dd 100644 --- a/cryptoki/src/context/general_purpose.rs +++ b/cryptoki/src/context/general_purpose.rs @@ -145,7 +145,7 @@ pub enum Function { impl Display for Function { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "Function::{:?}", self) + write!(f, "Function::{self:?}") } } diff --git a/cryptoki/tests/basic.rs b/cryptoki/tests/basic.rs index 2cd3d4ab..dede2e93 100644 --- a/cryptoki/tests/basic.rs +++ b/cryptoki/tests/basic.rs @@ -774,7 +774,7 @@ fn session_find_objects() -> testresult::TestResult { let key_template = vec![ Attribute::Token(true), Attribute::Encrypt(true), - Attribute::Label(format!("key_{}", i).as_bytes().to_vec()), + Attribute::Label(format!("key_{i}").as_bytes().to_vec()), Attribute::ValueLen(32.into()), Attribute::Id("12345678".as_bytes().to_vec()), // reusing the same CKA_ID ]; @@ -826,7 +826,7 @@ fn session_objecthandle_iterator() -> testresult::TestResult { Attribute::Token(true), Attribute::Encrypt(true), Attribute::ValueLen(32.into()), - Attribute::Label(format!("key_{}", i).as_bytes().to_vec()), + Attribute::Label(format!("key_{i}").as_bytes().to_vec()), Attribute::Id("12345678".as_bytes().to_vec()), // reusing the same CKA_ID ]; @@ -1000,27 +1000,27 @@ fn login_feast() { let session = pkcs11.open_rw_session(slot).unwrap(); match session.login(UserType::User, Some(&AuthPin::new(USER_PIN.into()))) { Ok(_) | Err(Error::Pkcs11(RvError::UserAlreadyLoggedIn, Function::Login)) => {} - Err(e) => panic!("Bad error response: {}", e), + Err(e) => panic!("Bad error response: {e}"), } match session.login(UserType::User, Some(&AuthPin::new(USER_PIN.into()))) { Ok(_) | Err(Error::Pkcs11(RvError::UserAlreadyLoggedIn, Function::Login)) => {} - Err(e) => panic!("Bad error response: {}", e), + Err(e) => panic!("Bad error response: {e}"), } match session.login(UserType::User, Some(&AuthPin::new(USER_PIN.into()))) { Ok(_) | Err(Error::Pkcs11(RvError::UserAlreadyLoggedIn, Function::Login)) => {} - Err(e) => panic!("Bad error response: {}", e), + Err(e) => panic!("Bad error response: {e}"), } match session.logout() { Ok(_) | Err(Error::Pkcs11(RvError::UserNotLoggedIn, Function::Logout)) => {} - Err(e) => panic!("Bad error response: {}", e), + Err(e) => panic!("Bad error response: {e}"), } match session.logout() { Ok(_) | Err(Error::Pkcs11(RvError::UserNotLoggedIn, Function::Logout)) => {} - Err(e) => panic!("Bad error response: {}", e), + Err(e) => panic!("Bad error response: {e}"), } match session.logout() { Ok(_) | Err(Error::Pkcs11(RvError::UserNotLoggedIn, Function::Logout)) => {} - Err(e) => panic!("Bad error response: {}", e), + Err(e) => panic!("Bad error response: {e}"), } })); } @@ -1317,7 +1317,7 @@ fn is_initialized_test() { match pkcs11.initialize(CInitializeArgs::OsThreads) { Err(Error::AlreadyInitialized) => (), - Err(e) => panic!("Got unexpected error when initializing: {}", e), + Err(e) => panic!("Got unexpected error when initializing: {e}"), Ok(()) => panic!("Initializing twice should not have been allowed"), } } @@ -1429,7 +1429,7 @@ fn ro_rw_session_test() -> TestResult { if let Error::Pkcs11(RvError::SessionReadOnly, _f) = e { // as expected } else { - panic!("Got wrong error code (expecting SessionReadOnly): {}", e); + panic!("Got wrong error code (expecting SessionReadOnly): {e}"); } ro_session.logout()?; } @@ -2075,8 +2075,7 @@ fn wait_for_slot_event() { Function::WaitForSlotEvent )) ), - "res = {:?}", - res + "res = {res:?}" ); }