diff --git a/src/rustup-cli/common.rs b/src/rustup-cli/common.rs index 9c8adcd0df..1abf345af4 100644 --- a/src/rustup-cli/common.rs +++ b/src/rustup-cli/common.rs @@ -225,7 +225,7 @@ pub fn rustc_version(toolchain: &Toolchain) -> String { toolchain.set_ldpath(&mut cmd); let out= cmd.output().ok(); - let out = out.into_iter().filter(|o| o.status.success()).next(); + let out = out.into_iter().find(|o| o.status.success()); let stdout = out.and_then(|o| String::from_utf8(o.stdout).ok()); let line1 = stdout.and_then(|o| o.lines().next().map(|l| l.to_owned())); @@ -375,7 +375,7 @@ pub fn report_error(e: &Error) { } } - return false; + false } } diff --git a/src/rustup-cli/download_tracker.rs b/src/rustup-cli/download_tracker.rs index 12fc4c07ab..e6e61b7cf6 100644 --- a/src/rustup-cli/download_tracker.rs +++ b/src/rustup-cli/download_tracker.rs @@ -51,19 +51,19 @@ impl DownloadTracker { } pub fn handle_notification(&mut self, n: &Notification) -> bool { - match n { - &Notification::Install(In::Utils(Un::DownloadContentLengthReceived(content_len))) => { + match *n { + Notification::Install(In::Utils(Un::DownloadContentLengthReceived(content_len))) => { self.content_length_received(content_len); true } - &Notification::Install(In::Utils(Un::DownloadDataReceived(data))) => { + Notification::Install(In::Utils(Un::DownloadDataReceived(data))) => { if tty::stdout_isatty() && self.term.is_some() { self.data_received(data.len()); } true } - &Notification::Install(In::Utils(Un::DownloadFinished)) => { + Notification::Install(In::Utils(Un::DownloadFinished)) => { self.download_finished(); true } diff --git a/src/rustup-cli/main.rs b/src/rustup-cli/main.rs index bb34be8aaa..8dc31f4d84 100644 --- a/src/rustup-cli/main.rs +++ b/src/rustup-cli/main.rs @@ -72,7 +72,7 @@ fn run_multirust() -> Result<()> { do_compatibility_hacks(); // The name of arg0 determines how the program is going to behave - let arg0 = env::args().next().map(|a| PathBuf::from(a)); + let arg0 = env::args().next().map(PathBuf::from); let name = arg0.as_ref() .and_then(|a| a.file_stem()) .and_then(|a| a.to_str()); diff --git a/src/rustup-cli/proxy_mode.rs b/src/rustup-cli/proxy_mode.rs index f6943c4bd3..4343b9a35f 100644 --- a/src/rustup-cli/proxy_mode.rs +++ b/src/rustup-cli/proxy_mode.rs @@ -15,7 +15,7 @@ pub fn main() -> Result<()> { let mut args = env::args(); - let arg0 = args.next().map(|a| PathBuf::from(a)); + let arg0 = args.next().map(PathBuf::from); let arg0 = arg0.as_ref() .and_then(|a| a.file_name()) .and_then(|a| a.to_str()); @@ -25,7 +25,7 @@ pub fn main() -> Result<()> { let arg1 = args.next(); let toolchain = arg1.as_ref() .and_then(|arg1| { - if arg1.starts_with("+") { + if arg1.starts_with('+') { Some(&arg1[1..]) } else { None diff --git a/src/rustup-cli/rustup_mode.rs b/src/rustup-cli/rustup_mode.rs index 45e969ff34..3b67d5a19f 100644 --- a/src/rustup-cli/rustup_mode.rs +++ b/src/rustup-cli/rustup_mode.rs @@ -389,7 +389,7 @@ fn update_bare_triple_check(cfg: &Cfg, name: &str) -> Result<()> { continue; } if let Ok(desc) = PartialToolchainDesc::from_str(&t) { - fn triple_comp_eq(given: &String, from_desc: Option<&String>) -> bool { + fn triple_comp_eq(given: &str, from_desc: Option<&String>) -> bool { from_desc.map_or(false, |s| *s == *given) } @@ -407,7 +407,7 @@ fn update_bare_triple_check(cfg: &Cfg, name: &str) -> Result<()> { 1 => println!("\nyou may use the following toolchain: {}\n", candidates[0]), _ => { println!("\nyou may use one of the following toolchains:"); - for n in candidates.iter() { + for n in &candidates { println!("{}", n); } println!(""); diff --git a/src/rustup-cli/self_update.rs b/src/rustup-cli/self_update.rs index 041e0e6871..e3abe8f550 100644 --- a/src/rustup-cli/self_update.rs +++ b/src/rustup-cli/self_update.rs @@ -196,7 +196,7 @@ static TOOLS: &'static [&'static str] static UPDATE_ROOT: &'static str = "https://static.rust-lang.org/rustup"; -/// CARGO_HOME suitable for display, possibly with $HOME +/// `CARGO_HOME` suitable for display, possibly with $HOME /// substituted for the directory prefix fn canonical_cargo_home() -> Result { let path = try!(utils::cargo_home()); @@ -211,8 +211,8 @@ fn canonical_cargo_home() -> Result { } /// Installing is a simple matter of coping the running binary to -/// CARGO_HOME/bin, hardlinking the various Rust tools to it, -/// and and adding CARGO_HOME/bin to PATH. +/// `CARGO_HOME`/bin, hardlinking the various Rust tools to it, +/// and and adding `CARGO_HOME`/bin to PATH. pub fn install(no_prompt: bool, verbose: bool, mut opts: InstallOpts) -> Result<()> { @@ -344,7 +344,7 @@ fn do_pre_install_sanity_checks() -> Result<()> { rustup_sh_version_path.map(|p| p.exists()) == Some(true); let old_multirust_meta_exists = if let Some(ref multirust_version_path) = multirust_version_path { multirust_version_path.exists() && { - let version = utils::read_file("old-multirust", &multirust_version_path); + let version = utils::read_file("old-multirust", multirust_version_path); let version = version.unwrap_or(String::new()); let version = version.parse().unwrap_or(0); let cutoff_version = 12; // First rustup version @@ -417,7 +417,7 @@ fn do_anti_sudo_check(no_prompt: bool) -> Result<()> { let mut pwd = unsafe { mem::uninitialized::() }; let mut pwdp: *mut c::passwd = ptr::null_mut(); let rv = unsafe { c::getpwuid_r(c::geteuid(), &mut pwd, mem::transmute(&mut buf), buf.len(), &mut pwdp) }; - if rv != 0 || pwdp == ptr::null_mut() { + if rv != 0 || pwdp.is_null() { warn!("getpwuid_r: couldn't get user data"); return false; } @@ -426,7 +426,7 @@ fn do_anti_sudo_check(no_prompt: bool) -> Result<()> { let env_home = env_home.as_ref().map(Deref::deref); match (env_home, pw_dir) { (None, _) | (_, None) => false, - (Some(ref eh), Some(ref pd)) => eh != pd + (Some(eh), Some(pd)) => eh != pd } } @@ -492,7 +492,7 @@ fn pre_install_msg(no_modify_path: bool) -> Result { None } }).collect::>(); - assert!(rcfiles.len() == 1); // Only modifying .profile + assert_eq!(rcfiles.len(), 1); // Only modifying .profile Ok(format!(pre_install_msg_unix!(), cargo_home_bin = cargo_home_bin.display(), rcfiles = rcfiles[0])) @@ -981,7 +981,7 @@ fn get_add_path_methods() -> Vec { let profile = utils::home_dir().map(|p| p.join(".profile")); let rcfiles = vec![profile].into_iter().filter_map(|f|f); - rcfiles.map(|f| PathUpdateMethod::RcFile(f)).collect() + rcfiles.map(PathUpdateMethod::RcFile).collect() } fn shell_export_string() -> Result { @@ -1119,7 +1119,7 @@ fn get_remove_path_methods() -> Result> { file.contains(addition) }); - Ok(matching_rcfiles.map(|f| PathUpdateMethod::RcFile(f)).collect()) + Ok(matching_rcfiles.map(PathUpdateMethod::RcFile).collect()) } #[cfg(windows)] @@ -1213,7 +1213,7 @@ fn do_remove_from_path(methods: &[PathUpdateMethod]) -> Result<()> { Ok(()) } -/// Self update downloads rustup-init to CARGO_HOME/bin/rustup-init +/// Self update downloads rustup-init to `CARGO_HOME`/bin/rustup-init /// and runs it. /// /// It does a few things to accomodate self-delete problems on windows: @@ -1226,7 +1226,7 @@ fn do_remove_from_path(methods: &[PathUpdateMethod]) -> Result<()> { /// /// Because it's again difficult for rustup-init to delete itself /// (and on windows this process will not be running to do it), -/// rustup-init is stored in CARGO_HOME/bin, and then deleted next +/// rustup-init is stored in `CARGO_HOME`/bin, and then deleted next /// time rustup runs. pub fn update() -> Result<()> { if NEVER_SELF_UPDATE { @@ -1236,7 +1236,7 @@ pub fn update() -> Result<()> { } let setup_path = try!(prepare_update()); if let Some(ref p) = setup_path { - let version = match get_new_rustup_version(&p) { + let version = match get_new_rustup_version(p) { Some(new_version) => parse_new_rustup_version(new_version), None => { err!("failed to get rustup version"); @@ -1376,7 +1376,7 @@ pub fn run_update(setup_path: &Path) -> Result<()> { } /// This function is as the final step of a self-upgrade. It replaces -/// CARGO_HOME/bin/rustup with the running exe, and updates the the +/// `CARGO_HOME`/bin/rustup with the running exe, and updates the the /// links to it. On windows this will run *after* the original /// rustup process exits. #[cfg(unix)] diff --git a/src/rustup-cli/term2.rs b/src/rustup-cli/term2.rs index cddfabeaed..1fb340f266 100644 --- a/src/rustup-cli/term2.rs +++ b/src/rustup-cli/term2.rs @@ -1,5 +1,5 @@ -//! This provides wrappers around the StdoutTerminal and StderrTerminal types -//! that does not fail if StdoutTerminal etc can't be constructed, which happens +//! This provides wrappers around the `StdoutTerminal` and `StderrTerminal` types +//! that does not fail if `StdoutTerminal` etc can't be constructed, which happens //! if TERM isn't defined. use std::io; diff --git a/tests/cli-exact.rs b/tests/cli-exact.rs index 2e24e6e883..b384db59e7 100644 --- a/tests/cli-exact.rs +++ b/tests/cli-exact.rs @@ -302,7 +302,7 @@ fn enable_telemetry() { expect_ok_ex(config, &["rustup", "telemetry", "enable"], r"", - &format!("info: telemetry set to 'on'\n")); + "info: telemetry set to 'on'\n"); }); } @@ -312,6 +312,6 @@ fn disable_telemetry() { expect_ok_ex(config, &["rustup", "telemetry", "disable"], r"", - &format!("info: telemetry set to 'off'\n")); + "info: telemetry set to 'off'\n"); }); } diff --git a/tests/cli-inst-interactive.rs b/tests/cli-inst-interactive.rs index 24c2f16e34..cb1fe054a9 100644 --- a/tests/cli-inst-interactive.rs +++ b/tests/cli-inst-interactive.rs @@ -32,7 +32,7 @@ pub fn setup(f: &Fn(&Config)) { } fn run_input(config: &Config, args: &[&str], input: &str) -> SanitizedOutput { - let mut cmd = clitools::cmd(config, &args[0], &args[1..]); + let mut cmd = clitools::cmd(config, args[0], &args[1..]); clitools::env(config, &mut cmd); cmd.stdin(Stdio::piped()); diff --git a/tests/cli-misc.rs b/tests/cli-misc.rs index ed164965f4..9c9facf3d0 100644 --- a/tests/cli-misc.rs +++ b/tests/cli-misc.rs @@ -172,7 +172,7 @@ fn subcommand_required_for_target() { clitools::env(config, &mut cmd); let out = cmd.output().unwrap(); assert!(!out.status.success()); - assert!(out.status.code().unwrap() != 101); + assert_ne!(out.status.code().unwrap(), 101); }); } @@ -185,7 +185,7 @@ fn subcommand_required_for_toolchain() { clitools::env(config, &mut cmd); let out = cmd.output().unwrap(); assert!(!out.status.success()); - assert!(out.status.code().unwrap() != 101); + assert_ne!(out.status.code().unwrap(), 101); }); } @@ -198,7 +198,7 @@ fn subcommand_required_for_override() { clitools::env(config, &mut cmd); let out = cmd.output().unwrap(); assert!(!out.status.success()); - assert!(out.status.code().unwrap() != 101); + assert_ne!(out.status.code().unwrap(), 101); }); } @@ -211,7 +211,7 @@ fn subcommand_required_for_self() { clitools::env(config, &mut cmd); let out = cmd.output().unwrap(); assert!(!out.status.success()); - assert!(out.status.code().unwrap() != 101); + assert_ne!(out.status.code().unwrap(), 101); }); } @@ -372,7 +372,7 @@ fn telemetry_supports_huge_output() { setup(&|config| { expect_ok(config, &["rustup", "default", "stable"]); expect_ok(config, &["rustup", "telemetry", "enable"]); - expect_timeout_ok(&config, StdDuration::from_secs(5), &["rustc", "--huge-output"]); + expect_timeout_ok(config, StdDuration::from_secs(5), &["rustc", "--huge-output"]); expect_stdout_ok(config, &["rustup", "telemetry", "analyze"], "'E0428': 10000") }) } @@ -402,6 +402,6 @@ fn telemetry_cleanup_removes_old_files() { let contents = out.unwrap(); let count = contents.count(); - assert!(count == 100); + assert_eq!(count, 100); }); } diff --git a/tests/cli-rustup.rs b/tests/cli-rustup.rs index 4679cc7dde..00c26e4fbb 100644 --- a/tests/cli-rustup.rs +++ b/tests/cli-rustup.rs @@ -477,7 +477,7 @@ fn show_toolchain_env() { let out = cmd.output().unwrap(); assert!(out.status.success()); let stdout = String::from_utf8(out.stdout).unwrap(); - assert!(&stdout == for_host!(r"Default host: {0} + assert_eq!(&stdout, for_host!(r"Default host: {0} nightly-{0} (environment override by RUSTUP_TOOLCHAIN) 1.3.0 (hash-n-2) diff --git a/tests/cli-self-upd.rs b/tests/cli-self-upd.rs index 1db5a55ac3..6359007e3b 100644 --- a/tests/cli-self-upd.rs +++ b/tests/cli-self-upd.rs @@ -571,7 +571,7 @@ fn update_updates_rustup_bin() { let after_hash = calc_hash(bin); - assert!(before_hash != after_hash); + assert_ne!(before_hash, after_hash); }); } @@ -610,7 +610,7 @@ fn rustup_self_updates() { let after_hash = calc_hash(bin); - assert!(before_hash != after_hash); + assert_ne!(before_hash, after_hash); }) } diff --git a/tests/cli-v1.rs b/tests/cli-v1.rs index 8c27211750..a75a94a42b 100644 --- a/tests/cli-v1.rs +++ b/tests/cli-v1.rs @@ -151,7 +151,7 @@ fn bad_sha_on_manifest() { let sha_file = config.distdir.join("dist/channel-rust-nightly.sha256"); let sha_str = rustup_utils::raw::read_file(&sha_file).unwrap(); let mut sha_bytes = sha_str.into_bytes(); - &mut sha_bytes[..10].clone_from_slice(b"aaaaaaaaaa"); + sha_bytes[..10].clone_from_slice(b"aaaaaaaaaa"); let sha_str = String::from_utf8(sha_bytes).unwrap(); rustup_utils::raw::write_file(&sha_file, &sha_str).unwrap(); expect_err(config, &["rustup", "default", "nightly"], diff --git a/tests/cli-v2.rs b/tests/cli-v2.rs index 1ec0e0de95..f55674a6dc 100644 --- a/tests/cli-v2.rs +++ b/tests/cli-v2.rs @@ -195,7 +195,7 @@ fn bad_sha_on_manifest() { let sha_file = config.distdir.join("dist/channel-rust-nightly.toml.sha256"); let sha_str = rustup_utils::raw::read_file(&sha_file).unwrap(); let mut sha_bytes = sha_str.into_bytes(); - &mut sha_bytes[..10].clone_from_slice(b"aaaaaaaaaa"); + sha_bytes[..10].clone_from_slice(b"aaaaaaaaaa"); let sha_str = String::from_utf8(sha_bytes).unwrap(); rustup_utils::raw::write_file(&sha_file, &sha_str).unwrap(); expect_err(config, &["rustup", "default", "nightly"],