[pbs-devel] [PATCH proxmox 03/18] remove needless borrows

Maximiliano Sandoval m.sandoval at proxmox.com
Wed Jun 26 12:44:59 CEST 2024


Fixes the following clippy warnings:

warning: the borrowed expression implements the required traits
  --> proxmox-tfa/src/api/recovery.rs:86:24
   |
86 |         Ok(hex::encode(&hmac))
   |                        ^^^^^ help: change this to: `hmac`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args

and

warning: this expression creates a reference which is immediately dereferenced by the compiler
   --> proxmox-network-api/src/api_impl.rs:108:47
    |
108 |                 interface.set_bond_slave_list(&slaves)?;
    |                                               ^^^^^^^ help: change this to: `slaves`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
    = note: `#[warn(clippy::needless_borrow)]` on by default

Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
---
 proxmox-acme-api/src/account_api_impl.rs  |  8 ++++----
 proxmox-auth-api/src/pam_authenticator.rs |  2 +-
 proxmox-auth-api/src/ticket.rs            |  2 +-
 proxmox-client/src/client.rs              |  4 ++--
 proxmox-network-api/src/api_impl.rs       |  2 +-
 proxmox-tfa/src/api/recovery.rs           |  4 ++--
 proxmox-tfa/src/u2f.rs                    | 12 ++++++------
 7 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/proxmox-acme-api/src/account_api_impl.rs b/proxmox-acme-api/src/account_api_impl.rs
index 71880e62..3a06dcc6 100644
--- a/proxmox-acme-api/src/account_api_impl.rs
+++ b/proxmox-acme-api/src/account_api_impl.rs
@@ -70,7 +70,7 @@ pub async fn register_account(
 
     let account = AccountData::from_account_dir_tos(account, directory_url, tos_url);
 
-    super::account_config::create_account_config(&name, &account)?;
+    super::account_config::create_account_config(name, &account)?;
 
     Ok(account.location)
 }
@@ -89,7 +89,7 @@ pub async fn deactivate_account(
     {
         Ok(account) => {
             account_data.account = account.data.clone();
-            super::account_config::save_account_config(&name, &account_data)?;
+            super::account_config::save_account_config(name, &account_data)?;
         }
         Err(err) if !force => return Err(err),
         Err(err) => {
@@ -102,7 +102,7 @@ pub async fn deactivate_account(
         }
     }
 
-    super::account_config::mark_account_deactivated(&name)?;
+    super::account_config::mark_account_deactivated(name)?;
 
     Ok(())
 }
@@ -120,7 +120,7 @@ pub async fn update_account(name: &AcmeAccountName, contact: Option<String>) ->
 
     let account = client.update_account(&data).await?;
     account_data.account = account.data.clone();
-    super::account_config::save_account_config(&name, &account_data)?;
+    super::account_config::save_account_config(name, &account_data)?;
 
     Ok(())
 }
diff --git a/proxmox-auth-api/src/pam_authenticator.rs b/proxmox-auth-api/src/pam_authenticator.rs
index fb8e7e7e..d34575be 100644
--- a/proxmox-auth-api/src/pam_authenticator.rs
+++ b/proxmox-auth-api/src/pam_authenticator.rs
@@ -183,7 +183,7 @@ struct PamGuard<'a> {
 
 impl Drop for PamGuard<'_> {
     fn drop(&mut self) {
-        pam_sys::wrapped::end(&mut self.handle, self.result);
+        pam_sys::wrapped::end(self.handle, self.result);
     }
 }
 
diff --git a/proxmox-auth-api/src/ticket.rs b/proxmox-auth-api/src/ticket.rs
index ff088158..498e9385 100644
--- a/proxmox-auth-api/src/ticket.rs
+++ b/proxmox-auth-api/src/ticket.rs
@@ -160,7 +160,7 @@ where
 
         let is_valid = keyring.verify(
             MessageDigest::sha256(),
-            &signature,
+            signature,
             &self.verification_data(aad),
         )?;
 
diff --git a/proxmox-client/src/client.rs b/proxmox-client/src/client.rs
index 1cae2883..fe18097a 100644
--- a/proxmox-client/src/client.rs
+++ b/proxmox-client/src/client.rs
@@ -52,7 +52,7 @@ impl TlsOptions {
             .filter(|&b| b != b':')
             .collect();
 
-        let fp = <[u8; 32]>::from_hex(&hex).map_err(|_| ParseFingerprintError)?;
+        let fp = <[u8; 32]>::from_hex(hex).map_err(|_| ParseFingerprintError)?;
 
         Ok(Self::Fingerprint(fp.into()))
     }
@@ -469,7 +469,7 @@ fn verify_fingerprint(chain: &x509::X509StoreContextRef, expected_fingerprint: &
 
     if expected_fingerprint != fp.as_ref() {
         log::error!("bad fingerprint: {}", fp_string(&fp));
-        log::error!("expected fingerprint: {}", fp_string(&expected_fingerprint));
+        log::error!("expected fingerprint: {}", fp_string(expected_fingerprint));
         return false;
     }
 
diff --git a/proxmox-network-api/src/api_impl.rs b/proxmox-network-api/src/api_impl.rs
index b3b9ec53..18602900 100644
--- a/proxmox-network-api/src/api_impl.rs
+++ b/proxmox-network-api/src/api_impl.rs
@@ -105,7 +105,7 @@ pub fn create_interface(iface: String, config: InterfaceUpdater) -> Result<(), E
                 }
             }
             if let Some(slaves) = &config.slaves {
-                interface.set_bond_slave_list(&slaves)?;
+                interface.set_bond_slave_list(slaves)?;
             }
         }
         NetworkInterfaceType::Vlan => {
diff --git a/proxmox-tfa/src/api/recovery.rs b/proxmox-tfa/src/api/recovery.rs
index 970770b6..9629d6ff 100644
--- a/proxmox-tfa/src/api/recovery.rs
+++ b/proxmox-tfa/src/api/recovery.rs
@@ -49,7 +49,7 @@ impl Recovery {
         getrandom(&mut secret)?;
 
         let mut this = Self {
-            secret: hex::encode(&secret),
+            secret: hex::encode(secret),
             entries: Vec::with_capacity(10),
             created: proxmox_time::epoch_i64(),
         };
@@ -83,7 +83,7 @@ impl Recovery {
             .sign_oneshot_to_vec(data)
             .map_err(|err| format_err!("error calculating hmac: {}", err))?;
 
-        Ok(hex::encode(&hmac))
+        Ok(hex::encode(hmac))
     }
 
     /// Iterator over available keys.
diff --git a/proxmox-tfa/src/u2f.rs b/proxmox-tfa/src/u2f.rs
index 43907a19..04a8f5af 100644
--- a/proxmox-tfa/src/u2f.rs
+++ b/proxmox-tfa/src/u2f.rs
@@ -36,9 +36,9 @@ impl StdError for Error {
 impl fmt::Display for Error {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match self {
-            Error::Generic(e) => f.write_str(&e),
-            Error::Decode(m, _e) => f.write_str(&m),
-            Error::Ssl(m, _e) => f.write_str(&m),
+            Error::Generic(e) => f.write_str(e),
+            Error::Decode(m, _e) => f.write_str(m),
+            Error::Ssl(m, _e) => f.write_str(m),
         }
     }
 }
@@ -604,13 +604,13 @@ mod bytes_as_base64 {
     use serde::{Deserialize, Deserializer, Serializer};
 
     pub fn serialize<S: Serializer>(data: &[u8], serializer: S) -> Result<S::Ok, S::Error> {
-        serializer.serialize_str(&base64::encode(&data))
+        serializer.serialize_str(&base64::encode(data))
     }
 
     pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Vec<u8>, D::Error> {
         use serde::de::Error;
         String::deserialize(deserializer).and_then(|string| {
-            base64::decode(&string).map_err(|err| Error::custom(err.to_string()))
+            base64::decode(string).map_err(|err| Error::custom(err.to_string()))
         })
     }
 }
@@ -625,7 +625,7 @@ mod bytes_as_base64url_nopad {
     pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Vec<u8>, D::Error> {
         use serde::de::Error;
         String::deserialize(deserializer).and_then(|string| {
-            base64::decode_config(&string, base64::URL_SAFE_NO_PAD)
+            base64::decode_config(string, base64::URL_SAFE_NO_PAD)
                 .map_err(|err| Error::custom(err.to_string()))
         })
     }
-- 
2.39.2





More information about the pbs-devel mailing list