public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox 01/15] clippy fix: the borrowed expression implements the required traits
@ 2023-08-08  8:01 Lukas Wagner
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 02/15] clippy fix: casting to the same type is unnecessary Lukas Wagner
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: Lukas Wagner @ 2023-08-08  8:01 UTC (permalink / raw)
  To: pbs-devel

See: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-apt/src/repositories/file.rs       |  2 +-
 proxmox-apt/src/repositories/repository.rs |  2 +-
 proxmox-openid/src/auth_state.rs           |  2 +-
 proxmox-rest-server/src/worker_task.rs     | 10 +++++-----
 proxmox-schema/src/ser/mod.rs              |  4 ++--
 proxmox-serde/src/lib.rs                   |  9 ++++-----
 proxmox-subscription/src/check.rs          |  2 +-
 7 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/proxmox-apt/src/repositories/file.rs b/proxmox-apt/src/repositories/file.rs
index b4c6b08..bfd7836 100644
--- a/proxmox-apt/src/repositories/file.rs
+++ b/proxmox-apt/src/repositories/file.rs
@@ -293,7 +293,7 @@ impl APTRepositoryFile {
         }
 
         if self.repositories.is_empty() {
-            return std::fs::remove_file(&path)
+            return std::fs::remove_file(path)
                 .map_err(|err| self.err(format_err!("unable to remove file - {}", err)));
         }
 
diff --git a/proxmox-apt/src/repositories/repository.rs b/proxmox-apt/src/repositories/repository.rs
index c2df2c7..0b04802 100644
--- a/proxmox-apt/src/repositories/repository.rs
+++ b/proxmox-apt/src/repositories/repository.rs
@@ -414,7 +414,7 @@ fn uri_to_filename(uri: &str) -> String {
         if *b <= 0x20 || *b >= 0x7F || encode_chars.contains(*b as char) {
             let mut hex = [0u8; 2];
             // unwrap: we're hex-encoding a single byte into a 2-byte slice
-            hex::encode_to_slice(&[*b], &mut hex).unwrap();
+            hex::encode_to_slice([*b], &mut hex).unwrap();
             let hex = unsafe { std::str::from_utf8_unchecked(&hex) };
             encoded = format!("{}%{}", encoded, hex);
         } else {
diff --git a/proxmox-openid/src/auth_state.rs b/proxmox-openid/src/auth_state.rs
index 8d940ec..f2a299a 100644
--- a/proxmox-openid/src/auth_state.rs
+++ b/proxmox-openid/src/auth_state.rs
@@ -97,7 +97,7 @@ pub fn store_auth_state(
         bail!("too many pending openid auth request for realm {}", realm);
     }
 
-    data.push(serde_json::to_value(&auth_state)?);
+    data.push(serde_json::to_value(auth_state)?);
 
     replace_auth_state(&path, &data)?;
 
diff --git a/proxmox-rest-server/src/worker_task.rs b/proxmox-rest-server/src/worker_task.rs
index 6263ce7..54b6bc2 100644
--- a/proxmox-rest-server/src/worker_task.rs
+++ b/proxmox-rest-server/src/worker_task.rs
@@ -1023,11 +1023,11 @@ impl WorkerTaskContext for WorkerTask {
 
     fn log(&self, level: log::Level, message: &std::fmt::Arguments) {
         match level {
-            log::Level::Error => self.log_warning(&message.to_string()),
-            log::Level::Warn => self.log_warning(&message.to_string()),
-            log::Level::Info => self.log_message(&message.to_string()),
-            log::Level::Debug => self.log_message(&format!("DEBUG: {}", message)),
-            log::Level::Trace => self.log_message(&format!("TRACE: {}", message)),
+            log::Level::Error => self.log_warning(message.to_string()),
+            log::Level::Warn => self.log_warning(message.to_string()),
+            log::Level::Info => self.log_message(message.to_string()),
+            log::Level::Debug => self.log_message(format!("DEBUG: {}", message)),
+            log::Level::Trace => self.log_message(format!("TRACE: {}", message)),
         }
     }
 }
diff --git a/proxmox-schema/src/ser/mod.rs b/proxmox-schema/src/ser/mod.rs
index bcf473d..3dad6d6 100644
--- a/proxmox-schema/src/ser/mod.rs
+++ b/proxmox-schema/src/ser/mod.rs
@@ -448,7 +448,7 @@ impl<T: fmt::Write> Serializer for ElementSerializer<T> {
     }
 
     fn serialize_str(mut self, v: &str) -> Result<Self::Ok, Error> {
-        if v.contains(&['"', '\\', '\n']) {
+        if v.contains(['"', '\\', '\n']) {
             self.inner.write_char('"')?;
             crate::property_string::quote(v, &mut self.inner)?;
             self.inner.write_char('"')?;
@@ -643,7 +643,7 @@ impl<T: fmt::Write> ElementSerializeSeq<T> {
 
     fn finish(mut self) -> Result<T, Error> {
         let value = self.inner.finish()?;
-        if value.contains(&[',', ';', ' ', '"', '\\', '\n']) {
+        if value.contains([',', ';', ' ', '"', '\\', '\n']) {
             self.output.write_char('"')?;
             crate::property_string::quote(&value, &mut self.output)?;
             self.output.write_char('"')?;
diff --git a/proxmox-serde/src/lib.rs b/proxmox-serde/src/lib.rs
index e1dc16a..2f1ccca 100644
--- a/proxmox-serde/src/lib.rs
+++ b/proxmox-serde/src/lib.rs
@@ -86,9 +86,8 @@ pub mod bytes_as_base64 {
         D: Deserializer<'de>,
     {
         use serde::de::Error;
-        String::deserialize(deserializer).and_then(|string| {
-            base64::decode(&string).map_err(|err| Error::custom(err.to_string()))
-        })
+        String::deserialize(deserializer)
+            .and_then(|string| base64::decode(string).map_err(|err| Error::custom(err.to_string())))
     }
 }
 
@@ -125,7 +124,7 @@ pub mod string_as_base64 {
     fn finish_deserializing<'de, D: Deserializer<'de>>(string: String) -> Result<String, D::Error> {
         use serde::de::Error;
 
-        let bytes = base64::decode(&string).map_err(|err| {
+        let bytes = base64::decode(string).map_err(|err| {
             let msg = format!("base64 decode: {}", err);
             Error::custom(msg)
         })?;
@@ -219,7 +218,7 @@ pub mod bytes_as_base64url_nopad {
     {
         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()))
         })
     }
diff --git a/proxmox-subscription/src/check.rs b/proxmox-subscription/src/check.rs
index 3838e9c..9d074ea 100644
--- a/proxmox-subscription/src/check.rs
+++ b/proxmox-subscription/src/check.rs
@@ -25,7 +25,7 @@ fn register_subscription<C: HttpClient<String, String>>(
     client: C,
 ) -> Result<(String, String), Error> {
     // WHCMS sample code feeds the key into this, but it's just a challenge, so keep it simple
-    let rand = hex::encode(&proxmox_sys::linux::random_data(16)?);
+    let rand = hex::encode(proxmox_sys::linux::random_data(16)?);
     let challenge = format!("{}{}", checktime, rand);
 
     let params = json!({
-- 
2.39.2





^ permalink raw reply	[flat|nested] 16+ messages in thread

* [pbs-devel] [PATCH proxmox 02/15] clippy fix: casting to the same type is unnecessary
  2023-08-08  8:01 [pbs-devel] [PATCH proxmox 01/15] clippy fix: the borrowed expression implements the required traits Lukas Wagner
@ 2023-08-08  8:01 ` Lukas Wagner
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 03/15] clippy fix: calls to `drop` with a value that implements `Copy` Lukas Wagner
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Lukas Wagner @ 2023-08-08  8:01 UTC (permalink / raw)
  To: pbs-devel

See: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-time/src/posix.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/proxmox-time/src/posix.rs b/proxmox-time/src/posix.rs
index 3201d6a..27de549 100644
--- a/proxmox-time/src/posix.rs
+++ b/proxmox-time/src/posix.rs
@@ -137,7 +137,7 @@ pub fn strftime(format: &str, t: &libc::tm) -> Result<String, Error> {
         // -1,, it's unsigned
         bail!("strftime failed");
     }
-    let len = res as usize;
+    let len = res;
 
     if len == 0 {
         bail!("strftime: result len is 0 (string too large)");
-- 
2.39.2





^ permalink raw reply	[flat|nested] 16+ messages in thread

* [pbs-devel] [PATCH proxmox 03/15] clippy fix: calls to `drop` with a value that implements `Copy`
  2023-08-08  8:01 [pbs-devel] [PATCH proxmox 01/15] clippy fix: the borrowed expression implements the required traits Lukas Wagner
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 02/15] clippy fix: casting to the same type is unnecessary Lukas Wagner
@ 2023-08-08  8:01 ` Lukas Wagner
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 04/15] clippy fix: needless borrow Lukas Wagner
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Lukas Wagner @ 2023-08-08  8:01 UTC (permalink / raw)
  To: pbs-devel

Dropping a copy leaves the original intact

See:
https://rust-lang.github.io/rust-clippy/master/index.html#drop_copy

I assume the `drop` was used to silence a 'unused variable' warning,
so I silenced it by other means.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-rest-server/src/connection.rs | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/proxmox-rest-server/src/connection.rs b/proxmox-rest-server/src/connection.rs
index 7681f00..1bec28d 100644
--- a/proxmox-rest-server/src/connection.rs
+++ b/proxmox-rest-server/src/connection.rs
@@ -226,7 +226,9 @@ impl AcceptBuilder {
                 _ =  shutdown_future => break,
             };
             #[cfg(not(feature = "rate-limited-stream"))]
-            drop(peer);
+            {
+                let _ = &peer;
+            }
 
             sock.set_nodelay(true).unwrap();
             let _ = proxmox_sys::linux::socket::set_tcp_keepalive(
-- 
2.39.2





^ permalink raw reply	[flat|nested] 16+ messages in thread

* [pbs-devel] [PATCH proxmox 04/15] clippy fix: needless borrow
  2023-08-08  8:01 [pbs-devel] [PATCH proxmox 01/15] clippy fix: the borrowed expression implements the required traits Lukas Wagner
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 02/15] clippy fix: casting to the same type is unnecessary Lukas Wagner
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 03/15] clippy fix: calls to `drop` with a value that implements `Copy` Lukas Wagner
@ 2023-08-08  8:01 ` Lukas Wagner
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 05/15] clippy fix: unneeded `return` statement Lukas Wagner
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Lukas Wagner @ 2023-08-08  8:01 UTC (permalink / raw)
  To: pbs-devel

See:
https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-openid/src/lib.rs       | 2 +-
 proxmox-rest-server/src/rest.rs | 4 ++--
 proxmox-schema/src/de/cow3.rs   | 2 +-
 proxmox-schema/src/de/mod.rs    | 2 +-
 proxmox-tfa/src/totp.rs         | 8 ++++----
 5 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/proxmox-openid/src/lib.rs b/proxmox-openid/src/lib.rs
index 825975b..d6ed89b 100644
--- a/proxmox-openid/src/lib.rs
+++ b/proxmox-openid/src/lib.rs
@@ -221,7 +221,7 @@ impl OpenIdAuthenticator {
         private_auth_state: &PrivateAuthState,
     ) -> Result<Value, Error> {
         let (id_token_claims, userinfo_claims) =
-            self.verify_authorization_code(&code, &private_auth_state)?;
+            self.verify_authorization_code(code, private_auth_state)?;
 
         let mut data = serde_json::to_value(id_token_claims)?;
 
diff --git a/proxmox-rest-server/src/rest.rs b/proxmox-rest-server/src/rest.rs
index cffcedc..b4f35aa 100644
--- a/proxmox-rest-server/src/rest.rs
+++ b/proxmox-rest-server/src/rest.rs
@@ -946,7 +946,7 @@ impl Formatted {
                 let result = if api_method.protected
                     && rpcenv.env_type == RpcEnvironmentType::PUBLIC
                 {
-                    proxy_protected_request(api_method, parts, body, &peer).await
+                    proxy_protected_request(api_method, parts, body, peer).await
                 } else {
                     handle_api_request(rpcenv, api_method, formatter, parts, body, uri_param).await
                 };
@@ -1051,7 +1051,7 @@ impl Unformatted {
                 let result = if api_method.protected
                     && rpcenv.env_type == RpcEnvironmentType::PUBLIC
                 {
-                    proxy_protected_request(api_method, parts, body, &peer).await
+                    proxy_protected_request(api_method, parts, body, peer).await
                 } else {
                     handle_unformatted_api_request(rpcenv, api_method, parts, body, uri_param).await
                 };
diff --git a/proxmox-schema/src/de/cow3.rs b/proxmox-schema/src/de/cow3.rs
index 3044681..73bf8b5 100644
--- a/proxmox-schema/src/de/cow3.rs
+++ b/proxmox-schema/src/de/cow3.rs
@@ -93,7 +93,7 @@ where
     <B as ToOwned>::Owned: Borrow<B>,
 {
     fn as_ref(&self) -> &B {
-        &self
+        self
     }
 }
 
diff --git a/proxmox-schema/src/de/mod.rs b/proxmox-schema/src/de/mod.rs
index 804ffcc..80d92fd 100644
--- a/proxmox-schema/src/de/mod.rs
+++ b/proxmox-schema/src/de/mod.rs
@@ -588,7 +588,7 @@ impl<'de, 'i> de::MapAccess<'de> for MapAccess<'de, 'i> {
 
         let (key, schema) = match key {
             Some(key) => {
-                let schema = self.schema.lookup(&key);
+                let schema = self.schema.lookup(key);
                 let key = match str_slice_to_range(&self.input, key) {
                     None => Cow::Owned(key.to_string()),
                     Some(range) => match &self.input {
diff --git a/proxmox-tfa/src/totp.rs b/proxmox-tfa/src/totp.rs
index 97be715..1827e43 100644
--- a/proxmox-tfa/src/totp.rs
+++ b/proxmox-tfa/src/totp.rs
@@ -36,12 +36,12 @@ 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),
             Error::UnsupportedAlgorithm(a) => write!(f, "unsupported algorithm: '{a}'"),
             Error::UnknownParameter(p) => write!(f, "unknown otpauth uri parameter: '{p}'"),
-            Error::BadParameter(m, _e) => f.write_str(&m),
+            Error::BadParameter(m, _e) => f.write_str(m),
         }
     }
 }
-- 
2.39.2





^ permalink raw reply	[flat|nested] 16+ messages in thread

* [pbs-devel] [PATCH proxmox 05/15] clippy fix: unneeded `return` statement
  2023-08-08  8:01 [pbs-devel] [PATCH proxmox 01/15] clippy fix: the borrowed expression implements the required traits Lukas Wagner
                   ` (2 preceding siblings ...)
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 04/15] clippy fix: needless borrow Lukas Wagner
@ 2023-08-08  8:01 ` Lukas Wagner
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 06/15] clippy fix: redundant closure Lukas Wagner
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Lukas Wagner @ 2023-08-08  8:01 UTC (permalink / raw)
  To: pbs-devel

See:
https://rust-lang.github.io/rust-clippy/master/index.html#needless_return

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-rest-server/src/rest.rs | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/proxmox-rest-server/src/rest.rs b/proxmox-rest-server/src/rest.rs
index b4f35aa..252532a 100644
--- a/proxmox-rest-server/src/rest.rs
+++ b/proxmox-rest-server/src/rest.rs
@@ -785,11 +785,11 @@ impl ApiConfig {
                 }
                 Err(AuthError::NoData) => {}
             }
-            return Ok(self.get_index(rpcenv, parts).await);
+            Ok(self.get_index(rpcenv, parts).await)
         } else {
             let filename = self.find_alias(&components);
             let compression = extract_compression_method(&parts.headers);
-            return handle_static_file_download(&components, filename, compression).await;
+            handle_static_file_download(&components, filename, compression).await
         }
     }
 }
@@ -926,7 +926,7 @@ impl Formatted {
         match api_method {
             None => {
                 let err = http_err!(NOT_FOUND, "Path '{}' not found.", full_path);
-                return Ok(formatter.format_error(err));
+                Ok(formatter.format_error(err))
             }
             Some(api_method) => {
                 let auth_id = rpcenv.get_auth_id();
@@ -962,7 +962,7 @@ impl Formatted {
                         .insert(AuthStringExtension(auth_id));
                 }
 
-                return Ok(response);
+                Ok(response)
             }
         }
     }
@@ -1067,7 +1067,7 @@ impl Unformatted {
                         .insert(AuthStringExtension(auth_id));
                 }
 
-                return Ok(response);
+                Ok(response)
             }
         }
     }
-- 
2.39.2





^ permalink raw reply	[flat|nested] 16+ messages in thread

* [pbs-devel] [PATCH proxmox 06/15] clippy fix: redundant closure
  2023-08-08  8:01 [pbs-devel] [PATCH proxmox 01/15] clippy fix: the borrowed expression implements the required traits Lukas Wagner
                   ` (3 preceding siblings ...)
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 05/15] clippy fix: unneeded `return` statement Lukas Wagner
@ 2023-08-08  8:01 ` Lukas Wagner
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 07/15] clippy fix: this (Default) `impl` can be derived Lukas Wagner
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Lukas Wagner @ 2023-08-08  8:01 UTC (permalink / raw)
  To: pbs-devel

See:
https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-openid/src/lib.rs    |  2 +-
 proxmox-schema/src/de/mod.rs | 10 +++-------
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/proxmox-openid/src/lib.rs b/proxmox-openid/src/lib.rs
index d6ed89b..c2b73c9 100644
--- a/proxmox-openid/src/lib.rs
+++ b/proxmox-openid/src/lib.rs
@@ -107,7 +107,7 @@ impl PrivateAuthState {
 impl OpenIdAuthenticator {
     pub fn discover(config: &OpenIdConfig, redirect_url: &str) -> Result<Self, Error> {
         let client_id = ClientId::new(config.client_id.clone());
-        let client_key = config.client_key.clone().map(|key| ClientSecret::new(key));
+        let client_key = config.client_key.clone().map(ClientSecret::new);
         let issuer_url = IssuerUrl::new(config.issuer_url.clone())?;
 
         let provider_metadata = CoreProviderMetadata::discover(&issuer_url, http_client)?;
diff --git a/proxmox-schema/src/de/mod.rs b/proxmox-schema/src/de/mod.rs
index 80d92fd..8cb3761 100644
--- a/proxmox-schema/src/de/mod.rs
+++ b/proxmox-schema/src/de/mod.rs
@@ -109,7 +109,7 @@ impl<'de, 'i> SchemaDeserializer<'de, 'i> {
         if !IN_PROPERTY_STRING.with(|v| v.get()) {
             schema
                 .check_constraints(&self.input)
-                .map_err(|err| Error::invalid(err))?;
+                .map_err(Error::invalid)?;
         }
         match self.input {
             Cow3::Original(input) => visitor.visit_borrowed_str(input),
@@ -175,9 +175,7 @@ impl<'de, 'i> de::Deserializer<'de> for SchemaDeserializer<'de, 'i> {
                     .parse()
                     .map_err(|_| Error::msg(format!("not an integer: {:?}", self.input)))?;
 
-                schema
-                    .check_constraints(value)
-                    .map_err(|err| Error::invalid(err))?;
+                schema.check_constraints(value).map_err(Error::invalid)?;
 
                 let value: i64 = i64::try_from(value)
                     .map_err(|_| Error::invalid("isize did not fit into i64"))?;
@@ -194,9 +192,7 @@ impl<'de, 'i> de::Deserializer<'de> for SchemaDeserializer<'de, 'i> {
                     .parse()
                     .map_err(|_| Error::msg(format!("not a valid number: {:?}", self.input)))?;
 
-                schema
-                    .check_constraints(value)
-                    .map_err(|err| Error::invalid(err))?;
+                schema.check_constraints(value).map_err(Error::invalid)?;
 
                 visitor.visit_f64(value)
             }
-- 
2.39.2





^ permalink raw reply	[flat|nested] 16+ messages in thread

* [pbs-devel] [PATCH proxmox 07/15] clippy fix: this (Default) `impl` can be derived
  2023-08-08  8:01 [pbs-devel] [PATCH proxmox 01/15] clippy fix: the borrowed expression implements the required traits Lukas Wagner
                   ` (4 preceding siblings ...)
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 06/15] clippy fix: redundant closure Lukas Wagner
@ 2023-08-08  8:01 ` Lukas Wagner
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 08/15] clippy fix: you should consider adding a `Default` implementation Lukas Wagner
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Lukas Wagner @ 2023-08-08  8:01 UTC (permalink / raw)
  To: pbs-devel

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-api-macro/src/util.rs                 | 9 ++-------
 proxmox-subscription/src/subscription_info.rs | 9 +++------
 2 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/proxmox-api-macro/src/util.rs b/proxmox-api-macro/src/util.rs
index 1eba31f..b90f303 100644
--- a/proxmox-api-macro/src/util.rs
+++ b/proxmox-api-macro/src/util.rs
@@ -623,19 +623,14 @@ where
 }
 
 /// Helper to distinguish between explicitly set or derived data.
-#[derive(Clone, Copy, Eq, PartialEq)]
+#[derive(Clone, Copy, Default, Eq, PartialEq)]
 pub enum Maybe<T> {
     Explicit(T),
     Derived(T),
+    #[default]
     None,
 }
 
-impl<T> Default for Maybe<T> {
-    fn default() -> Self {
-        Maybe::None
-    }
-}
-
 impl<T> Maybe<T> {
     pub fn as_ref(&self) -> Maybe<&T> {
         match self {
diff --git a/proxmox-subscription/src/subscription_info.rs b/proxmox-subscription/src/subscription_info.rs
index 8c0bd3e..f455392 100644
--- a/proxmox-subscription/src/subscription_info.rs
+++ b/proxmox-subscription/src/subscription_info.rs
@@ -20,7 +20,7 @@ pub(crate) const SUBSCRIPTION_MAX_KEY_CHECK_FAILURE_AGE: i64 = 5 * 24 * 3600;
 
 // Aliases are needed for PVE compat!
 #[cfg_attr(feature = "api-types", api())]
-#[derive(Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]
+#[derive(Default, Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]
 #[serde(rename_all = "lowercase")]
 /// Subscription status
 pub enum SubscriptionStatus {
@@ -29,6 +29,7 @@ pub enum SubscriptionStatus {
     #[serde(alias = "New")]
     New,
     /// no subscription set
+    #[default]
     #[serde(alias = "NotFound")]
     NotFound,
     /// subscription set and active
@@ -44,11 +45,7 @@ pub enum SubscriptionStatus {
     #[serde(alias = "Suspended")]
     Suspended,
 }
-impl Default for SubscriptionStatus {
-    fn default() -> Self {
-        SubscriptionStatus::NotFound
-    }
-}
+
 impl std::fmt::Display for SubscriptionStatus {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
         match self {
-- 
2.39.2





^ permalink raw reply	[flat|nested] 16+ messages in thread

* [pbs-devel] [PATCH proxmox 08/15] clippy fix: you should consider adding a `Default` implementation
  2023-08-08  8:01 [pbs-devel] [PATCH proxmox 01/15] clippy fix: the borrowed expression implements the required traits Lukas Wagner
                   ` (5 preceding siblings ...)
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 07/15] clippy fix: this (Default) `impl` can be derived Lukas Wagner
@ 2023-08-08  8:01 ` Lukas Wagner
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 09/15] clippy fix: unnecessary use of `to_string` Lukas Wagner
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Lukas Wagner @ 2023-08-08  8:01 UTC (permalink / raw)
  To: pbs-devel

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-openid/src/lib.rs | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/proxmox-openid/src/lib.rs b/proxmox-openid/src/lib.rs
index c2b73c9..a65a729 100644
--- a/proxmox-openid/src/lib.rs
+++ b/proxmox-openid/src/lib.rs
@@ -72,6 +72,12 @@ pub struct PrivateAuthState {
     pub ctime: i64,
 }
 
+impl Default for PrivateAuthState {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl PrivateAuthState {
     pub fn new() -> Self {
         let nonce = Nonce::new_random();
-- 
2.39.2





^ permalink raw reply	[flat|nested] 16+ messages in thread

* [pbs-devel] [PATCH proxmox 09/15] clippy fix: unnecessary use of `to_string`
  2023-08-08  8:01 [pbs-devel] [PATCH proxmox 01/15] clippy fix: the borrowed expression implements the required traits Lukas Wagner
                   ` (6 preceding siblings ...)
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 08/15] clippy fix: you should consider adding a `Default` implementation Lukas Wagner
@ 2023-08-08  8:01 ` Lukas Wagner
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 10/15] clippy fix: binary comparison to literal `Option::None` Lukas Wagner
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Lukas Wagner @ 2023-08-08  8:01 UTC (permalink / raw)
  To: pbs-devel

See:
https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_to_owned

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-openid/src/http_client.rs | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/proxmox-openid/src/http_client.rs b/proxmox-openid/src/http_client.rs
index e391421..1850d64 100644
--- a/proxmox-openid/src/http_client.rs
+++ b/proxmox-openid/src/http_client.rs
@@ -54,15 +54,15 @@ fn ureq_agent() -> Result<ureq::Agent, Error> {
 pub fn http_client(request: HttpRequest) -> Result<HttpResponse, Error> {
     let agent = ureq_agent()?;
     let mut req = if let Method::POST = request.method {
-        agent.post(&request.url.to_string())
+        agent.post(request.url.as_ref())
     } else {
-        agent.get(&request.url.to_string())
+        agent.get(request.url.as_ref())
     };
 
     for (name, value) in request.headers {
         if let Some(name) = name {
             req = req.set(
-                &name.to_string(),
+                name.as_ref(),
                 value.to_str().map_err(|_| {
                     Error::Other(format!(
                         "invalid {} header value {:?}",
-- 
2.39.2





^ permalink raw reply	[flat|nested] 16+ messages in thread

* [pbs-devel] [PATCH proxmox 10/15] clippy fix: binary comparison to literal `Option::None`
  2023-08-08  8:01 [pbs-devel] [PATCH proxmox 01/15] clippy fix: the borrowed expression implements the required traits Lukas Wagner
                   ` (7 preceding siblings ...)
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 09/15] clippy fix: unnecessary use of `to_string` Lukas Wagner
@ 2023-08-08  8:01 ` Lukas Wagner
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 11/15] clippy fix: warning: this let-binding has unit value Lukas Wagner
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Lukas Wagner @ 2023-08-08  8:01 UTC (permalink / raw)
  To: pbs-devel

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-apt/src/repositories/file/list_parser.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/proxmox-apt/src/repositories/file/list_parser.rs b/proxmox-apt/src/repositories/file/list_parser.rs
index deba41a..0edeea7 100644
--- a/proxmox-apt/src/repositories/file/list_parser.rs
+++ b/proxmox-apt/src/repositories/file/list_parser.rs
@@ -54,7 +54,7 @@ impl Iterator for SplitQuoteWord {
                 continue;
             }
 
-            if start == None {
+            if start.is_none() {
                 start = Some(n);
             }
 
-- 
2.39.2





^ permalink raw reply	[flat|nested] 16+ messages in thread

* [pbs-devel] [PATCH proxmox 11/15] clippy fix: warning: this let-binding has unit value
  2023-08-08  8:01 [pbs-devel] [PATCH proxmox 01/15] clippy fix: the borrowed expression implements the required traits Lukas Wagner
                   ` (8 preceding siblings ...)
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 10/15] clippy fix: binary comparison to literal `Option::None` Lukas Wagner
@ 2023-08-08  8:01 ` Lukas Wagner
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 12/15] clippy fix: useless use of `format!` Lukas Wagner
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Lukas Wagner @ 2023-08-08  8:01 UTC (permalink / raw)
  To: pbs-devel

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-schema/src/de/verify.rs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/proxmox-schema/src/de/verify.rs b/proxmox-schema/src/de/verify.rs
index 71e87b0..0ed4713 100644
--- a/proxmox-schema/src/de/verify.rs
+++ b/proxmox-schema/src/de/verify.rs
@@ -292,6 +292,7 @@ impl<'de> de::Visitor<'de> for Visitor {
             _ => return Err(E::invalid_type(Unexpected::Str(value), &self)),
         };
 
+        #[allow(clippy::let_unit_value)]
         let _: () = schema.check_constraints(value).map_err(E::custom)?;
 
         Ok(Verifier)
-- 
2.39.2





^ permalink raw reply	[flat|nested] 16+ messages in thread

* [pbs-devel] [PATCH proxmox 12/15] clippy fix: useless use of `format!`
  2023-08-08  8:01 [pbs-devel] [PATCH proxmox 01/15] clippy fix: the borrowed expression implements the required traits Lukas Wagner
                   ` (9 preceding siblings ...)
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 11/15] clippy fix: warning: this let-binding has unit value Lukas Wagner
@ 2023-08-08  8:01 ` Lukas Wagner
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 13/15] clippy fix: the following explicit lifetimes could be elided Lukas Wagner
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Lukas Wagner @ 2023-08-08  8:01 UTC (permalink / raw)
  To: pbs-devel

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-schema/src/de/mod.rs | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/proxmox-schema/src/de/mod.rs b/proxmox-schema/src/de/mod.rs
index 8cb3761..cccca06 100644
--- a/proxmox-schema/src/de/mod.rs
+++ b/proxmox-schema/src/de/mod.rs
@@ -290,13 +290,9 @@ impl<'de, 'i> de::Deserializer<'de> for SchemaDeserializer<'de, 'i> {
                 Some(schema::ApiStringFormat::PropertyString(schema)) => {
                     self.deserialize_property_string(visitor, schema)
                 }
-                _ => Err(Error::msg(format!(
-                    "cannot deserialize map with a string schema",
-                ))),
+                _ => Err(Error::msg("cannot deserialize map with a string schema")),
             },
-            _ => Err(Error::msg(format!(
-                "cannot deserialize map with non-object schema",
-            ))),
+            _ => Err(Error::msg("cannot deserialize map with non-object schema")),
         }
     }
 
-- 
2.39.2





^ permalink raw reply	[flat|nested] 16+ messages in thread

* [pbs-devel] [PATCH proxmox 13/15] clippy fix: the following explicit lifetimes could be elided
  2023-08-08  8:01 [pbs-devel] [PATCH proxmox 01/15] clippy fix: the borrowed expression implements the required traits Lukas Wagner
                   ` (10 preceding siblings ...)
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 12/15] clippy fix: useless use of `format!` Lukas Wagner
@ 2023-08-08  8:01 ` Lukas Wagner
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 14/15] clippy fix: complex type definitions Lukas Wagner
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Lukas Wagner @ 2023-08-08  8:01 UTC (permalink / raw)
  To: pbs-devel

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-schema/src/property_string.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/proxmox-schema/src/property_string.rs b/proxmox-schema/src/property_string.rs
index e02b716..36bc0e7 100644
--- a/proxmox-schema/src/property_string.rs
+++ b/proxmox-schema/src/property_string.rs
@@ -173,7 +173,7 @@ fn ascii_split_around(s: &str, mid: usize) -> (&str, &str) {
 
 /// Split "off" the first `mid` bytes of `s`, advancing it to `mid + 1` (assuming `mid` points to
 /// an ASCII character!).
-fn ascii_split_off<'a, 's>(s: &'a mut &'s str, mid: usize) -> &'s str {
+fn ascii_split_off<'s>(s: &mut &'s str, mid: usize) -> &'s str {
     let (a, b) = ascii_split_around(s, mid);
     *s = b;
     a
-- 
2.39.2





^ permalink raw reply	[flat|nested] 16+ messages in thread

* [pbs-devel] [PATCH proxmox 14/15] clippy fix: complex type definitions
  2023-08-08  8:01 [pbs-devel] [PATCH proxmox 01/15] clippy fix: the borrowed expression implements the required traits Lukas Wagner
                   ` (11 preceding siblings ...)
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 13/15] clippy fix: the following explicit lifetimes could be elided Lukas Wagner
@ 2023-08-08  8:01 ` Lukas Wagner
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 15/15] clippy fix: deref on an immutable reference Lukas Wagner
  2023-08-08  9:33 ` [pbs-devel] partially-applied: [PATCH proxmox 01/15] clippy fix: the borrowed expression implements the required traits Wolfgang Bumiller
  14 siblings, 0 replies; 16+ messages in thread
From: Lukas Wagner @ 2023-08-08  8:01 UTC (permalink / raw)
  To: pbs-devel

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-apt/src/repositories/mod.rs   | 20 +++++++++-----------
 proxmox-schema/src/property_string.rs |  6 +++---
 2 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/proxmox-apt/src/repositories/mod.rs b/proxmox-apt/src/repositories/mod.rs
index b2e83a0..45adc85 100644
--- a/proxmox-apt/src/repositories/mod.rs
+++ b/proxmox-apt/src/repositories/mod.rs
@@ -113,21 +113,19 @@ pub fn standard_repositories(
     result
 }
 
+/// Type containing successfully parsed files, a list of errors for files that
+/// could not be read and a common digest for the successfully parsed files.
+pub type Repositories = (
+    Vec<APTRepositoryFile>,
+    Vec<APTRepositoryFileError>,
+    [u8; 32],
+);
+
 /// Returns all APT repositories configured in `/etc/apt/sources.list` and
 /// in `/etc/apt/sources.list.d` including disabled repositories.
 ///
-/// Returns the succesfully parsed files, a list of errors for files that could
-/// not be read or parsed and a common digest for the succesfully parsed files.
-///
 /// The digest is guaranteed to be set for each successfully parsed file.
-pub fn repositories() -> Result<
-    (
-        Vec<APTRepositoryFile>,
-        Vec<APTRepositoryFileError>,
-        [u8; 32],
-    ),
-    Error,
-> {
+pub fn repositories() -> Result<Repositories, Error> {
     let to_result = |files: Vec<APTRepositoryFile>, errors: Vec<APTRepositoryFileError>| {
         let common_digest = common_digest(&files);
 
diff --git a/proxmox-schema/src/property_string.rs b/proxmox-schema/src/property_string.rs
index 36bc0e7..7dd60f7 100644
--- a/proxmox-schema/src/property_string.rs
+++ b/proxmox-schema/src/property_string.rs
@@ -40,10 +40,10 @@ impl<'a> Iterator for PropertyIterator<'a> {
     }
 }
 
+type NextProperty<'a> = (Option<&'a str>, Cow<'a, str>, &'a str);
+
 /// Returns an optional key, its value, and the remainder of `data`.
-pub(crate) fn next_property(
-    mut data: &str,
-) -> Option<Result<(Option<&str>, Cow<str>, &str), Error>> {
+pub(crate) fn next_property(mut data: &str) -> Option<Result<NextProperty, Error>> {
     if data.is_empty() {
         return None;
     }
-- 
2.39.2





^ permalink raw reply	[flat|nested] 16+ messages in thread

* [pbs-devel] [PATCH proxmox 15/15] clippy fix: deref on an immutable reference
  2023-08-08  8:01 [pbs-devel] [PATCH proxmox 01/15] clippy fix: the borrowed expression implements the required traits Lukas Wagner
                   ` (12 preceding siblings ...)
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 14/15] clippy fix: complex type definitions Lukas Wagner
@ 2023-08-08  8:01 ` Lukas Wagner
  2023-08-08  9:33 ` [pbs-devel] partially-applied: [PATCH proxmox 01/15] clippy fix: the borrowed expression implements the required traits Wolfgang Bumiller
  14 siblings, 0 replies; 16+ messages in thread
From: Lukas Wagner @ 2023-08-08  8:01 UTC (permalink / raw)
  To: pbs-devel

See:
https://rust-lang.github.io/rust-clippy/master/index.html#borrow_deref_ref

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-rest-server/src/rest.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/proxmox-rest-server/src/rest.rs b/proxmox-rest-server/src/rest.rs
index 252532a..0ee9fab 100644
--- a/proxmox-rest-server/src/rest.rs
+++ b/proxmox-rest-server/src/rest.rs
@@ -106,7 +106,7 @@ pub trait PeerAddress {
 // Pin<Box<T>>
 impl<T: PeerAddress> PeerAddress for Pin<Box<T>> {
     fn peer_addr(&self) -> Result<std::net::SocketAddr, Error> {
-        T::peer_addr(&*self)
+        T::peer_addr(&**self)
     }
 }
 
-- 
2.39.2





^ permalink raw reply	[flat|nested] 16+ messages in thread

* [pbs-devel] partially-applied: [PATCH proxmox 01/15] clippy fix: the borrowed expression implements the required traits
  2023-08-08  8:01 [pbs-devel] [PATCH proxmox 01/15] clippy fix: the borrowed expression implements the required traits Lukas Wagner
                   ` (13 preceding siblings ...)
  2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 15/15] clippy fix: deref on an immutable reference Lukas Wagner
@ 2023-08-08  9:33 ` Wolfgang Bumiller
  14 siblings, 0 replies; 16+ messages in thread
From: Wolfgang Bumiller @ 2023-08-08  9:33 UTC (permalink / raw)
  To: Lukas Wagner; +Cc: pbs-devel

applied all except 2/15 since there, `res` is a `libc::size_t`, I'd
rather `#[allow]` that cast instead of removing it, since otherwise it
could technically fail depending on the target architecture one is
building for...




^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2023-08-08  9:34 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-08  8:01 [pbs-devel] [PATCH proxmox 01/15] clippy fix: the borrowed expression implements the required traits Lukas Wagner
2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 02/15] clippy fix: casting to the same type is unnecessary Lukas Wagner
2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 03/15] clippy fix: calls to `drop` with a value that implements `Copy` Lukas Wagner
2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 04/15] clippy fix: needless borrow Lukas Wagner
2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 05/15] clippy fix: unneeded `return` statement Lukas Wagner
2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 06/15] clippy fix: redundant closure Lukas Wagner
2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 07/15] clippy fix: this (Default) `impl` can be derived Lukas Wagner
2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 08/15] clippy fix: you should consider adding a `Default` implementation Lukas Wagner
2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 09/15] clippy fix: unnecessary use of `to_string` Lukas Wagner
2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 10/15] clippy fix: binary comparison to literal `Option::None` Lukas Wagner
2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 11/15] clippy fix: warning: this let-binding has unit value Lukas Wagner
2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 12/15] clippy fix: useless use of `format!` Lukas Wagner
2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 13/15] clippy fix: the following explicit lifetimes could be elided Lukas Wagner
2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 14/15] clippy fix: complex type definitions Lukas Wagner
2023-08-08  8:01 ` [pbs-devel] [PATCH proxmox 15/15] clippy fix: deref on an immutable reference Lukas Wagner
2023-08-08  9:33 ` [pbs-devel] partially-applied: [PATCH proxmox 01/15] clippy fix: the borrowed expression implements the required traits Wolfgang Bumiller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal