From 07640d9fe10fbf281dedb8171422ff1b738d073d Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Sun, 26 Mar 2017 11:23:40 +0100 Subject: [PATCH 01/10] Switch to more specific assert macros --- src/rustup-cli/self_update.rs | 2 +- tests/cli-misc.rs | 10 +++++----- tests/cli-rustup.rs | 2 +- tests/cli-self-upd.rs | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/rustup-cli/self_update.rs b/src/rustup-cli/self_update.rs index 041e0e6871..35d2b1a88e 100644 --- a/src/rustup-cli/self_update.rs +++ b/src/rustup-cli/self_update.rs @@ -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])) diff --git a/tests/cli-misc.rs b/tests/cli-misc.rs index ed164965f4..d7344274e0 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); }); } @@ -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); }) } From d50461fba0d6c5e8437c4ff3f41b84c360f15f65 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Sun, 26 Mar 2017 11:25:43 +0100 Subject: [PATCH 02/10] Remove unnecessary reference --- src/rustup-cli/download_tracker.rs | 8 ++++---- src/rustup-cli/self_update.rs | 6 +++--- tests/cli-inst-interactive.rs | 2 +- tests/cli-misc.rs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) 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/self_update.rs b/src/rustup-cli/self_update.rs index 35d2b1a88e..01c5a091eb 100644 --- a/src/rustup-cli/self_update.rs +++ b/src/rustup-cli/self_update.rs @@ -344,8 +344,8 @@ 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 = version.unwrap_or(String::new()); + let version = utils::read_file("old-multirust", multirust_version_path); let version = version.parse().unwrap_or(0); let cutoff_version = 12; // First rustup version @@ -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 } } @@ -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"); 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 d7344274e0..9c9facf3d0 100644 --- a/tests/cli-misc.rs +++ b/tests/cli-misc.rs @@ -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") }) } From dca4b23b14957cdf862f0380f03a8c18357076ba Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Sun, 26 Mar 2017 11:26:37 +0100 Subject: [PATCH 03/10] Switch to more suitable functions/simplify closures --- src/rustup-cli/common.rs | 2 +- src/rustup-cli/main.rs | 2 +- src/rustup-cli/proxy_mode.rs | 2 +- src/rustup-cli/self_update.rs | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/rustup-cli/common.rs b/src/rustup-cli/common.rs index 9c8adcd0df..5e6bf28a93 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())); 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..ab4fd0406e 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()); diff --git a/src/rustup-cli/self_update.rs b/src/rustup-cli/self_update.rs index 01c5a091eb..4505efacba 100644 --- a/src/rustup-cli/self_update.rs +++ b/src/rustup-cli/self_update.rs @@ -344,8 +344,8 @@ 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 = version.unwrap_or(String::new()); 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; } @@ -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)] From 12b83bea1aad9f3a02261171bc5d82f09aee46f0 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Sun, 26 Mar 2017 11:26:50 +0100 Subject: [PATCH 04/10] Remove explicit return --- src/rustup-cli/common.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rustup-cli/common.rs b/src/rustup-cli/common.rs index 5e6bf28a93..1abf345af4 100644 --- a/src/rustup-cli/common.rs +++ b/src/rustup-cli/common.rs @@ -375,7 +375,7 @@ pub fn report_error(e: &Error) { } } - return false; + false } } From 9859c02fd2dc81ab8f7c6461736216bd4c6d42aa Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Sun, 26 Mar 2017 11:27:18 +0100 Subject: [PATCH 05/10] Fix documentation --- src/rustup-cli/self_update.rs | 12 ++++++------ src/rustup-cli/term2.rs | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/rustup-cli/self_update.rs b/src/rustup-cli/self_update.rs index 4505efacba..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<()> { @@ -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 { @@ -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; From 579c4393db1186a3ec5399fce637fbbf8aa9fe21 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Sun, 26 Mar 2017 11:27:51 +0100 Subject: [PATCH 06/10] Remove unnecessary use of format!() --- tests/cli-exact.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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"); }); } From 86c287bc4b4a52513120d57708dc9cb3c4177fbf Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Sun, 26 Mar 2017 11:28:53 +0100 Subject: [PATCH 07/10] Switch String to str --- src/rustup-cli/rustup_mode.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rustup-cli/rustup_mode.rs b/src/rustup-cli/rustup_mode.rs index 9e2285f0ca..cd13ce021f 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) } From 950c465bb9dd7fdfdce1ccf2639d2ea24cb4b6bc Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Sun, 26 Mar 2017 11:29:11 +0100 Subject: [PATCH 08/10] Switch single character double-quote usage to single-quote --- src/rustup-cli/proxy_mode.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rustup-cli/proxy_mode.rs b/src/rustup-cli/proxy_mode.rs index ab4fd0406e..4343b9a35f 100644 --- a/src/rustup-cli/proxy_mode.rs +++ b/src/rustup-cli/proxy_mode.rs @@ -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 From efd2cd709b0a8a265a72a56e1e6f5fbddd316ba1 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Sun, 26 Mar 2017 11:29:19 +0100 Subject: [PATCH 09/10] Use reference instead of .iter() --- src/rustup-cli/rustup_mode.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rustup-cli/rustup_mode.rs b/src/rustup-cli/rustup_mode.rs index cd13ce021f..7e57538a57 100644 --- a/src/rustup-cli/rustup_mode.rs +++ b/src/rustup-cli/rustup_mode.rs @@ -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!(""); From 2c41ddf4c0b27def52c4e517112f0c531dcfa99c Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Sun, 26 Mar 2017 11:29:34 +0100 Subject: [PATCH 10/10] Remove explicit use of &mut --- tests/cli-v1.rs | 2 +- tests/cli-v2.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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"],