From 6f532dfb7d567e757d9a1a5857da0a2f151f5f3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Thu, 6 Jun 2024 11:21:24 +0200 Subject: [PATCH] various clippy fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabian Grünbichler --- proxmox-api-macro/src/util.rs | 2 +- proxmox-apt/tests/repositories.rs | 20 ++++++++++---------- proxmox-io/src/vec/mod.rs | 2 +- proxmox-ldap/tests/glauth.rs | 12 +++--------- proxmox-notify/src/api/gotify.rs | 2 +- proxmox-notify/src/config.rs | 4 ++-- proxmox-rest-server/src/api_config.rs | 2 +- proxmox-rest-server/src/rest.rs | 2 +- proxmox-rest-server/src/worker_task.rs | 2 +- proxmox-rrd/src/cache.rs | 4 ++-- proxmox-schema/src/de/mod.rs | 2 +- proxmox-schema/src/de/no_schema.rs | 2 +- proxmox-sys/src/fs/dir.rs | 6 ++---- proxmox-tfa/src/totp.rs | 2 +- 14 files changed, 28 insertions(+), 36 deletions(-) diff --git a/proxmox-api-macro/src/util.rs b/proxmox-api-macro/src/util.rs index 324c460d..428b1e4d 100644 --- a/proxmox-api-macro/src/util.rs +++ b/proxmox-api-macro/src/util.rs @@ -865,7 +865,7 @@ pub fn parse_str_value_to_option( path: &syn::Path, nv: syn::parse::ParseStream<'_>, ) { - duplicate(&*target, &path); + duplicate(&*target, path); match nv.parse().and_then(|lit| parse_lit_str(&lit)) { Ok(value) => *target = Some(value), Err(err) => crate::add_error(err), diff --git a/proxmox-apt/tests/repositories.rs b/proxmox-apt/tests/repositories.rs index 8b4b035a..bb0014ac 100644 --- a/proxmox-apt/tests/repositories.rs +++ b/proxmox-apt/tests/repositories.rs @@ -125,7 +125,7 @@ fn test_digest() -> Result<(), Error> { std::fs::copy(path, new_path)?; // modify the repo - let mut repo = file.repositories.first_mut().unwrap(); + let repo = file.repositories.first_mut().unwrap(); repo.enabled = !repo.enabled; // ...then it should work @@ -183,7 +183,7 @@ fn test_check_repositories() -> Result<(), Error> { )); let absolute_suite_list = read_dir.join("absolute_suite.list"); - let mut file = APTRepositoryFile::new(&absolute_suite_list)?.unwrap(); + let mut file = APTRepositoryFile::new(absolute_suite_list)?.unwrap(); file.parse()?; let infos = check_repositories(&[file], DebianCodename::Bullseye); @@ -327,7 +327,7 @@ fn test_get_cached_origin() -> Result<(), Error> { )); let pve_list = read_dir.join("pve.list"); - let mut file = APTRepositoryFile::new(&pve_list)?.unwrap(); + let mut file = APTRepositoryFile::new(pve_list)?.unwrap(); file.parse()?; let origins = [ @@ -366,7 +366,7 @@ fn test_standard_repositories() -> Result<(), Error> { ]; let absolute_suite_list = read_dir.join("absolute_suite.list"); - let mut file = APTRepositoryFile::new(&absolute_suite_list)?.unwrap(); + let mut file = APTRepositoryFile::new(absolute_suite_list)?.unwrap(); file.parse()?; let std_repos = standard_repositories(&[file], "pve", DebianCodename::Bullseye); @@ -374,7 +374,7 @@ fn test_standard_repositories() -> Result<(), Error> { assert_eq!(std_repos, &expected[0..=5]); let absolute_suite_list = read_dir.join("absolute_suite.list"); - let mut file = APTRepositoryFile::new(&absolute_suite_list)?.unwrap(); + let mut file = APTRepositoryFile::new(absolute_suite_list)?.unwrap(); file.parse()?; let std_repos = standard_repositories(&[file], "pve", DebianCodename::Bookworm); @@ -382,7 +382,7 @@ fn test_standard_repositories() -> Result<(), Error> { assert_eq!(std_repos, expected); let pve_list = read_dir.join("pve.list"); - let mut file = APTRepositoryFile::new(&pve_list)?.unwrap(); + let mut file = APTRepositoryFile::new(pve_list)?.unwrap(); file.parse()?; let file_vec = vec![file]; @@ -399,7 +399,7 @@ fn test_standard_repositories() -> Result<(), Error> { assert_eq!(std_repos, &expected[0..=5]); let pve_alt_list = read_dir.join("pve-alt.list"); - let mut file = APTRepositoryFile::new(&pve_alt_list)?.unwrap(); + let mut file = APTRepositoryFile::new(pve_alt_list)?.unwrap(); file.parse()?; expected[0].status = Some(true); @@ -411,7 +411,7 @@ fn test_standard_repositories() -> Result<(), Error> { assert_eq!(std_repos, &expected[0..=5]); let pve_alt_list = read_dir.join("ceph-quincy-bookworm.list"); - let mut file = APTRepositoryFile::new(&pve_alt_list)?.unwrap(); + let mut file = APTRepositoryFile::new(pve_alt_list)?.unwrap(); file.parse()?; expected[0].status = None; @@ -426,7 +426,7 @@ fn test_standard_repositories() -> Result<(), Error> { assert_eq!(std_repos, expected); let pve_alt_list = read_dir.join("ceph-quincy-nosub-bookworm.list"); - let mut file = APTRepositoryFile::new(&pve_alt_list)?.unwrap(); + let mut file = APTRepositoryFile::new(pve_alt_list)?.unwrap(); file.parse()?; expected[0].status = None; @@ -441,7 +441,7 @@ fn test_standard_repositories() -> Result<(), Error> { assert_eq!(std_repos, expected); let pve_alt_list = read_dir.join("ceph-reef-enterprise-bookworm.list"); - let mut file = APTRepositoryFile::new(&pve_alt_list)?.unwrap(); + let mut file = APTRepositoryFile::new(pve_alt_list)?.unwrap(); file.parse()?; expected[0].status = None; diff --git a/proxmox-io/src/vec/mod.rs b/proxmox-io/src/vec/mod.rs index 8798025d..16d3a32e 100644 --- a/proxmox-io/src/vec/mod.rs +++ b/proxmox-io/src/vec/mod.rs @@ -54,7 +54,7 @@ pub use byte_vec::ByteVecExt; pub unsafe fn uninitialized(len: usize) -> Vec { unsafe { let data = std::alloc::alloc(std::alloc::Layout::array::(len).unwrap()); - Vec::from_raw_parts(data as *mut u8, len, len) + Vec::from_raw_parts(data, len, len) } } diff --git a/proxmox-ldap/tests/glauth.rs b/proxmox-ldap/tests/glauth.rs index 74720c10..d497018c 100644 --- a/proxmox-ldap/tests/glauth.rs +++ b/proxmox-ldap/tests/glauth.rs @@ -14,7 +14,7 @@ struct GlauthServer { impl GlauthServer { fn new(path: &str) -> Result { let glauth_bin = std::env::var("GLAUTH_BIN").context("GLAUTH_BIN is not set")?; - let handle = Command::new(&glauth_bin) + let handle = Command::new(glauth_bin) .arg("-c") .arg(path) .stdin(Stdio::null()) @@ -155,16 +155,10 @@ fn test_search() -> Result<(), Error> { .attributes .get("mail") .unwrap() - .get(0) + .first() .unwrap() .ends_with("@example.com")); - assert!(a - .attributes - .get("sn") - .unwrap() - .get(0) - .unwrap() - .eq("User".into())); + assert!(a.attributes.get("sn").unwrap().first().unwrap().eq("User")); } Ok(()) diff --git a/proxmox-notify/src/api/gotify.rs b/proxmox-notify/src/api/gotify.rs index 92151f52..b4be7b44 100644 --- a/proxmox-notify/src/api/gotify.rs +++ b/proxmox-notify/src/api/gotify.rs @@ -102,7 +102,7 @@ pub fn update_endpoint( config, &GotifyPrivateConfig { name: name.into(), - token: token.into(), + token, }, )?; } diff --git a/proxmox-notify/src/config.rs b/proxmox-notify/src/config.rs index 44453713..789c4a7d 100644 --- a/proxmox-notify/src/config.rs +++ b/proxmox-notify/src/config.rs @@ -12,13 +12,13 @@ use crate::Error; /// Section config schema for the public config file. pub fn config_parser() -> &'static SectionConfig { static CONFIG: OnceLock = OnceLock::new(); - CONFIG.get_or_init(|| config_init()) + CONFIG.get_or_init(config_init) } /// Section config schema for the private config file. pub fn private_config_parser() -> &'static SectionConfig { static CONFIG: OnceLock = OnceLock::new(); - CONFIG.get_or_init(|| private_config_init()) + CONFIG.get_or_init(private_config_init) } fn config_init() -> SectionConfig { diff --git a/proxmox-rest-server/src/api_config.rs b/proxmox-rest-server/src/api_config.rs index 80589446..eaece05a 100644 --- a/proxmox-rest-server/src/api_config.rs +++ b/proxmox-rest-server/src/api_config.rs @@ -495,7 +495,7 @@ impl Service for PrivilegedAddr { fn call(&mut self, _req: Uri) -> Self::Future { match self { PrivilegedAddr::Tcp(addr) => { - let addr = addr.clone(); + let addr = *addr; Box::pin(async move { tokio::net::TcpStream::connect(addr) .await diff --git a/proxmox-rest-server/src/rest.rs b/proxmox-rest-server/src/rest.rs index 4900592d..39ae9a18 100644 --- a/proxmox-rest-server/src/rest.rs +++ b/proxmox-rest-server/src/rest.rs @@ -155,7 +155,7 @@ impl Service> for RedirectService { Response::builder() .status(status_code) - .header("Location", String::from(location_value)) + .header("Location", location_value) .body(Body::empty())? } else { Response::builder() diff --git a/proxmox-rest-server/src/worker_task.rs b/proxmox-rest-server/src/worker_task.rs index 4cf24cc4..5bab4cdc 100644 --- a/proxmox-rest-server/src/worker_task.rs +++ b/proxmox-rest-server/src/worker_task.rs @@ -850,7 +850,7 @@ impl WorkerTask { file_opts: setup.file_opts.clone(), ..Default::default() }; - let logger = FileLogger::new(&path, logger_options)?; + let logger = FileLogger::new(path, logger_options)?; let worker = Arc::new(Self { setup, diff --git a/proxmox-rrd/src/cache.rs b/proxmox-rrd/src/cache.rs index e3d2f8d5..5b123a6b 100644 --- a/proxmox-rrd/src/cache.rs +++ b/proxmox-rrd/src/cache.rs @@ -62,8 +62,8 @@ impl Cache { ) -> Result { let basedir = basedir.as_ref().to_owned(); - let file_options = file_options.unwrap_or_else(CreateOptions::new); - let dir_options = dir_options.unwrap_or_else(CreateOptions::new); + let file_options = file_options.unwrap_or_default(); + let dir_options = dir_options.unwrap_or_default(); create_path( &basedir, diff --git a/proxmox-schema/src/de/mod.rs b/proxmox-schema/src/de/mod.rs index 75b500e5..09ccfeb3 100644 --- a/proxmox-schema/src/de/mod.rs +++ b/proxmox-schema/src/de/mod.rs @@ -421,7 +421,7 @@ impl<'de, 'i, 's> de::SeqAccess<'de> for SeqAccess<'de, 'i, 's> { return Ok(None); } - while let Some(el_range) = next_str_entry(&self.input, &mut self.at, self.has_null) { + if let Some(el_range) = next_str_entry(&self.input, &mut self.at, self.has_null) { if let Some(max) = self.schema.max_length { if self.count == max { return Err(Error::msg("too many elements")); diff --git a/proxmox-schema/src/de/no_schema.rs b/proxmox-schema/src/de/no_schema.rs index 546e5001..45fe08cd 100644 --- a/proxmox-schema/src/de/no_schema.rs +++ b/proxmox-schema/src/de/no_schema.rs @@ -303,7 +303,7 @@ impl<'a> Iterator for SplitList<'a> { type Item = &'a str; fn next(&mut self) -> Option<&'a str> { - let range = super::next_str_entry(&self.input, &mut self.at, self.has_null)?; + let range = super::next_str_entry(self.input, &mut self.at, self.has_null)?; Some(&self.input[range]) } } diff --git a/proxmox-sys/src/fs/dir.rs b/proxmox-sys/src/fs/dir.rs index c39b9fdf..a3c6b3a9 100644 --- a/proxmox-sys/src/fs/dir.rs +++ b/proxmox-sys/src/fs/dir.rs @@ -52,10 +52,8 @@ pub fn ensure_dir_exists>( Err(nix::errno::Errno::EEXIST) => { if enforce_permissions { return options.check(path); - } else { - if let Err(err) = options.check(path) { - log::error!("{err}"); - } + } else if let Err(err) = options.check(path) { + log::error!("{err}"); } } Err(err) => bail!("unable to create directory {path:?} - {err}",), diff --git a/proxmox-tfa/src/totp.rs b/proxmox-tfa/src/totp.rs index 1827e435..ac725804 100644 --- a/proxmox-tfa/src/totp.rs +++ b/proxmox-tfa/src/totp.rs @@ -656,7 +656,7 @@ fn test_algorithm_parsing() { assert_eq!(hotp.issuer.as_deref(), Some(issuer)); assert_eq!(hotp.account_name.as_deref(), Some("user@hostname")); assert_eq!( - &base32::encode(base32::Alphabet::RFC4648 { padding: false }, &hotp.secret()), + &base32::encode(base32::Alphabet::RFC4648 { padding: false }, hotp.secret()), secret ) }