From e1b2b9ad47bd8104583d3501db1458850c95c32d Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Wed, 4 Oct 2023 10:40:38 +0200 Subject: [PATCH] Apply clippy suggestions from Rust 1.74 --- src/cli/rustup_mode.rs | 6 +++--- src/cli/self_update.rs | 4 ++-- src/currentprocess/homethunk.rs | 6 ++---- src/diskio/test.rs | 24 +++++++++++------------- tests/suite/cli_v1.rs | 2 +- tests/suite/cli_v2.rs | 2 +- 6 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 71f86581d9..e29c189754 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -357,7 +357,7 @@ pub(crate) fn cli() -> Command { .subcommand( Command::new("update") .about("Update Rust toolchains and rustup") - .aliases(&["upgrade", "up"]) + .aliases(["upgrade", "up"]) .after_help(UPDATE_HELP) .arg( Arg::new("toolchain") @@ -413,7 +413,7 @@ pub(crate) fn cli() -> Command { .subcommand( Command::new("install") .about("Install or update a given toolchain") - .aliases(&["update", "add"]) + .aliases(["update", "add"]) .arg( Arg::new("toolchain") .help(OFFICIAL_TOOLCHAIN_ARG_HELP) @@ -727,7 +727,7 @@ pub(crate) fn cli() -> Command { .arg(Arg::new("topic").help(TOPIC_ARG_HELP)) .group( ArgGroup::new("page").args( - &DOCS_DATA + DOCS_DATA .iter() .map(|(name, _, _)| *name) .collect::>(), diff --git a/src/cli/self_update.rs b/src/cli/self_update.rs index 9dcee209e9..e3823980af 100644 --- a/src/cli/self_update.rs +++ b/src/cli/self_update.rs @@ -750,7 +750,7 @@ fn install_bins() -> Result<()> { pub(crate) fn install_proxies() -> Result<()> { let bin_path = utils::cargo_home()?.join("bin"); - let rustup_path = bin_path.join(&format!("rustup{EXE_SUFFIX}")); + let rustup_path = bin_path.join(format!("rustup{EXE_SUFFIX}")); let rustup = Handle::from_path(&rustup_path)?; @@ -965,7 +965,7 @@ pub(crate) fn uninstall(no_prompt: bool) -> Result { let cargo_home = utils::cargo_home()?; - if !cargo_home.join(&format!("bin/rustup{EXE_SUFFIX}")).exists() { + if !cargo_home.join(format!("bin/rustup{EXE_SUFFIX}")).exists() { return Err(CLIError::NotSelfInstalled { p: cargo_home }.into()); } diff --git a/src/currentprocess/homethunk.rs b/src/currentprocess/homethunk.rs index 65f2d59e7b..065a28960e 100644 --- a/src/currentprocess/homethunk.rs +++ b/src/currentprocess/homethunk.rs @@ -1,8 +1,6 @@ /// Adapts currentprocess to the trait home::Env use std::ffi::OsString; use std::io; -#[cfg(feature = "test")] -use std::ops::Deref; use std::path::PathBuf; use home::env as home; @@ -42,10 +40,10 @@ impl home::Env for TestProcess { self.var("HOME").ok().map(|v| v.into()) } fn current_dir(&self) -> Result { - CurrentDirSource::current_dir(self.deref()) + CurrentDirSource::current_dir(self) } fn var_os(&self, key: &str) -> Option { - VarSource::var_os(self.deref(), key) + VarSource::var_os(self, key) } } diff --git a/src/diskio/test.rs b/src/diskio/test.rs index 8130213858..14c5fcb3bc 100644 --- a/src/diskio/test.rs +++ b/src/diskio/test.rs @@ -36,10 +36,10 @@ fn test_incremental_file(io_threads: &str) -> Result<()> { 0o666, io_executor.incremental_file_state(), )?; - for _ in io_executor.execute(item).collect::>() { - // The file should be open and incomplete, and no completed chunks - unreachable!(); - } + + // The file should be open and incomplete, and no completed chunks + assert!(io_executor.execute(item).collect::>().is_empty()); + let mut chunk = io_executor.get_buffer(super::IO_CHUNK_SIZE); chunk.extend(b"0123456789"); chunk = chunk.finished(); @@ -76,13 +76,12 @@ fn test_incremental_file(io_threads: &str) -> Result<()> { break; } } - assert!(file_finished); - for _ in io_executor.join().collect::>() { - // no more work should be outstanding - unreachable!(); - } + // no more work should be outstanding + assert!(file_finished); + assert!(io_executor.join().collect::>().is_empty()); assert_eq!(io_executor.buffer_used(), 0); + Ok(()) })?; // We should be able to read back the file @@ -143,10 +142,9 @@ fn test_complete_file(io_threads: &str) -> Result<()> { } } assert!(items > 0); - for _ in io_executor.join().collect::>() { - // no more work should be outstanding - unreachable!(); - } + // no more work should be outstanding + assert!(io_executor.join().collect::>().is_empty()); + Ok(()) })?; // We should be able to read back the file with correct content diff --git a/tests/suite/cli_v1.rs b/tests/suite/cli_v1.rs index 4a3d617423..331b2747f6 100644 --- a/tests/suite/cli_v1.rs +++ b/tests/suite/cli_v1.rs @@ -176,7 +176,7 @@ fn bad_sha_on_manifest() { fn bad_sha_on_installer() { setup(&|config| { let dir = config.distdir.as_ref().unwrap().join("dist"); - for file in fs::read_dir(&dir).unwrap() { + for file in fs::read_dir(dir).unwrap() { let file = file.unwrap(); let path = file.path(); let filename = path.to_string_lossy(); diff --git a/tests/suite/cli_v2.rs b/tests/suite/cli_v2.rs index e892ac8048..f94f3da91a 100644 --- a/tests/suite/cli_v2.rs +++ b/tests/suite/cli_v2.rs @@ -304,7 +304,7 @@ fn bad_sha_on_installer() { setup(&|config| { // Since the v2 sha's are contained in the manifest, corrupt the installer let dir = config.distdir.as_ref().unwrap().join("dist/2015-01-02"); - for file in fs::read_dir(&dir).unwrap() { + for file in fs::read_dir(dir).unwrap() { let file = file.unwrap(); let path = file.path(); let filename = path.to_string_lossy();