From 9b2bb43c95fd23357c95a845a0bac79d70ff84c2 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 19 Apr 2019 13:55:30 +0700 Subject: [PATCH 01/17] clippy: Fix unused_imports --- download/src/lib.rs | 1 - src/utils/raw.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/download/src/lib.rs b/download/src/lib.rs index 1d3ddfc9d7..848da8c415 100644 --- a/download/src/lib.rs +++ b/download/src/lib.rs @@ -330,7 +330,6 @@ pub mod reqwest_be { callback: &dyn Fn(Event<'_>) -> Result<()>, ) -> Result { use std::fs; - use std::io; // The file scheme is mostly for use by tests to mock the dist server if url.scheme() == "file" { diff --git a/src/utils/raw.rs b/src/utils/raw.rs index d433e09e8d..8435173750 100644 --- a/src/utils/raw.rs +++ b/src/utils/raw.rs @@ -356,7 +356,6 @@ pub fn find_cmd<'a>(cmds: &[&'a str]) -> Option<&'a str> { pub fn open_browser(path: &Path) -> io::Result { #[cfg(not(windows))] fn inner(path: &Path) -> io::Result { - use std::env; use std::process::Stdio; let env_browser = env::var_os("BROWSER").map(|b| env::split_paths(&b).collect::>()); From b75c3fd0b009c4a8cfeab748c4ad21167661fbc3 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 19 Apr 2019 13:57:06 +0700 Subject: [PATCH 02/17] clippy: Fix let_and_return --- download/tests/support/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/download/tests/support/mod.rs b/download/tests/support/mod.rs index 256f3772cb..ca5a571e15 100644 --- a/download/tests/support/mod.rs +++ b/download/tests/support/mod.rs @@ -53,8 +53,7 @@ pub fn serve_file(contents: Vec) -> SocketAddr { addr_tx.send(addr).unwrap(); hyper::rt::run(server.map_err(|e| panic!(e))); }); - let addr = addr_rx.wait().unwrap(); - addr + addr_rx.wait().unwrap() } fn serve_contents( From 58b18a650d2e702e042139e7475ab2ecaefc24af Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 19 Apr 2019 14:02:51 +0700 Subject: [PATCH 03/17] clippy: Fix single_char_pattern --- download/tests/support/mod.rs | 6 +++--- tests/cli-misc.rs | 2 +- tests/mock/clitools.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/download/tests/support/mod.rs b/download/tests/support/mod.rs index ca5a571e15..be8d64b2d3 100644 --- a/download/tests/support/mod.rs +++ b/download/tests/support/mod.rs @@ -66,9 +66,9 @@ fn serve_contents( let range = range.to_str().expect("unexpected Range header"); assert!(range.starts_with("bytes=")); let range = range.trim_start_matches("bytes="); - assert!(range.ends_with("-")); - let range = range.trim_end_matches("-"); - assert_eq!(range.split("-").count(), 1); + assert!(range.ends_with('-')); + let range = range.trim_end_matches('-'); + assert_eq!(range.split('-').count(), 1); let start: u64 = range.parse().expect("unexpected Range header"); range_header = Some(format!("bytes {}-{len}/{len}", start, len = contents.len())); diff --git a/tests/cli-misc.rs b/tests/cli-misc.rs index 9b7e83e0c6..83b4e242d5 100644 --- a/tests/cli-misc.rs +++ b/tests/cli-misc.rs @@ -36,7 +36,7 @@ fn no_colors_in_piped_error_output() { let args: Vec<&str> = vec![]; let out = run(config, "rustc", &args, &[]); assert!(!out.ok); - assert!(!out.stderr.contains("\u{1b}")); + assert!(!out.stderr.contains('\x1b')); }); } diff --git a/tests/mock/clitools.rs b/tests/mock/clitools.rs index a4044084a2..21db0f4a83 100644 --- a/tests/mock/clitools.rs +++ b/tests/mock/clitools.rs @@ -268,7 +268,7 @@ pub fn expect_ok_eq(config: &Config, args1: &[&str], args2: &[&str]) { fn print_command(args: &[&str], out: &SanitizedOutput) { print!("\n>"); for arg in args { - if arg.contains(" ") { + if arg.contains(' ') { print!(" {:?}", arg); } else { print!(" {}", arg); From 71178b4aa11d89cddf569176e1f45864c718335e Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 19 Apr 2019 15:33:58 +0700 Subject: [PATCH 04/17] clippy: Fix toplevel_ref_arg --- download/tests/download-curl-resume.rs | 4 +- download/tests/download-reqwest-resume.rs | 4 +- tests/cli-misc.rs | 29 +-- tests/cli-rustup.rs | 22 +-- tests/cli-self-upd.rs | 158 ++++++++-------- tests/cli-v2.rs | 22 +-- tests/dist.rs | 212 +++++++++++++++------- tests/dist_manifest.rs | 4 +- tests/dist_transactions.rs | 60 +++--- tests/mock/clitools.rs | 44 ++--- tests/mock/dist.rs | 101 +++++------ tests/mock/mod.rs | 4 +- 12 files changed, 368 insertions(+), 296 deletions(-) diff --git a/download/tests/download-curl-resume.rs b/download/tests/download-curl-resume.rs index a61defd804..b5cc862f26 100644 --- a/download/tests/download-curl-resume.rs +++ b/download/tests/download-curl-resume.rs @@ -70,7 +70,7 @@ fn callback_gets_all_data_as_if_the_download_happened_all_at_once() { assert!(*callback_partial.lock().unwrap()); assert_eq!(*callback_len.lock().unwrap(), Some(5)); - let ref observed_bytes = *received_in_callback.lock().unwrap(); - assert_eq!(observed_bytes, &vec![b'1', b'2', b'3', b'4', b'5']); + let observed_bytes = received_in_callback.into_inner().unwrap(); + assert_eq!(observed_bytes, vec![b'1', b'2', b'3', b'4', b'5']); assert_eq!(file_contents(&target_path), "12345"); } diff --git a/download/tests/download-reqwest-resume.rs b/download/tests/download-reqwest-resume.rs index 38feb6ad34..592cab8dda 100644 --- a/download/tests/download-reqwest-resume.rs +++ b/download/tests/download-reqwest-resume.rs @@ -70,7 +70,7 @@ fn callback_gets_all_data_as_if_the_download_happened_all_at_once() { assert!(*callback_partial.lock().unwrap()); assert_eq!(*callback_len.lock().unwrap(), Some(5)); - let ref observed_bytes = *received_in_callback.lock().unwrap(); - assert_eq!(observed_bytes, &vec![b'1', b'2', b'3', b'4', b'5']); + let observed_bytes = received_in_callback.into_inner().unwrap(); + assert_eq!(observed_bytes, vec![b'1', b'2', b'3', b'4', b'5']); assert_eq!(file_contents(&target_path), "12345"); } diff --git a/tests/cli-misc.rs b/tests/cli-misc.rs index 83b4e242d5..2d30dc7498 100644 --- a/tests/cli-misc.rs +++ b/tests/cli-misc.rs @@ -196,8 +196,8 @@ fn multi_host_smoke_test() { } clitools::setup(Scenario::MultiHost, &|config| { - let ref toolchain = format!("nightly-{}", clitools::MULTI_ARCH1); - expect_ok(config, &["rustup", "default", toolchain]); + let toolchain = format!("nightly-{}", clitools::MULTI_ARCH1); + expect_ok(config, &["rustup", "default", &toolchain]); expect_stdout_ok(config, &["rustc", "--version"], "xxxx-n-2"); // cross-host mocks have their own versions }); } @@ -288,9 +288,10 @@ fn rustup_failed_path_search() { setup(&|config| { use std::env::consts::EXE_SUFFIX; - let ref rustup_path = config.exedir.join(&format!("rustup{}", EXE_SUFFIX)); - let ref tool_path = config.exedir.join(&format!("fake_proxy{}", EXE_SUFFIX)); - utils::hardlink_file(rustup_path, tool_path).expect("Failed to create fake proxy for test"); + let rustup_path = config.exedir.join(&format!("rustup{}", EXE_SUFFIX)); + let tool_path = config.exedir.join(&format!("fake_proxy{}", EXE_SUFFIX)); + utils::hardlink_file(&rustup_path, &tool_path) + .expect("Failed to create fake proxy for test"); expect_ok( config, @@ -324,9 +325,9 @@ fn rustup_failed_path_search_toolchain() { setup(&|config| { use std::env::consts::EXE_SUFFIX; - let ref rustup_path = config.exedir.join(&format!("rustup{}", EXE_SUFFIX)); - let ref tool_path = config.exedir.join(&format!("cargo-miri{}", EXE_SUFFIX)); - utils::hardlink_file(rustup_path, tool_path) + let rustup_path = config.exedir.join(&format!("rustup{}", EXE_SUFFIX)); + let tool_path = config.exedir.join(&format!("cargo-miri{}", EXE_SUFFIX)); + utils::hardlink_file(&rustup_path, &tool_path) .expect("Failed to create fake cargo-miri for test"); expect_ok( @@ -561,8 +562,8 @@ fn rename_rls_remove() { fn install_stops_if_rustc_exists() { let temp_dir = TempDir::new("fakebin").unwrap(); // Create fake executable - let ref fake_exe = temp_dir.path().join(&format!("{}{}", "rustc", EXE_SUFFIX)); - raw::append_file(fake_exe, "").unwrap(); + let fake_exe = temp_dir.path().join(&format!("{}{}", "rustc", EXE_SUFFIX)); + raw::append_file(&fake_exe, "").unwrap(); let temp_dir_path = temp_dir.path().to_str().unwrap(); setup(&|config| { @@ -590,8 +591,8 @@ fn install_stops_if_rustc_exists() { fn install_stops_if_cargo_exists() { let temp_dir = TempDir::new("fakebin").unwrap(); // Create fake executable - let ref fake_exe = temp_dir.path().join(&format!("{}{}", "cargo", EXE_SUFFIX)); - raw::append_file(fake_exe, "").unwrap(); + let fake_exe = temp_dir.path().join(&format!("{}{}", "cargo", EXE_SUFFIX)); + raw::append_file(&fake_exe, "").unwrap(); let temp_dir_path = temp_dir.path().to_str().unwrap(); setup(&|config| { @@ -619,8 +620,8 @@ fn install_stops_if_cargo_exists() { fn with_no_prompt_install_succeeds_if_rustc_exists() { let temp_dir = TempDir::new("fakebin").unwrap(); // Create fake executable - let ref fake_exe = temp_dir.path().join(&format!("{}{}", "rustc", EXE_SUFFIX)); - raw::append_file(fake_exe, "").unwrap(); + let fake_exe = temp_dir.path().join(&format!("{}{}", "rustc", EXE_SUFFIX)); + raw::append_file(&fake_exe, "").unwrap(); let temp_dir_path = temp_dir.path().to_str().unwrap(); setup(&|config| { diff --git a/tests/cli-rustup.rs b/tests/cli-rustup.rs index 6dbeea9f4e..a6ea4bea9d 100644 --- a/tests/cli-rustup.rs +++ b/tests/cli-rustup.rs @@ -303,19 +303,19 @@ fn add_target() { #[test] fn remove_target() { setup(&|config| { - let ref path = format!( + let path = format!( "toolchains/nightly-{}/lib/rustlib/{}/lib/libstd.rlib", &this_host_triple(), clitools::CROSS_ARCH1 ); expect_ok(config, &["rustup", "default", "nightly"]); expect_ok(config, &["rustup", "target", "add", clitools::CROSS_ARCH1]); - assert!(config.rustupdir.join(path).exists()); + assert!(config.rustupdir.join(&path).exists()); expect_ok( config, &["rustup", "target", "remove", clitools::CROSS_ARCH1], ); - assert!(!config.rustupdir.join(path).exists()); + assert!(!config.rustupdir.join(&path).exists()); }); } @@ -406,7 +406,7 @@ fn add_target_explicit() { #[test] fn remove_target_explicit() { setup(&|config| { - let ref path = format!( + let path = format!( "toolchains/nightly-{}/lib/rustlib/{}/lib/libstd.rlib", &this_host_triple(), clitools::CROSS_ARCH1 @@ -423,7 +423,7 @@ fn remove_target_explicit() { clitools::CROSS_ARCH1, ], ); - assert!(config.rustupdir.join(path).exists()); + assert!(config.rustupdir.join(&path).exists()); expect_ok( config, &[ @@ -435,7 +435,7 @@ fn remove_target_explicit() { clitools::CROSS_ARCH1, ], ); - assert!(!config.rustupdir.join(path).exists()); + assert!(!config.rustupdir.join(&path).exists()); }); } @@ -474,11 +474,11 @@ fn fallback_cargo_calls_correct_rustc() { setup(&|config| { // Hm, this is the _only_ test that assumes that toolchain proxies // exist in CARGO_HOME. Adding that proxy here. - let ref rustup_path = config.exedir.join(format!("rustup{}", EXE_SUFFIX)); - let ref cargo_bin_path = config.cargodir.join("bin"); - fs::create_dir_all(cargo_bin_path).unwrap(); - let ref rustc_path = cargo_bin_path.join(format!("rustc{}", EXE_SUFFIX)); - fs::hard_link(rustup_path, rustc_path).unwrap(); + let rustup_path = config.exedir.join(format!("rustup{}", EXE_SUFFIX)); + let cargo_bin_path = config.cargodir.join("bin"); + fs::create_dir_all(&cargo_bin_path).unwrap(); + let rustc_path = cargo_bin_path.join(format!("rustc{}", EXE_SUFFIX)); + fs::hard_link(&rustup_path, &rustc_path).unwrap(); // Install a custom toolchain and a nightly toolchain for the cargo fallback let path = config.customdir.join("custom-1"); diff --git a/tests/cli-self-upd.rs b/tests/cli-self-upd.rs index 385a796a3a..7d4301b811 100644 --- a/tests/cli-self-upd.rs +++ b/tests/cli-self-upd.rs @@ -47,21 +47,21 @@ pub fn setup(f: &dyn Fn(&Config)) { pub fn update_setup(f: &dyn Fn(&Config, &Path)) { setup(&|config| { // Create a mock self-update server - let ref self_dist_tmp = TempDir::new("self_dist").unwrap(); - let ref self_dist = self_dist_tmp.path(); + let self_dist_tmp = TempDir::new("self_dist").unwrap(); + let self_dist = self_dist_tmp.path(); - let ref trip = this_host_triple(); - let ref dist_dir = self_dist.join(&format!("archive/{}/{}", TEST_VERSION, trip)); - let ref dist_exe = dist_dir.join(&format!("rustup-init{}", EXE_SUFFIX)); - let ref rustup_bin = config.exedir.join(&format!("rustup-init{}", EXE_SUFFIX)); + let trip = this_host_triple(); + let dist_dir = self_dist.join(&format!("archive/{}/{}", TEST_VERSION, trip)); + let dist_exe = dist_dir.join(&format!("rustup-init{}", EXE_SUFFIX)); + let rustup_bin = config.exedir.join(&format!("rustup-init{}", EXE_SUFFIX)); fs::create_dir_all(dist_dir).unwrap(); output_release_file(self_dist, "1", TEST_VERSION); - fs::copy(rustup_bin, dist_exe).unwrap(); + fs::copy(&rustup_bin, &dist_exe).unwrap(); // Modify the exe so it hashes different - raw::append_file(dist_exe, "").unwrap(); + raw::append_file(&dist_exe, "").unwrap(); - let ref root_url = format!("file://{}", self_dist.display()); + let root_url = format!("file://{}", self_dist.display()); env::set_var("RUSTUP_UPDATE_ROOT", root_url); f(config, self_dist); @@ -116,20 +116,20 @@ fn install_twice() { fn bins_are_executable() { setup(&|config| { expect_ok(config, &["rustup-init", "-y"]); - let ref rustup = config.cargodir.join(&format!("bin/rustup{}", EXE_SUFFIX)); - let ref rustc = config.cargodir.join(&format!("bin/rustc{}", EXE_SUFFIX)); - let ref rustdoc = config.cargodir.join(&format!("bin/rustdoc{}", EXE_SUFFIX)); - let ref cargo = config.cargodir.join(&format!("bin/cargo{}", EXE_SUFFIX)); - let ref rust_lldb = config + let rustup = config.cargodir.join(&format!("bin/rustup{}", EXE_SUFFIX)); + let rustc = config.cargodir.join(&format!("bin/rustc{}", EXE_SUFFIX)); + let rustdoc = config.cargodir.join(&format!("bin/rustdoc{}", EXE_SUFFIX)); + let cargo = config.cargodir.join(&format!("bin/cargo{}", EXE_SUFFIX)); + let rust_lldb = config .cargodir .join(&format!("bin/rust-lldb{}", EXE_SUFFIX)); - let ref rust_gdb = config.cargodir.join(&format!("bin/rust-gdb{}", EXE_SUFFIX)); - assert!(is_exe(rustup)); - assert!(is_exe(rustc)); - assert!(is_exe(rustdoc)); - assert!(is_exe(cargo)); - assert!(is_exe(rust_lldb)); - assert!(is_exe(rust_gdb)); + let rust_gdb = config.cargodir.join(&format!("bin/rust-gdb{}", EXE_SUFFIX)); + assert!(is_exe(&rustup)); + assert!(is_exe(&rustc)); + assert!(is_exe(&rustdoc)); + assert!(is_exe(&cargo)); + assert!(is_exe(&rust_lldb)); + assert!(is_exe(&rust_gdb)); }); fn is_exe(path: &Path) -> bool { @@ -290,7 +290,7 @@ fn uninstall_doesnt_leave_gc_file() { // The gc removal happens after rustup terminates. Give it a moment. thread::sleep(Duration::from_millis(100)); - let ref parent = config.cargodir.parent().unwrap(); + let parent = config.cargodir.parent().unwrap(); // Actually, there just shouldn't be any files here for dirent in fs::read_dir(parent).unwrap() { let dirent = dirent.unwrap(); @@ -308,11 +308,11 @@ fn uninstall_stress_test() {} fn install_adds_path_to_rc(rcfile: &str) { setup(&|config| { let my_rc = "foo\nbar\nbaz"; - let ref rc = config.homedir.join(rcfile); - raw::write_file(rc, my_rc).unwrap(); + let rc = config.homedir.join(rcfile); + raw::write_file(&rc, my_rc).unwrap(); expect_ok(config, &["rustup-init", "-y"]); - let new_rc = raw::read_file(rc).unwrap(); + let new_rc = raw::read_file(&rc).unwrap(); let addition = format!(r#"export PATH="{}/bin:$PATH""#, config.cargodir.display()); let expected = format!("{}\n{}\n", my_rc, addition); assert_eq!(new_rc, expected); @@ -335,7 +335,7 @@ fn install_adds_path_to_bash_profile() { #[cfg(unix)] fn install_does_not_add_path_to_bash_profile_that_doesnt_exist() { setup(&|config| { - let ref rc = config.homedir.join(".bash_profile"); + let rc = config.homedir.join(".bash_profile"); expect_ok(config, &["rustup-init", "-y"]); assert!(!rc.exists()); @@ -347,14 +347,14 @@ fn install_does_not_add_path_to_bash_profile_that_doesnt_exist() { fn install_with_zsh_adds_path_to_zprofile() { setup(&|config| { let my_rc = "foo\nbar\nbaz"; - let ref rc = config.homedir.join(".zprofile"); - raw::write_file(rc, my_rc).unwrap(); + let rc = config.homedir.join(".zprofile"); + raw::write_file(&rc, my_rc).unwrap(); let mut cmd = clitools::cmd(config, "rustup-init", &["-y"]); cmd.env("SHELL", "zsh"); assert!(cmd.output().unwrap().status.success()); - let new_rc = raw::read_file(rc).unwrap(); + let new_rc = raw::read_file(&rc).unwrap(); let addition = format!(r#"export PATH="{}/bin:$PATH""#, config.cargodir.display()); let expected = format!("{}\n{}\n", my_rc, addition); assert_eq!(new_rc, expected); @@ -367,15 +367,15 @@ fn install_with_zsh_adds_path_to_zdotdir_zprofile() { setup(&|config| { let zdotdir = TempDir::new("zdotdir").unwrap(); let my_rc = "foo\nbar\nbaz"; - let ref rc = zdotdir.path().join(".zprofile"); - raw::write_file(rc, my_rc).unwrap(); + let rc = zdotdir.path().join(".zprofile"); + raw::write_file(&rc, my_rc).unwrap(); let mut cmd = clitools::cmd(config, "rustup-init", &["-y"]); cmd.env("SHELL", "zsh"); cmd.env("ZDOTDIR", zdotdir.path()); assert!(cmd.output().unwrap().status.success()); - let new_rc = raw::read_file(rc).unwrap(); + let new_rc = raw::read_file(&rc).unwrap(); let addition = format!(r#"export PATH="{}/bin:$PATH""#, config.cargodir.display()); let expected = format!("{}\n{}\n", my_rc, addition); assert_eq!(new_rc, expected); @@ -387,12 +387,12 @@ fn install_with_zsh_adds_path_to_zdotdir_zprofile() { fn install_adds_path_to_rcfile_just_once() { setup(&|config| { let my_profile = "foo\nbar\nbaz"; - let ref profile = config.homedir.join(".profile"); - raw::write_file(profile, my_profile).unwrap(); + let profile = config.homedir.join(".profile"); + raw::write_file(&profile, my_profile).unwrap(); expect_ok(config, &["rustup-init", "-y"]); expect_ok(config, &["rustup-init", "-y"]); - let new_profile = raw::read_file(profile).unwrap(); + let new_profile = raw::read_file(&profile).unwrap(); let addition = format!(r#"export PATH="{}/bin:$PATH""#, config.cargodir.display()); let expected = format!("{}\n{}\n", my_profile, addition); assert_eq!(new_profile, expected); @@ -403,12 +403,12 @@ fn install_adds_path_to_rcfile_just_once() { fn uninstall_removes_path_from_rc(rcfile: &str) { setup(&|config| { let my_rc = "foo\nbar\nbaz"; - let ref rc = config.homedir.join(rcfile); - raw::write_file(rc, my_rc).unwrap(); + let rc = config.homedir.join(rcfile); + raw::write_file(&rc, my_rc).unwrap(); expect_ok(config, &["rustup-init", "-y"]); expect_ok(config, &["rustup", "self", "uninstall", "-y"]); - let new_rc = raw::read_file(rc).unwrap(); + let new_rc = raw::read_file(&rc).unwrap(); assert_eq!(new_rc, my_rc); }); } @@ -433,10 +433,10 @@ fn uninstall_doesnt_touch_rc_files_that_dont_contain_cargo_home() { expect_ok(config, &["rustup-init", "-y"]); expect_ok(config, &["rustup", "self", "uninstall", "-y"]); - let ref profile = config.homedir.join(".profile"); - raw::write_file(profile, my_rc).unwrap(); + let profile = config.homedir.join(".profile"); + raw::write_file(&profile, my_rc).unwrap(); - let profile = raw::read_file(profile).unwrap(); + let profile = raw::read_file(&profile).unwrap(); assert_eq!(profile, my_rc); }); @@ -453,13 +453,13 @@ fn when_cargo_home_is_the_default_write_path_specially() { // otherwise the literal path will be written to the file. let my_profile = "foo\nbar\nbaz"; - let ref profile = config.homedir.join(".profile"); - raw::write_file(profile, my_profile).unwrap(); + let profile = config.homedir.join(".profile"); + raw::write_file(&profile, my_profile).unwrap(); let mut cmd = clitools::cmd(config, "rustup-init", &["-y"]); cmd.env_remove("CARGO_HOME"); assert!(cmd.output().unwrap().status.success()); - let new_profile = raw::read_file(profile).unwrap(); + let new_profile = raw::read_file(&profile).unwrap(); let addition = format!(r#"export PATH="$HOME/.cargo/bin:$PATH""#); let expected = format!("{}\n{}\n", my_profile, addition); assert_eq!(new_profile, expected); @@ -468,7 +468,7 @@ fn when_cargo_home_is_the_default_write_path_specially() { cmd.env_remove("CARGO_HOME"); assert!(cmd.output().unwrap().status.success()); - let new_profile = raw::read_file(profile).unwrap(); + let new_profile = raw::read_file(&profile).unwrap(); assert_eq!(new_profile, my_profile); }); } @@ -512,7 +512,7 @@ fn uninstall_removes_path() { #[cfg(unix)] fn install_doesnt_modify_path_if_passed_no_modify_path() { setup(&|config| { - let ref profile = config.homedir.join(".profile"); + let profile = config.homedir.join(".profile"); expect_ok(config, &["rustup-init", "-y", "--no-modify-path"]); assert!(!profile.exists()); }); @@ -580,7 +580,7 @@ fn update_but_not_installed() { fn update_but_delete_existing_updater_first() { update_setup(&|config, _| { // The updater is stored in a known location - let ref setup = config + let setup = config .cargodir .join(&format!("bin/rustup-init{}", EXE_SUFFIX)); @@ -588,7 +588,7 @@ fn update_but_delete_existing_updater_first() { // If it happens to already exist for some reason it // should just be deleted. - raw::write_file(setup, "").unwrap(); + raw::write_file(&setup, "").unwrap(); expect_ok(config, &["rustup", "self", "update"]); let rustup = config.cargodir.join(&format!("bin/rustup{}", EXE_SUFFIX)); @@ -601,9 +601,9 @@ fn update_download_404() { update_setup(&|config, self_dist| { expect_ok(config, &["rustup-init", "-y"]); - let ref trip = this_host_triple(); - let ref dist_dir = self_dist.join(&format!("archive/{}/{}", TEST_VERSION, trip)); - let ref dist_exe = dist_dir.join(&format!("rustup-init{}", EXE_SUFFIX)); + let trip = this_host_triple(); + let dist_dir = self_dist.join(&format!("archive/{}/{}", TEST_VERSION, trip)); + let dist_exe = dist_dir.join(&format!("rustup-init{}", EXE_SUFFIX)); fs::remove_file(dist_exe).unwrap(); @@ -635,12 +635,12 @@ fn update_updates_rustup_bin() { update_setup(&|config, _| { expect_ok(config, &["rustup-init", "-y"]); - let ref bin = config.cargodir.join(&format!("bin/rustup{}", EXE_SUFFIX)); - let before_hash = calc_hash(bin); + let bin = config.cargodir.join(&format!("bin/rustup{}", EXE_SUFFIX)); + let before_hash = calc_hash(&bin); // Running the self update command on the installed binary, // so that the running binary must be replaced. - let mut cmd = Command::new(bin.clone()); + let mut cmd = Command::new(&bin); cmd.args(&["self", "update"]); clitools::env(config, &mut cmd); let out = cmd.output().unwrap(); @@ -650,7 +650,7 @@ fn update_updates_rustup_bin() { assert!(out.status.success()); - let after_hash = calc_hash(bin); + let after_hash = calc_hash(&bin); assert_ne!(before_hash, after_hash); }); @@ -690,12 +690,12 @@ fn rustup_self_updates() { update_setup(&|config, _| { expect_ok(config, &["rustup-init", "-y"]); - let ref bin = config.cargodir.join(&format!("bin/rustup{}", EXE_SUFFIX)); - let before_hash = calc_hash(bin); + let bin = config.cargodir.join(&format!("bin/rustup{}", EXE_SUFFIX)); + let before_hash = calc_hash(&bin); expect_ok(config, &["rustup", "update"]); - let after_hash = calc_hash(bin); + let after_hash = calc_hash(&bin); assert_ne!(before_hash, after_hash); }) @@ -706,12 +706,12 @@ fn rustup_self_updates_with_specified_toolchain() { update_setup(&|config, _| { expect_ok(config, &["rustup-init", "-y"]); - let ref bin = config.cargodir.join(&format!("bin/rustup{}", EXE_SUFFIX)); - let before_hash = calc_hash(bin); + let bin = config.cargodir.join(&format!("bin/rustup{}", EXE_SUFFIX)); + let before_hash = calc_hash(&bin); expect_ok(config, &["rustup", "update", "stable"]); - let after_hash = calc_hash(bin); + let after_hash = calc_hash(&bin); assert_ne!(before_hash, after_hash); }) @@ -722,12 +722,12 @@ fn rustup_no_self_update_with_specified_toolchain() { update_setup(&|config, _| { expect_ok(config, &["rustup-init", "-y"]); - let ref bin = config.cargodir.join(&format!("bin/rustup{}", EXE_SUFFIX)); - let before_hash = calc_hash(bin); + let bin = config.cargodir.join(&format!("bin/rustup{}", EXE_SUFFIX)); + let before_hash = calc_hash(&bin); expect_ok(config, &["rustup", "update", "stable", "--no-self-update"]); - let after_hash = calc_hash(bin); + let after_hash = calc_hash(&bin); assert_eq!(before_hash, after_hash); }) @@ -890,8 +890,8 @@ fn produces_env_file_on_unix() { let mut cmd = clitools::cmd(config, "rustup-init", &["-y"]); cmd.env_remove("CARGO_HOME"); assert!(cmd.output().unwrap().status.success()); - let ref envfile = config.homedir.join(".cargo/env"); - let envfile = raw::read_file(envfile).unwrap(); + let envfile = config.homedir.join(".cargo/env"); + let envfile = raw::read_file(&envfile).unwrap(); assert!(envfile.contains(r#"export PATH="$HOME/.cargo/bin:$PATH""#)); }); } @@ -951,9 +951,9 @@ fn rustup_init_works_with_weird_names() { // Browsers often rename bins to e.g. rustup-init(2).exe. setup(&|config| { - let ref old = config.exedir.join(&format!("rustup-init{}", EXE_SUFFIX)); - let ref new = config.exedir.join(&format!("rustup-init(2){}", EXE_SUFFIX)); - utils::rename_file("test", old, new).unwrap(); + let old = config.exedir.join(&format!("rustup-init{}", EXE_SUFFIX)); + let new = config.exedir.join(&format!("rustup-init(2){}", EXE_SUFFIX)); + utils::rename_file("test", &old, &new).unwrap(); expect_ok(config, &["rustup-init(2)", "-y"]); let rustup = config.cargodir.join(&format!("bin/rustup{}", EXE_SUFFIX)); assert!(rustup.exists()); @@ -1176,9 +1176,9 @@ fn rls_proxy_set_up_after_install() { #[test] fn rls_proxy_set_up_after_update() { update_setup(&|config, _| { - let ref rls_path = config.cargodir.join(format!("bin/rls{}", EXE_SUFFIX)); + let rls_path = config.cargodir.join(format!("bin/rls{}", EXE_SUFFIX)); expect_ok(config, &["rustup-init", "-y"]); - fs::remove_file(rls_path).unwrap(); + fs::remove_file(&rls_path).unwrap(); expect_ok(config, &["rustup", "self", "update"]); assert!(rls_path.exists()); }); @@ -1194,11 +1194,11 @@ fn update_does_not_overwrite_rustfmt() { // Since we just did a fresh install rustfmt will exist. Let's emulate // it not existing in this test though by removing it just after our // installation. - let ref rustfmt_path = config.cargodir.join(format!("bin/rustfmt{}", EXE_SUFFIX)); + let rustfmt_path = config.cargodir.join(format!("bin/rustfmt{}", EXE_SUFFIX)); assert!(rustfmt_path.exists()); - fs::remove_file(rustfmt_path).unwrap(); - raw::write_file(rustfmt_path, "").unwrap(); - assert_eq!(utils::file_size(rustfmt_path).unwrap(), 0); + fs::remove_file(&rustfmt_path).unwrap(); + raw::write_file(&rustfmt_path, "").unwrap(); + assert_eq!(utils::file_size(&rustfmt_path).unwrap(), 0); // Ok, now a self-update should complain about `rustfmt` not looking // like rustup and the user should take some action. @@ -1208,21 +1208,21 @@ fn update_does_not_overwrite_rustfmt() { "`rustfmt` is already installed", ); assert!(rustfmt_path.exists()); - assert_eq!(utils::file_size(rustfmt_path).unwrap(), 0); + assert_eq!(utils::file_size(&rustfmt_path).unwrap(), 0); // Now simluate us removing the rustfmt executable and rerunning a self // update, this should install the rustup shim. Note that we don't run // `rustup` here but rather the rustup we've actually installed, this'll // help reproduce bugs related to having that file being opened by the // current process. - fs::remove_file(rustfmt_path).unwrap(); + fs::remove_file(&rustfmt_path).unwrap(); let installed_rustup = config.cargodir.join("bin/rustup"); expect_ok( config, &[installed_rustup.to_str().unwrap(), "self", "update"], ); assert!(rustfmt_path.exists()); - assert!(utils::file_size(rustfmt_path).unwrap() > 0); + assert!(utils::file_size(&rustfmt_path).unwrap() > 0); }); } @@ -1233,7 +1233,7 @@ fn update_installs_clippy_cargo_and() { let version = env!("CARGO_PKG_VERSION"); output_release_file(self_dist, "1", version); - let ref cargo_clippy_path = config + let cargo_clippy_path = config .cargodir .join(format!("bin/cargo-clippy{}", EXE_SUFFIX)); assert!(cargo_clippy_path.exists()); diff --git a/tests/cli-v2.rs b/tests/cli-v2.rs index ab7ff36e2d..72ae8be264 100644 --- a/tests/cli-v2.rs +++ b/tests/cli-v2.rs @@ -812,28 +812,28 @@ fn make_component_unavailable(config: &Config, name: &str, target: &TargetTriple use crate::mock::dist::create_hash; use rustup::dist::manifest::Manifest; - let ref manifest_path = config.distdir.join("dist/channel-rust-nightly.toml"); - let ref manifest_str = rustup::utils::raw::read_file(manifest_path).unwrap(); - let mut manifest = Manifest::parse(manifest_str).unwrap(); + let manifest_path = config.distdir.join("dist/channel-rust-nightly.toml"); + let manifest_str = rustup::utils::raw::read_file(&manifest_path).unwrap(); + let mut manifest = Manifest::parse(&manifest_str).unwrap(); { let std_pkg = manifest.packages.get_mut(name).unwrap(); let target_pkg = std_pkg.targets.get_mut(target).unwrap(); target_pkg.bins = None; } - let ref manifest_str = manifest.stringify(); - rustup::utils::raw::write_file(manifest_path, manifest_str).unwrap(); + let manifest_str = manifest.stringify(); + rustup::utils::raw::write_file(&manifest_path, &manifest_str).unwrap(); // Have to update the hash too - let ref hash_path = manifest_path.with_extension("toml.sha256"); + let hash_path = manifest_path.with_extension("toml.sha256"); println!("{}", hash_path.display()); - create_hash(manifest_path, hash_path); + create_hash(&manifest_path, &hash_path); } #[test] fn update_unavailable_std() { setup(&|config| { - let ref trip = TargetTriple::from_build(); - make_component_unavailable(config, "rust-std", trip); + let trip = TargetTriple::from_build(); + make_component_unavailable(config, "rust-std", &trip); expect_err( config, &["rustup", "update", "nightly", "--no-self-update"], @@ -848,7 +848,7 @@ fn update_unavailable_std() { #[test] fn update_unavailable_force() { setup(&|config| { - let ref trip = TargetTriple::from_build(); + let trip = TargetTriple::from_build(); expect_ok(config, &["rustup", "update", "nightly", "--no-self-update"]); expect_ok( config, @@ -861,7 +861,7 @@ fn update_unavailable_force() { "nightly", ], ); - make_component_unavailable(config, "rls-preview", trip); + make_component_unavailable(config, "rls-preview", &trip); expect_err( config, &["rustup", "update", "nightly", "--no-self-update"], diff --git a/tests/dist.rs b/tests/dist.rs index c9e1978f52..48d60d866c 100644 --- a/tests/dist.rs +++ b/tests/dist.rs @@ -262,7 +262,7 @@ fn mock_dist_server_smoke_test() { #[test] fn rename_component() { let dist_tempdir = TempDir::new("rustup").unwrap(); - let ref url = Url::parse(&format!("file://{}", dist_tempdir.path().to_string_lossy())).unwrap(); + let url = Url::parse(&format!("file://{}", dist_tempdir.path().to_string_lossy())).unwrap(); let edit_1 = &|_: &str, pkgs: &mut [MockPackage]| { let tpkg = pkgs[0] @@ -303,7 +303,7 @@ fn rename_component() { setup_from_dist_server( mock_dist_server, - url, + &url, false, &|url, toolchain, prefix, download_cfg, temp_cfg| { change_channel_date(url, "nightly", "2016-02-01"); @@ -322,7 +322,7 @@ fn rename_component() { #[test] fn rename_component_new() { let dist_tempdir = TempDir::new("rustup").unwrap(); - let ref url = Url::parse(&format!("file://{}", dist_tempdir.path().to_string_lossy())).unwrap(); + let url = Url::parse(&format!("file://{}", dist_tempdir.path().to_string_lossy())).unwrap(); let edit_2 = &|_: &str, pkgs: &mut [MockPackage]| { let tpkg = pkgs[0] @@ -352,7 +352,7 @@ fn rename_component_new() { setup_from_dist_server( mock_dist_server, - url, + &url, false, &|url, toolchain, prefix, download_cfg, temp_cfg| { change_channel_date(url, "nightly", "2016-02-01"); @@ -403,9 +403,9 @@ fn update_from_dist_( force_update: bool, ) -> Result { // Download the dist manifest and place it into the installation prefix - let ref manifest_url = make_manifest_url(dist_server, toolchain)?; + let manifest_url = make_manifest_url(dist_server, toolchain)?; let manifest_file = temp_cfg.new_file()?; - utils::download_file(manifest_url, &manifest_file, None, &|_| {})?; + utils::download_file(&manifest_url, &manifest_file, None, &|_| {})?; let manifest_str = utils::read_file("manifest", &manifest_file)?; let manifest = Manifest::parse(&manifest_str)?; @@ -459,8 +459,8 @@ fn setup( ) { let dist_tempdir = TempDir::new("rustup").unwrap(); let mock_dist_server = create_mock_dist_server(dist_tempdir.path(), edit); - let ref url = Url::parse(&format!("file://{}", dist_tempdir.path().to_string_lossy())).unwrap(); - setup_from_dist_server(mock_dist_server, url, enable_xz, f); + let url = Url::parse(&format!("file://{}", dist_tempdir.path().to_string_lossy())).unwrap(); + setup_from_dist_server(mock_dist_server, &url, enable_xz, f); } fn setup_from_dist_server( @@ -474,22 +474,22 @@ fn setup_from_dist_server( let prefix_tempdir = TempDir::new("rustup").unwrap(); let work_tempdir = TempDir::new("rustup").unwrap(); - let ref temp_cfg = temp::Cfg::new( + let temp_cfg = temp::Cfg::new( work_tempdir.path().to_owned(), DEFAULT_DIST_SERVER, Box::new(|_| ()), ); - let ref toolchain = ToolchainDesc::from_str("nightly-x86_64-apple-darwin").unwrap(); - let ref prefix = InstallPrefix::from(prefix_tempdir.path().to_owned()); - let ref download_cfg = DownloadCfg { + let toolchain = ToolchainDesc::from_str("nightly-x86_64-apple-darwin").unwrap(); + let prefix = InstallPrefix::from(prefix_tempdir.path().to_owned()); + let download_cfg = DownloadCfg { dist_root: "phony", - temp_cfg: temp_cfg, + temp_cfg: &temp_cfg, download_dir: &prefix.path().to_owned().join("downloads"), notify_handler: &|_| {}, }; - f(url, toolchain, prefix, download_cfg, temp_cfg); + f(url, &toolchain, &prefix, &download_cfg, &temp_cfg); } #[test] @@ -679,7 +679,7 @@ fn update_preserves_extensions() { prefix, download_cfg, temp_cfg| { - let ref adds = vec![ + let adds = vec![ Component::new( "rust-std".to_string(), Some(TargetTriple::from_str("i686-apple-darwin")), @@ -691,7 +691,7 @@ fn update_preserves_extensions() { ]; change_channel_date(url, "nightly", "2016-02-01"); - update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); + update_from_dist(url, toolchain, prefix, &adds, &[], download_cfg, temp_cfg).unwrap(); assert!(utils::path_exists( &prefix.path().join("lib/i686-apple-darwin/libstd.rlib") @@ -742,13 +742,13 @@ fn update_preserves_extensions_that_became_components() { Some(edit), false, &|url, toolchain, prefix, download_cfg, temp_cfg| { - let ref adds = vec![Component::new( + let adds = vec![Component::new( "bonus".to_string(), Some(TargetTriple::from_str("x86_64-apple-darwin")), )]; change_channel_date(url, "nightly", "2016-02-01"); - update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); + update_from_dist(url, toolchain, prefix, &adds, &[], download_cfg, temp_cfg).unwrap(); assert!(utils::path_exists(&prefix.path().join("bin/bonus"))); @@ -822,7 +822,7 @@ fn add_extensions_for_initial_install() { prefix, download_cfg, temp_cfg| { - let ref adds = vec![ + let adds = vec![ Component::new( "rust-std".to_string(), Some(TargetTriple::from_str("i686-apple-darwin")), @@ -833,7 +833,7 @@ fn add_extensions_for_initial_install() { ), ]; - update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); + update_from_dist(url, toolchain, prefix, &adds, &[], download_cfg, temp_cfg).unwrap(); assert!(utils::path_exists( &prefix.path().join("lib/i686-apple-darwin/libstd.rlib") )); @@ -852,7 +852,7 @@ fn add_extensions_for_same_manifest() { temp_cfg| { update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg).unwrap(); - let ref adds = vec![ + let adds = vec![ Component::new( "rust-std".to_string(), Some(TargetTriple::from_str("i686-apple-darwin")), @@ -863,7 +863,7 @@ fn add_extensions_for_same_manifest() { ), ]; - update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); + update_from_dist(url, toolchain, prefix, &adds, &[], download_cfg, temp_cfg).unwrap(); assert!(utils::path_exists( &prefix.path().join("lib/i686-apple-darwin/libstd.rlib") @@ -887,7 +887,7 @@ fn add_extensions_for_upgrade() { change_channel_date(url, "nightly", "2016-02-02"); - let ref adds = vec![ + let adds = vec![ Component::new( "rust-std".to_string(), Some(TargetTriple::from_str("i686-apple-darwin")), @@ -898,7 +898,7 @@ fn add_extensions_for_upgrade() { ), ]; - update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); + update_from_dist(url, toolchain, prefix, &adds, &[], download_cfg, temp_cfg).unwrap(); assert!(utils::path_exists( &prefix.path().join("lib/i686-apple-darwin/libstd.rlib") @@ -917,12 +917,12 @@ fn add_extension_not_in_manifest() { prefix, download_cfg, temp_cfg| { - let ref adds = vec![Component::new( + let adds = vec![Component::new( "rust-bogus".to_string(), Some(TargetTriple::from_str("i686-apple-darwin")), )]; - update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); + update_from_dist(url, toolchain, prefix, &adds, &[], download_cfg, temp_cfg).unwrap(); }); } @@ -934,12 +934,12 @@ fn add_extension_that_is_required_component() { prefix, download_cfg, temp_cfg| { - let ref adds = vec![Component::new( + let adds = vec![Component::new( "rustc".to_string(), Some(TargetTriple::from_str("x86_64-apple-darwin")), )]; - update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); + update_from_dist(url, toolchain, prefix, &adds, &[], download_cfg, temp_cfg).unwrap(); }); } @@ -960,12 +960,12 @@ fn add_extensions_does_not_remove_other_components() { temp_cfg| { update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg).unwrap(); - let ref adds = vec![Component::new( + let adds = vec![Component::new( "rust-std".to_string(), Some(TargetTriple::from_str("i686-apple-darwin")), )]; - update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); + update_from_dist(url, toolchain, prefix, &adds, &[], download_cfg, temp_cfg).unwrap(); assert!(utils::path_exists(&prefix.path().join("bin/rustc"))); }); @@ -980,12 +980,21 @@ fn remove_extensions_for_initial_install() { prefix, download_cfg, temp_cfg| { - let ref removes = vec![Component::new( + let removes = vec![Component::new( "rustc".to_string(), Some(TargetTriple::from_str("x86_64-apple-darwin")), )]; - update_from_dist(url, toolchain, prefix, &[], removes, download_cfg, temp_cfg).unwrap(); + update_from_dist( + url, + toolchain, + prefix, + &[], + &removes, + download_cfg, + temp_cfg, + ) + .unwrap(); }); } @@ -996,7 +1005,7 @@ fn remove_extensions_for_same_manifest() { prefix, download_cfg, temp_cfg| { - let ref adds = vec![ + let adds = vec![ Component::new( "rust-std".to_string(), Some(TargetTriple::from_str("i686-apple-darwin")), @@ -1007,14 +1016,23 @@ fn remove_extensions_for_same_manifest() { ), ]; - update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); + update_from_dist(url, toolchain, prefix, &adds, &[], download_cfg, temp_cfg).unwrap(); - let ref removes = vec![Component::new( + let removes = vec![Component::new( "rust-std".to_string(), Some(TargetTriple::from_str("i686-apple-darwin")), )]; - update_from_dist(url, toolchain, prefix, &[], removes, download_cfg, temp_cfg).unwrap(); + update_from_dist( + url, + toolchain, + prefix, + &[], + &removes, + download_cfg, + temp_cfg, + ) + .unwrap(); assert!(!utils::path_exists( &prefix.path().join("lib/i686-apple-darwin/libstd.rlib") @@ -1034,7 +1052,7 @@ fn remove_extensions_for_upgrade() { temp_cfg| { change_channel_date(url, "nightly", "2016-02-01"); - let ref adds = vec![ + let adds = vec![ Component::new( "rust-std".to_string(), Some(TargetTriple::from_str("i686-apple-darwin")), @@ -1045,16 +1063,25 @@ fn remove_extensions_for_upgrade() { ), ]; - update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); + update_from_dist(url, toolchain, prefix, &adds, &[], download_cfg, temp_cfg).unwrap(); change_channel_date(url, "nightly", "2016-02-02"); - let ref removes = vec![Component::new( + let removes = vec![Component::new( "rust-std".to_string(), Some(TargetTriple::from_str("i686-apple-darwin")), )]; - update_from_dist(url, toolchain, prefix, &[], removes, download_cfg, temp_cfg).unwrap(); + update_from_dist( + url, + toolchain, + prefix, + &[], + &removes, + download_cfg, + temp_cfg, + ) + .unwrap(); assert!(!utils::path_exists( &prefix.path().join("lib/i686-apple-darwin/libstd.rlib") @@ -1079,12 +1106,21 @@ fn remove_extension_not_in_manifest() { change_channel_date(url, "nightly", "2016-02-02"); - let ref removes = vec![Component::new( + let removes = vec![Component::new( "rust-bogus".to_string(), Some(TargetTriple::from_str("i686-apple-darwin")), )]; - update_from_dist(url, toolchain, prefix, &[], removes, download_cfg, temp_cfg).unwrap(); + update_from_dist( + url, + toolchain, + prefix, + &[], + &removes, + download_cfg, + temp_cfg, + ) + .unwrap(); }); } @@ -1113,20 +1149,29 @@ fn remove_extension_not_in_manifest_but_is_already_installed() { &|url, toolchain, prefix, download_cfg, temp_cfg| { change_channel_date(url, "nightly", "2016-02-01"); - let ref adds = vec![Component::new( + let adds = vec![Component::new( "bonus".to_string(), Some(TargetTriple::from_str("x86_64-apple-darwin")), )]; - update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); + update_from_dist(url, toolchain, prefix, &adds, &[], download_cfg, temp_cfg).unwrap(); assert!(utils::path_exists(&prefix.path().join("bin/bonus"))); change_channel_date(url, "nightly", "2016-02-02"); - let ref removes = vec![Component::new( + let removes = vec![Component::new( "bonus".to_string(), Some(TargetTriple::from_str("x86_64-apple-darwin")), )]; - update_from_dist(url, toolchain, prefix, &[], removes, download_cfg, temp_cfg).unwrap(); + update_from_dist( + url, + toolchain, + prefix, + &[], + &removes, + download_cfg, + temp_cfg, + ) + .unwrap(); }, ); } @@ -1141,12 +1186,21 @@ fn remove_extension_that_is_required_component() { temp_cfg| { update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg).unwrap(); - let ref removes = vec![Component::new( + let removes = vec![Component::new( "rustc".to_string(), Some(TargetTriple::from_str("x86_64-apple-darwin")), )]; - update_from_dist(url, toolchain, prefix, &[], removes, download_cfg, temp_cfg).unwrap(); + update_from_dist( + url, + toolchain, + prefix, + &[], + &removes, + download_cfg, + temp_cfg, + ) + .unwrap(); }); } @@ -1160,12 +1214,21 @@ fn remove_extension_not_installed() { temp_cfg| { update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg).unwrap(); - let ref removes = vec![Component::new( + let removes = vec![Component::new( "rust-std".to_string(), Some(TargetTriple::from_str("i686-apple-darwin")), )]; - update_from_dist(url, toolchain, prefix, &[], removes, download_cfg, temp_cfg).unwrap(); + update_from_dist( + url, + toolchain, + prefix, + &[], + &removes, + download_cfg, + temp_cfg, + ) + .unwrap(); }); } @@ -1180,19 +1243,28 @@ fn remove_extensions_does_not_remove_other_components() { prefix, download_cfg, temp_cfg| { - let ref adds = vec![Component::new( + let adds = vec![Component::new( "rust-std".to_string(), Some(TargetTriple::from_str("i686-apple-darwin")), )]; - update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); + update_from_dist(url, toolchain, prefix, &adds, &[], download_cfg, temp_cfg).unwrap(); - let ref removes = vec![Component::new( + let removes = vec![Component::new( "rust-std".to_string(), Some(TargetTriple::from_str("i686-apple-darwin")), )]; - update_from_dist(url, toolchain, prefix, &[], removes, download_cfg, temp_cfg).unwrap(); + update_from_dist( + url, + toolchain, + prefix, + &[], + &removes, + download_cfg, + temp_cfg, + ) + .unwrap(); assert!(utils::path_exists(&prefix.path().join("bin/rustc"))); }); @@ -1207,21 +1279,21 @@ fn add_and_remove_for_upgrade() { temp_cfg| { change_channel_date(url, "nightly", "2016-02-01"); - let ref adds = vec![Component::new( + let adds = vec![Component::new( "rust-std".to_string(), Some(TargetTriple::from_str("i686-unknown-linux-gnu")), )]; - update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); + update_from_dist(url, toolchain, prefix, &adds, &[], download_cfg, temp_cfg).unwrap(); change_channel_date(url, "nightly", "2016-02-02"); - let ref adds = vec![Component::new( + let adds = vec![Component::new( "rust-std".to_string(), Some(TargetTriple::from_str("i686-apple-darwin")), )]; - let ref removes = vec![Component::new( + let removes = vec![Component::new( "rust-std".to_string(), Some(TargetTriple::from_str("i686-unknown-linux-gnu")), )]; @@ -1230,8 +1302,8 @@ fn add_and_remove_for_upgrade() { url, toolchain, prefix, - adds, - removes, + &adds, + &removes, download_cfg, temp_cfg, ) @@ -1253,19 +1325,19 @@ fn add_and_remove() { prefix, download_cfg, temp_cfg| { - let ref adds = vec![Component::new( + let adds = vec![Component::new( "rust-std".to_string(), Some(TargetTriple::from_str("i686-unknown-linux-gnu")), )]; - update_from_dist(url, toolchain, prefix, adds, &[], download_cfg, temp_cfg).unwrap(); + update_from_dist(url, toolchain, prefix, &adds, &[], download_cfg, temp_cfg).unwrap(); - let ref adds = vec![Component::new( + let adds = vec![Component::new( "rust-std".to_string(), Some(TargetTriple::from_str("i686-apple-darwin")), )]; - let ref removes = vec![Component::new( + let removes = vec![Component::new( "rust-std".to_string(), Some(TargetTriple::from_str("i686-unknown-linux-gnu")), )]; @@ -1274,8 +1346,8 @@ fn add_and_remove() { url, toolchain, prefix, - adds, - removes, + &adds, + &removes, download_cfg, temp_cfg, ) @@ -1300,12 +1372,12 @@ fn add_and_remove_same_component() { temp_cfg| { update_from_dist(url, toolchain, prefix, &[], &[], download_cfg, temp_cfg).unwrap(); - let ref adds = vec![Component::new( + let adds = vec![Component::new( "rust-std".to_string(), Some(TargetTriple::from_str("i686-apple-darwin")), )]; - let ref removes = vec![Component::new( + let removes = vec![Component::new( "rust-std".to_string(), Some(TargetTriple::from_str("i686-apple_darwin")), )]; @@ -1314,8 +1386,8 @@ fn add_and_remove_same_component() { url, toolchain, prefix, - adds, - removes, + &adds, + &removes, download_cfg, temp_cfg, ) diff --git a/tests/dist_manifest.rs b/tests/dist_manifest.rs index d0b81c921e..0066e6d266 100644 --- a/tests/dist_manifest.rs +++ b/tests/dist_manifest.rs @@ -30,11 +30,11 @@ fn parse_smoke_test() { assert_eq!(rust_target_pkg.bins.clone().unwrap().url, "example.com"); assert_eq!(rust_target_pkg.bins.clone().unwrap().hash, "..."); - let ref component = rust_target_pkg.components[0]; + let component = &rust_target_pkg.components[0]; assert_eq!(component.short_name_in_manifest(), "rustc"); assert_eq!(component.target.as_ref(), Some(&x86_64_unknown_linux_gnu)); - let ref component = rust_target_pkg.extensions[0]; + let component = &rust_target_pkg.extensions[0]; assert_eq!(component.short_name_in_manifest(), "rust-std"); assert_eq!(component.target.as_ref(), Some(&x86_64_unknown_linux_musl)); diff --git a/tests/dist_transactions.rs b/tests/dist_transactions.rs index 6a3bc625a6..fb21029739 100644 --- a/tests/dist_transactions.rs +++ b/tests/dist_transactions.rs @@ -561,12 +561,12 @@ fn modify_file_that_exists() { let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); - let ref path = prefix.path().join("foo"); - utils_raw::write_file(path, "wow").unwrap(); + let path = prefix.path().join("foo"); + utils_raw::write_file(&path, "wow").unwrap(); tx.modify_file(PathBuf::from("foo")).unwrap(); tx.commit(); - assert_eq!(utils_raw::read_file(path).unwrap(), "wow"); + assert_eq!(utils_raw::read_file(&path).unwrap(), "wow"); } #[test] @@ -607,13 +607,13 @@ fn modify_file_that_exists_then_rollback() { let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); - let ref path = prefix.path().join("foo"); - utils_raw::write_file(path, "wow").unwrap(); + let path = prefix.path().join("foo"); + utils_raw::write_file(&path, "wow").unwrap(); tx.modify_file(PathBuf::from("foo")).unwrap(); - utils_raw::write_file(path, "eww").unwrap(); + utils_raw::write_file(&path, "eww").unwrap(); drop(tx); - assert_eq!(utils_raw::read_file(path).unwrap(), "wow"); + assert_eq!(utils_raw::read_file(&path).unwrap(), "wow"); } // This is testing that the backup scheme is smart enough not @@ -634,15 +634,15 @@ fn modify_twice_then_rollback() { let notify = |_: Notification<'_>| (); let mut tx = Transaction::new(prefix.clone(), &tmpcfg, ¬ify); - let ref path = prefix.path().join("foo"); - utils_raw::write_file(path, "wow").unwrap(); + let path = prefix.path().join("foo"); + utils_raw::write_file(&path, "wow").unwrap(); tx.modify_file(PathBuf::from("foo")).unwrap(); - utils_raw::write_file(path, "eww").unwrap(); + utils_raw::write_file(&path, "eww").unwrap(); tx.modify_file(PathBuf::from("foo")).unwrap(); - utils_raw::write_file(path, "ewww").unwrap(); + utils_raw::write_file(&path, "ewww").unwrap(); drop(tx); - assert_eq!(utils_raw::read_file(path).unwrap(), "wow"); + assert_eq!(utils_raw::read_file(&path).unwrap(), "wow"); } fn do_multiple_op_transaction(rollback: bool) { @@ -675,40 +675,40 @@ fn do_multiple_op_transaction(rollback: bool) { // remove_dir let relpath8 = PathBuf::from("olddoc/htm/index.html"); - let ref path1 = prefix.path().join(&relpath1); - let ref path2 = prefix.path().join(&relpath2); - let ref path4 = prefix.path().join(&relpath4); - let ref path5 = prefix.path().join(&relpath5); - let ref path6 = prefix.path().join(&relpath6); - let ref path7 = prefix.path().join(&relpath7); - let ref path8 = prefix.path().join(&relpath8); + let path1 = prefix.path().join(&relpath1); + let path2 = prefix.path().join(&relpath2); + let path4 = prefix.path().join(&relpath4); + let path5 = prefix.path().join(&relpath5); + let path6 = prefix.path().join(&relpath6); + let path7 = prefix.path().join(&relpath7); + let path8 = prefix.path().join(&relpath8); - let ref srcpath1 = srcdir.path().join(&relpath1); + let srcpath1 = srcdir.path().join(&relpath1); fs::create_dir_all(srcpath1.parent().unwrap()).unwrap(); - utils_raw::write_file(srcpath1, "").unwrap(); - tx.copy_file("", relpath1, srcpath1).unwrap(); + utils_raw::write_file(&srcpath1, "").unwrap(); + tx.copy_file("", relpath1, &srcpath1).unwrap(); - let ref srcpath2 = srcdir.path().join(&relpath2); - utils_raw::write_file(srcpath2, "").unwrap(); - tx.copy_file("", relpath2, srcpath2).unwrap(); + let srcpath2 = srcdir.path().join(&relpath2); + utils_raw::write_file(&srcpath2, "").unwrap(); + tx.copy_file("", relpath2, &srcpath2).unwrap(); - let ref srcpath4 = srcdir.path().join(&relpath4); + let srcpath4 = srcdir.path().join(&relpath4); fs::create_dir_all(srcpath4.parent().unwrap()).unwrap(); - utils_raw::write_file(srcpath4, "").unwrap(); + utils_raw::write_file(&srcpath4, "").unwrap(); tx.copy_dir("", PathBuf::from("doc"), &srcdir.path().join("doc")) .unwrap(); tx.modify_file(relpath5).unwrap(); - utils_raw::write_file(path5, "").unwrap(); + utils_raw::write_file(&path5, "").unwrap(); tx.write_file("", relpath6, "".to_string()).unwrap(); fs::create_dir_all(path7.parent().unwrap()).unwrap(); - utils_raw::write_file(path7, "").unwrap(); + utils_raw::write_file(&path7, "").unwrap(); tx.remove_file("", relpath7).unwrap(); fs::create_dir_all(path8.parent().unwrap()).unwrap(); - utils_raw::write_file(path8, "").unwrap(); + utils_raw::write_file(&path8, "").unwrap(); tx.remove_dir("", PathBuf::from("olddoc")).unwrap(); if !rollback { diff --git a/tests/mock/clitools.rs b/tests/mock/clitools.rs index 21db0f4a83..8d791e54ec 100644 --- a/tests/mock/clitools.rs +++ b/tests/mock/clitools.rs @@ -106,19 +106,19 @@ pub fn setup(s: Scenario, f: &dyn Fn(&mut Config)) { create_mock_dist_server(&config.distdir, s); - let ref build_path = exe_dir.join(format!("rustup-init{}", EXE_SUFFIX)); + let build_path = exe_dir.join(format!("rustup-init{}", EXE_SUFFIX)); - let ref rustup_path = config.exedir.join(format!("rustup{}", EXE_SUFFIX)); + let rustup_path = config.exedir.join(format!("rustup{}", EXE_SUFFIX)); let setup_path = config.exedir.join(format!("rustup-init{}", EXE_SUFFIX)); let rustc_path = config.exedir.join(format!("rustc{}", EXE_SUFFIX)); let cargo_path = config.exedir.join(format!("cargo{}", EXE_SUFFIX)); let rls_path = config.exedir.join(format!("rls{}", EXE_SUFFIX)); hard_link(&build_path, &rustup_path).unwrap(); - hard_link(rustup_path, setup_path).unwrap(); - hard_link(rustup_path, rustc_path).unwrap(); - hard_link(rustup_path, cargo_path).unwrap(); - hard_link(rustup_path, rls_path).unwrap(); + hard_link(&rustup_path, setup_path).unwrap(); + hard_link(&rustup_path, rustc_path).unwrap(); + hard_link(&rustup_path, cargo_path).unwrap(); + hard_link(&rustup_path, rls_path).unwrap(); // Make sure the host triple matches the build triple. Otherwise testing a 32-bit build of // rustup on a 64-bit machine will fail, because the tests do not have the host detection @@ -163,9 +163,9 @@ impl Config { /// Change the current distribution manifest to a particular date pub fn set_current_dist_date(config: &Config, date: &str) { - let ref url = Url::from_file_path(&config.distdir).unwrap(); + let url = Url::from_file_path(&config.distdir).unwrap(); for channel in &["nightly", "beta", "stable"] { - change_channel_date(url, channel, date); + change_channel_date(&url, channel, date); } } @@ -394,7 +394,7 @@ fn create_mock_dist_server(path: &Path, s: Scenario) { let c6 = build_mock_channel(s, "stable", "2015-01-02", "1.1.0", "hash-s-2", false); chans.extend(vec![c4, c5, c6]); - let ref vs = match s { + let vs = match s { Scenario::Full => vec![ManifestVersion::V1, ManifestVersion::V2], Scenario::SimpleV1 | Scenario::ArchivesV1 => vec![ManifestVersion::V1], Scenario::SimpleV2 | Scenario::ArchivesV2 | Scenario::MultiHost | Scenario::Unavailable => { @@ -406,7 +406,7 @@ fn create_mock_dist_server(path: &Path, s: Scenario) { path: path.to_owned(), channels: chans, } - .write(vs, true); + .write(&vs, true); // Also create the manifests for stable releases by version if dates_count > 1 { @@ -475,16 +475,16 @@ fn build_mock_channel( rename_rls: bool, ) -> MockChannel { // Build the mock installers - let ref host_triple = this_host_triple(); - let std = build_mock_std_installer(host_triple); - let rustc = build_mock_rustc_installer(host_triple, version, version_hash); + let host_triple = this_host_triple(); + let std = build_mock_std_installer(&host_triple); + let rustc = build_mock_rustc_installer(&host_triple, version, version_hash); let cargo = build_mock_cargo_installer(version, version_hash); let rust_docs = build_mock_rust_doc_installer(); let rust = build_combined_installer(&[&std, &rustc, &cargo, &rust_docs]); let cross_std1 = build_mock_cross_std_installer(CROSS_ARCH1, date); let cross_std2 = build_mock_cross_std_installer(CROSS_ARCH2, date); let rust_src = build_mock_rust_src_installer(); - let rust_analysis = build_mock_rust_analysis_installer(host_triple); + let rust_analysis = build_mock_rust_analysis_installer(&host_triple); // Convert the mock installers to mock package definitions for the // mock dist server @@ -582,7 +582,7 @@ fn build_mock_channel( { let rust_pkg = packages.last_mut().unwrap(); for target_pkg in rust_pkg.targets.iter_mut() { - let ref target = target_pkg.target; + let target = &target_pkg.target; target_pkg.components.push(MockComponent { name: "rust-std".to_string(), target: target.to_string(), @@ -643,7 +643,7 @@ fn build_mock_channel( } fn build_mock_unavailable_channel(channel: &str, date: &str, version: &'static str) -> MockChannel { - let ref host_triple = this_host_triple(); + let host_triple = this_host_triple(); let packages = [ "cargo", @@ -836,13 +836,13 @@ fn mock_bin(name: &str, version: &str, version_hash: &str) -> Vec { lazy_static! { static ref MOCK_BIN: Arc> = { // Create a temp directory to hold the source and the output - let ref tempdir = TempDir::new("rustup").unwrap(); - let ref source_path = tempdir.path().join("in.rs"); - let ref dest_path = tempdir.path().join(&format!("out{}", EXE_SUFFIX)); + let tempdir = TempDir::new("rustup").unwrap(); + let source_path = tempdir.path().join("in.rs"); + let dest_path = tempdir.path().join(&format!("out{}", EXE_SUFFIX)); // Write the source let source = include_str!("mock_bin_src.rs"); - File::create(source_path).and_then(|mut f| f.write_all(source.as_bytes())).unwrap(); + File::create(&source_path).and_then(|mut f| f.write_all(source.as_bytes())).unwrap(); // Create the executable let status = Command::new("rustc") @@ -880,13 +880,13 @@ fn mock_bin(name: &str, version: &str, version_hash: &str) -> Vec { // These are toolchains for installation with --link-local and --copy-local fn create_custom_toolchains(customdir: &Path) { - let ref libdir = customdir.join("custom-1/lib"); + let libdir = customdir.join("custom-1/lib"); fs::create_dir_all(libdir).unwrap(); for file in mock_bin("rustc", "1.0.0", "hash-c-1") { file.build(&customdir.join("custom-1")); } - let ref libdir = customdir.join("custom-2/lib"); + let libdir = customdir.join("custom-2/lib"); fs::create_dir_all(libdir).unwrap(); for file in mock_bin("rustc", "1.0.0", "hash-c-2") { file.build(&customdir.join("custom-2")); diff --git a/tests/mock/dist.rs b/tests/mock/dist.rs index d9edf5f735..90e5f52d7a 100644 --- a/tests/mock/dist.rs +++ b/tests/mock/dist.rs @@ -22,34 +22,34 @@ pub fn change_channel_date(dist_server: &Url, channel: &str, date: &str) { // V2 let manifest_name = format!("dist/channel-rust-{}", channel); - let ref manifest_path = path.join(format!("{}.toml", manifest_name)); - let ref hash_path = path.join(format!("{}.toml.sha256", manifest_name)); + let manifest_path = path.join(format!("{}.toml", manifest_name)); + let hash_path = path.join(format!("{}.toml.sha256", manifest_name)); let archive_manifest_name = format!("dist/{}/channel-rust-{}", date, channel); - let ref archive_manifest_path = path.join(format!("{}.toml", archive_manifest_name)); - let ref archive_hash_path = path.join(format!("{}.toml.sha256", archive_manifest_name)); + let archive_manifest_path = path.join(format!("{}.toml", archive_manifest_name)); + let archive_hash_path = path.join(format!("{}.toml.sha256", archive_manifest_name)); let _ = hard_link(archive_manifest_path, manifest_path); let _ = hard_link(archive_hash_path, hash_path); // V1 let manifest_name = format!("dist/channel-rust-{}", channel); - let ref manifest_path = path.join(format!("{}", manifest_name)); - let ref hash_path = path.join(format!("{}.sha256", manifest_name)); + let manifest_path = path.join(format!("{}", manifest_name)); + let hash_path = path.join(format!("{}.sha256", manifest_name)); let archive_manifest_name = format!("dist/{}/channel-rust-{}", date, channel); - let ref archive_manifest_path = path.join(format!("{}", archive_manifest_name)); - let ref archive_hash_path = path.join(format!("{}.sha256", archive_manifest_name)); + let archive_manifest_path = path.join(format!("{}", archive_manifest_name)); + let archive_hash_path = path.join(format!("{}.sha256", archive_manifest_name)); let _ = hard_link(archive_manifest_path, manifest_path); let _ = hard_link(archive_hash_path, hash_path); // Copy all files that look like rust-* for the v1 installers - let ref archive_path = path.join(format!("dist/{}", date)); + let archive_path = path.join(format!("dist/{}", date)); for dir in fs::read_dir(archive_path).unwrap() { let dir = dir.unwrap(); if dir.file_name().to_str().unwrap().contains("rust-") { - let ref path = path.join(format!("dist/{}", dir.file_name().to_str().unwrap())); + let path = path.join(format!("dist/{}", dir.file_name().to_str().unwrap())); hard_link(&dir.path(), path).unwrap(); } } @@ -121,7 +121,7 @@ impl MockDistServer { fs::create_dir_all(&self.path).unwrap(); for channel in self.channels.iter() { - let ref mut hashes = HashMap::new(); + let mut hashes = HashMap::new(); for package in &channel.packages { let new_hashes = self.build_package(&channel, &package, enable_xz); hashes.extend(new_hashes.into_iter()); @@ -129,7 +129,7 @@ impl MockDistServer { for v in vs { match *v { ManifestVersion::V1 => self.write_manifest_v1(&channel), - ManifestVersion::V2 => self.write_manifest_v2(&channel, hashes), + ManifestVersion::V2 => self.write_manifest_v2(&channel, &hashes), } } } @@ -175,15 +175,15 @@ impl MockDistServer { format: &str, ) -> String { // This is where the tarball, sums and sigs will go - let ref dist_dir = self.path.join("dist"); - let ref archive_dir = dist_dir.join(&channel.date); + let dist_dir = self.path.join("dist"); + let archive_dir = dist_dir.join(&channel.date); - fs::create_dir_all(archive_dir).unwrap(); + fs::create_dir_all(&archive_dir).unwrap(); let tmpdir = TempDir::new("rustup").unwrap(); let workdir = tmpdir.path().join("work"); - let ref installer_name = if target_package.target != "*" { + let installer_name = if target_package.target != "*" { format!( "{}-{}-{}", package.name, channel.name, target_package.target @@ -191,11 +191,11 @@ impl MockDistServer { } else { format!("{}-{}", package.name, channel.name) }; - let ref installer_dir = workdir.join(installer_name); - let ref installer_tarball = archive_dir.join(format!("{}{}", installer_name, format)); - let ref installer_hash = archive_dir.join(format!("{}{}.sha256", installer_name, format)); + let installer_dir = workdir.join(&installer_name); + let installer_tarball = archive_dir.join(format!("{}{}", installer_name, format)); + let installer_hash = archive_dir.join(format!("{}{}.sha256", installer_name, format)); - fs::create_dir_all(installer_dir).unwrap(); + fs::create_dir_all(&installer_dir).unwrap(); // Tarball creation can be super slow, so cache created tarballs // globally to avoid recreating and recompressing tons of tarballs. @@ -223,18 +223,18 @@ impl MockDistServer { hash.clone() } else { drop(tarballs); - target_package.installer.build(installer_dir); + target_package.installer.build(&installer_dir); create_tarball( - &PathBuf::from(installer_name), - installer_dir, - installer_tarball, + &PathBuf::from(&installer_name), + &installer_dir, + &installer_tarball, ); let mut contents = Vec::new(); - File::open(installer_tarball) + File::open(&installer_tarball) .unwrap() .read_to_end(&mut contents) .unwrap(); - let hash = create_hash(installer_tarball, installer_hash); + let hash = create_hash(&installer_tarball, &installer_hash); TARBALLS .lock() .unwrap() @@ -244,9 +244,8 @@ impl MockDistServer { // Copy from the archive to the main dist directory if package.name == "rust" { - let ref main_installer_tarball = dist_dir.join(format!("{}{}", installer_name, format)); - let ref main_installer_hash = - dist_dir.join(format!("{}{}.sha256", installer_name, format)); + let main_installer_tarball = dist_dir.join(format!("{}{}", installer_name, format)); + let main_installer_hash = dist_dir.join(format!("{}{}.sha256", installer_name, format)); hard_link(installer_tarball, main_installer_tarball).unwrap(); hard_link(installer_hash, main_installer_hash).unwrap(); } @@ -268,19 +267,19 @@ impl MockDistServer { } let manifest_name = format!("dist/channel-rust-{}", channel.name); - let ref manifest_path = self.path.join(format!("{}", manifest_name)); - write_file(manifest_path, &buf); + let manifest_path = self.path.join(format!("{}", manifest_name)); + write_file(&manifest_path, &buf); - let ref hash_path = self.path.join(format!("{}.sha256", manifest_name)); - create_hash(manifest_path, hash_path); + let hash_path = self.path.join(format!("{}.sha256", manifest_name)); + create_hash(&manifest_path, &hash_path); // Also copy the manifest and hash into the archive folder let archive_manifest_name = format!("dist/{}/channel-rust-{}", channel.date, channel.name); - let ref archive_manifest_path = self.path.join(format!("{}", archive_manifest_name)); + let archive_manifest_path = self.path.join(format!("{}", archive_manifest_name)); hard_link(manifest_path, archive_manifest_path).unwrap(); - let ref archive_hash_path = self.path.join(format!("{}.sha256", archive_manifest_name)); - hard_link(hash_path, archive_hash_path).unwrap(); + let archive_hash_path = self.path.join(format!("{}.sha256", archive_manifest_name)); + hard_link(&hash_path, archive_hash_path).unwrap(); } fn write_manifest_v2( @@ -330,11 +329,11 @@ impl MockDistServer { let url = format!("file://{}", path.to_string_lossy()); toml_target.insert(String::from("url"), toml::Value::String(url.clone())); - let ref component = MockComponent { + let component = MockComponent { name: package.name.to_owned(), target: target.target.to_owned(), }; - let hash = hashes[component].clone(); + let hash = hashes[&component].clone(); toml_target.insert(String::from("hash"), toml::Value::String(hash.gz)); if let Some(xz_hash) = hash.xz { @@ -400,18 +399,18 @@ impl MockDistServer { toml_manifest.insert(String::from("renames"), toml::Value::Table(toml_renames)); let manifest_name = format!("dist/channel-rust-{}", channel.name); - let ref manifest_path = self.path.join(format!("{}.toml", manifest_name)); - write_file(manifest_path, &toml::to_string(&toml_manifest).unwrap()); + let manifest_path = self.path.join(format!("{}.toml", manifest_name)); + write_file(&manifest_path, &toml::to_string(&toml_manifest).unwrap()); - let ref hash_path = self.path.join(format!("{}.toml.sha256", manifest_name)); - create_hash(manifest_path, hash_path); + let hash_path = self.path.join(format!("{}.toml.sha256", manifest_name)); + create_hash(&manifest_path, &hash_path); // Also copy the manifest and hash into the archive folder let archive_manifest_name = format!("dist/{}/channel-rust-{}", channel.date, channel.name); - let ref archive_manifest_path = self.path.join(format!("{}.toml", archive_manifest_name)); - hard_link(manifest_path, archive_manifest_path).unwrap(); + let archive_manifest_path = self.path.join(format!("{}.toml", archive_manifest_name)); + hard_link(&manifest_path, archive_manifest_path).unwrap(); - let ref archive_hash_path = self + let archive_hash_path = self .path .join(format!("{}.toml.sha256", archive_manifest_name)); hard_link(hash_path, archive_hash_path).unwrap(); @@ -445,8 +444,8 @@ fn create_tarball(relpath: &Path, src: &Path, dst: &Path) { relpath = relpath.join(part); } if entry.file_type().is_file() { - let ref mut srcfile = File::open(entry.path()).unwrap(); - tar.append_file(relpath, srcfile).unwrap(); + let mut srcfile = File::open(entry.path()).unwrap(); + tar.append_file(relpath, &mut srcfile).unwrap(); } else if entry.file_type().is_dir() { tar.append_dir(relpath, entry.path()).unwrap(); } @@ -455,8 +454,8 @@ fn create_tarball(relpath: &Path, src: &Path, dst: &Path) { } pub fn calc_hash(src: &Path) -> String { - let ref mut buf = Vec::new(); - File::open(src).unwrap().read_to_end(buf).unwrap(); + let mut buf = Vec::new(); + File::open(src).unwrap().read_to_end(&mut buf).unwrap(); let mut hasher = Sha256::new(); hasher.input(buf); format!("{:x}", hasher.result()) @@ -465,8 +464,8 @@ pub fn calc_hash(src: &Path) -> String { pub fn create_hash(src: &Path, dst: &Path) -> String { let hex = calc_hash(src); let src_file = src.file_name().unwrap(); - let ref file_contents = format!("{} *{}\n", hex, src_file.to_string_lossy()); - write_file(dst, file_contents); + let file_contents = format!("{} *{}\n", hex, src_file.to_string_lossy()); + write_file(dst, &file_contents); hex } diff --git a/tests/mock/mod.rs b/tests/mock/mod.rs index 121141b661..9e639d1c01 100644 --- a/tests/mock/mod.rs +++ b/tests/mock/mod.rs @@ -43,7 +43,7 @@ impl MockInstallerBuilder { for component in &self.components { // Update the components file let comp_file = path.join("components"); - let ref mut comp_file = OpenOptions::new() + let mut comp_file = OpenOptions::new() .write(true) .append(true) .create(true) @@ -58,7 +58,7 @@ impl MockInstallerBuilder { } // Create the component files and manifest - let ref mut manifest = File::create(component_dir.join("manifest.in")).unwrap(); + let mut manifest = File::create(component_dir.join("manifest.in")).unwrap(); for file in component.files.iter() { match file.contents { Contents::Dir(_) => { From b6f8f34c6c044610cc93be4709ab26275719dec2 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 19 Apr 2019 15:43:15 +0700 Subject: [PATCH 05/17] clippy: Fix redundant_closure --- src/config.rs | 4 ++-- src/dist/component/package.rs | 5 ++++- src/dist/manifestation.rs | 2 +- tests/cli-inst-interactive.rs | 2 +- tests/cli-self-upd.rs | 2 +- tests/mock/dist.rs | 6 +++++- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/config.rs b/src/config.rs index 648792affc..1800152e43 100644 --- a/src/config.rs +++ b/src/config.rs @@ -377,8 +377,8 @@ impl Cfg { let toolchains = toolchains.map(|n| (n.clone(), self.get_toolchain(&n, true))); // Filter out toolchains that don't track a release channel - let toolchains = - toolchains.filter(|&(_, ref t)| t.as_ref().map(|t| t.is_tracking()).unwrap_or(false)); + let toolchains = toolchains + .filter(|&(_, ref t)| t.as_ref().map(Toolchain::is_tracking).unwrap_or(false)); // Update toolchains and collect the results let toolchains = toolchains.map(|(n, t)| { diff --git a/src/dist/component/package.rs b/src/dist/component/package.rs index 930604b9f7..e0fdea28ce 100644 --- a/src/dist/component/package.rs +++ b/src/dist/component/package.rs @@ -43,7 +43,10 @@ impl DirectoryPackage { validate_installer_version(&path)?; let content = utils::read_file("package components", &path.join("components"))?; - let components = content.lines().map(|l| l.to_owned()).collect(); + let components = content + .lines() + .map(std::borrow::ToOwned::to_owned) + .collect(); Ok(DirectoryPackage { path, components, diff --git a/src/dist/manifestation.rs b/src/dist/manifestation.rs index a875af5548..3c01b3277d 100644 --- a/src/dist/manifestation.rs +++ b/src/dist/manifestation.rs @@ -631,7 +631,7 @@ impl Update { new_manifest.get_package(&c.short_name_in_manifest()).ok(); let target_pkg: Option<&TargetedPackage> = pkg.and_then(|p| p.get_target(c.target.as_ref()).ok()); - target_pkg.map(|tp| tp.available()) != Some(true) + target_pkg.map(TargetedPackage::available) != Some(true) }) .cloned() .collect(); diff --git a/tests/cli-inst-interactive.rs b/tests/cli-inst-interactive.rs index 084ebfad89..3ea6a3ede0 100644 --- a/tests/cli-inst-interactive.rs +++ b/tests/cli-inst-interactive.rs @@ -20,7 +20,7 @@ pub fn setup(f: &dyn Fn(&Config)) { // An windows these tests mess with the user's PATH. Save // and restore them here to keep from trashing things. let saved_path = get_path(); - let _g = scopeguard::guard(saved_path, |p| restore_path(p)); + let _g = scopeguard::guard(saved_path, restore_path); f(config); }); diff --git a/tests/cli-self-upd.rs b/tests/cli-self-upd.rs index 7d4301b811..aff7af68c1 100644 --- a/tests/cli-self-upd.rs +++ b/tests/cli-self-upd.rs @@ -38,7 +38,7 @@ pub fn setup(f: &dyn Fn(&Config)) { // On windows these tests mess with the user's PATH. Save // and restore them here to keep from trashing things. let saved_path = get_path(); - let _g = scopeguard::guard(saved_path, |p| restore_path(p)); + let _g = scopeguard::guard(saved_path, restore_path); f(config); }); diff --git a/tests/mock/dist.rs b/tests/mock/dist.rs index 90e5f52d7a..70c21cbcc6 100644 --- a/tests/mock/dist.rs +++ b/tests/mock/dist.rs @@ -436,7 +436,11 @@ fn create_tarball(relpath: &Path, src: &Path, dst: &Path) { let mut tar = tar::Builder::new(writer); for entry in walkdir::WalkDir::new(src) { let entry = entry.unwrap(); - let parts: Vec<_> = entry.path().iter().map(|p| p.to_owned()).collect(); + let parts: Vec<_> = entry + .path() + .iter() + .map(std::borrow::ToOwned::to_owned) + .collect(); let parts_len = parts.len(); let parts = parts.into_iter().skip(parts_len - entry.depth()); let mut relpath = relpath.to_owned(); From 914128f372abf777a6b3c116580725409d31cefd Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 19 Apr 2019 16:25:52 +0700 Subject: [PATCH 06/17] clippy: Fix print_literal --- tests/mock/clitools.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/mock/clitools.rs b/tests/mock/clitools.rs index 8d791e54ec..10d0f88625 100644 --- a/tests/mock/clitools.rs +++ b/tests/mock/clitools.rs @@ -173,7 +173,7 @@ pub fn expect_ok(config: &Config, args: &[&str]) { let out = run(config, args[0], &args[1..], &[]); if !out.ok { print_command(args, &out); - println!("expected.ok: {}", true); + println!("expected.ok: true"); panic!(); } } @@ -182,7 +182,7 @@ pub fn expect_err(config: &Config, args: &[&str], expected: &str) { let out = run(config, args[0], &args[1..], &[]); if out.ok || !out.stderr.contains(expected) { print_command(args, &out); - println!("expected.ok: {}", false); + println!("expected.ok: false"); print_indented("expected.stderr.contains", expected); panic!(); } @@ -192,7 +192,7 @@ pub fn expect_stdout_ok(config: &Config, args: &[&str], expected: &str) { let out = run(config, args[0], &args[1..], &[]); if !out.ok || !out.stdout.contains(expected) { print_command(args, &out); - println!("expected.ok: {}", true); + println!("expected.ok: true"); print_indented("expected.stdout.contains", expected); panic!(); } @@ -202,7 +202,7 @@ pub fn expect_not_stdout_ok(config: &Config, args: &[&str], expected: &str) { let out = run(config, args[0], &args[1..], &[]); if !out.ok || out.stdout.contains(expected) { print_command(args, &out); - println!("expected.ok: {}", true); + println!("expected.ok: true"); print_indented("expected.stdout.does_not_contain", expected); panic!(); } @@ -212,7 +212,7 @@ pub fn expect_stderr_ok(config: &Config, args: &[&str], expected: &str) { let out = run(config, args[0], &args[1..], &[]); if !out.ok || !out.stderr.contains(expected) { print_command(args, &out); - println!("expected.ok: {}", true); + println!("expected.ok: true"); print_indented("expected.stderr.contains", expected); panic!(); } @@ -222,7 +222,7 @@ pub fn expect_ok_ex(config: &Config, args: &[&str], stdout: &str, stderr: &str) let out = run(config, args[0], &args[1..], &[]); if !out.ok || out.stdout != stdout || out.stderr != stderr { print_command(args, &out); - println!("expected.ok: {}", true); + println!("expected.ok: true"); print_indented("expected.stdout", stdout); print_indented("expected.stderr", stderr); dbg!(out.stdout == stdout); @@ -235,7 +235,7 @@ pub fn expect_err_ex(config: &Config, args: &[&str], stdout: &str, stderr: &str) let out = run(config, args[0], &args[1..], &[]); if out.ok || out.stdout != stdout || out.stderr != stderr { print_command(args, &out); - println!("expected.ok: {}", false); + println!("expected.ok: false"); print_indented("expected.stdout", stdout); print_indented("expected.stderr", stderr); panic!(); @@ -246,7 +246,7 @@ pub fn expect_ok_contains(config: &Config, args: &[&str], stdout: &str, stderr: let out = run(config, args[0], &args[1..], &[]); if !out.ok || !out.stdout.contains(stdout) || !out.stderr.contains(stderr) { print_command(args, &out); - println!("expected.ok: {}", true); + println!("expected.ok: true"); print_indented("expected.stdout.contains", stdout); print_indented("expected.stderr.contains", stderr); panic!(); @@ -258,9 +258,9 @@ pub fn expect_ok_eq(config: &Config, args1: &[&str], args2: &[&str]) { let out2 = run(config, args2[0], &args2[1..], &[]); if !out1.ok || !out2.ok || out1.stdout != out2.stdout || out1.stderr != out2.stderr { print_command(args1, &out1); - println!("expected.ok: {}", true); + println!("expected.ok: true"); print_command(args2, &out2); - println!("expected.ok: {}", true); + println!("expected.ok: true"); panic!(); } } From d3f5cb0ccb292e826e4e86b3f8bfb35326d20bfc Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 19 Apr 2019 16:27:58 +0700 Subject: [PATCH 07/17] clippy: Fix clone_double_ref --- tests/dist.rs | 4 ++-- tests/mock/clitools.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/dist.rs b/tests/dist.rs index 48d60d866c..71bcfca43e 100644 --- a/tests/dist.rs +++ b/tests/dist.rs @@ -423,7 +423,7 @@ fn update_from_dist_( changes, force_update, download_cfg, - download_cfg.notify_handler.clone(), + download_cfg.notify_handler, &toolchain.to_string(), ) } @@ -447,7 +447,7 @@ fn uninstall( let manifestation = Manifestation::open(prefix.clone(), trip)?; let manifest = manifestation.load_manifest()?.unwrap(); - manifestation.uninstall(&manifest, temp_cfg, notify_handler.clone())?; + manifestation.uninstall(&manifest, temp_cfg, notify_handler)?; Ok(()) } diff --git a/tests/mock/clitools.rs b/tests/mock/clitools.rs index 10d0f88625..583bedab73 100644 --- a/tests/mock/clitools.rs +++ b/tests/mock/clitools.rs @@ -716,7 +716,7 @@ pub fn this_host_triple() -> String { fn build_mock_std_installer(trip: &str) -> MockInstallerBuilder { MockInstallerBuilder { components: vec![MockComponentBuilder { - name: format!("rust-std-{}", trip.clone()), + name: format!("rust-std-{}", trip), files: vec![MockFile::new( format!("lib/rustlib/{}/libstd.rlib", trip), b"", @@ -728,7 +728,7 @@ fn build_mock_std_installer(trip: &str) -> MockInstallerBuilder { fn build_mock_cross_std_installer(target: &str, date: &str) -> MockInstallerBuilder { MockInstallerBuilder { components: vec![MockComponentBuilder { - name: format!("rust-std-{}", target.clone()), + name: format!("rust-std-{}", target), files: vec![ MockFile::new(format!("lib/rustlib/{}/lib/libstd.rlib", target), b""), MockFile::new(format!("lib/rustlib/{}/lib/{}", target, date), b""), From 5c5de71c4a3554fc5640d37f84d69dfe0f6d7e6d Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 19 Apr 2019 16:32:48 +0700 Subject: [PATCH 08/17] clippy: Fix useless_let_if_seq --- tests/mock/clitools.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/mock/clitools.rs b/tests/mock/clitools.rs index 583bedab73..4b1ae04aab 100644 --- a/tests/mock/clitools.rs +++ b/tests/mock/clitools.rs @@ -745,12 +745,11 @@ fn build_mock_rustc_installer( // For cross-host rustc's modify the version_hash so they can be identified from // test cases. let this_host = this_host_triple(); - let version_hash; - if this_host != target { - version_hash = format!("xxxx-{}", &version_hash_[5..]); + let version_hash = if this_host != target { + format!("xxxx-{}", &version_hash_[5..]) } else { - version_hash = version_hash_.to_string(); - } + version_hash_.to_string() + }; MockInstallerBuilder { components: vec![MockComponentBuilder { From 2d3b91c79a645cbcb0374dcd6ea6ffa69c621b5b Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 19 Apr 2019 16:36:25 +0700 Subject: [PATCH 09/17] clippy: Fix useless_format --- tests/cli-exact.rs | 2 +- tests/cli-self-upd.rs | 3 +-- tests/mock/dist.rs | 8 ++++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/cli-exact.rs b/tests/cli-exact.rs index 621c3fc22f..4b64e6b1d2 100644 --- a/tests/cli-exact.rs +++ b/tests/cli-exact.rs @@ -396,7 +396,7 @@ fn undefined_linked_toolchain() { config, &["cargo", "+bogus", "test"], r"", - &format!("error: toolchain 'bogus' is not installed\n"), + "error: toolchain 'bogus' is not installed\n", ); }); } diff --git a/tests/cli-self-upd.rs b/tests/cli-self-upd.rs index aff7af68c1..84c1406431 100644 --- a/tests/cli-self-upd.rs +++ b/tests/cli-self-upd.rs @@ -460,8 +460,7 @@ fn when_cargo_home_is_the_default_write_path_specially() { assert!(cmd.output().unwrap().status.success()); let new_profile = raw::read_file(&profile).unwrap(); - let addition = format!(r#"export PATH="$HOME/.cargo/bin:$PATH""#); - let expected = format!("{}\n{}\n", my_profile, addition); + let expected = format!("{}\nexport PATH=\"$HOME/.cargo/bin:$PATH\"\n", my_profile); assert_eq!(new_profile, expected); let mut cmd = clitools::cmd(config, "rustup", &["self", "uninstall", "-y"]); diff --git a/tests/mock/dist.rs b/tests/mock/dist.rs index 70c21cbcc6..232c29ced2 100644 --- a/tests/mock/dist.rs +++ b/tests/mock/dist.rs @@ -34,11 +34,11 @@ pub fn change_channel_date(dist_server: &Url, channel: &str, date: &str) { // V1 let manifest_name = format!("dist/channel-rust-{}", channel); - let manifest_path = path.join(format!("{}", manifest_name)); + let manifest_path = path.join(&manifest_name); let hash_path = path.join(format!("{}.sha256", manifest_name)); let archive_manifest_name = format!("dist/{}/channel-rust-{}", date, channel); - let archive_manifest_path = path.join(format!("{}", archive_manifest_name)); + let archive_manifest_path = path.join(&archive_manifest_name); let archive_hash_path = path.join(format!("{}.sha256", archive_manifest_name)); let _ = hard_link(archive_manifest_path, manifest_path); @@ -267,7 +267,7 @@ impl MockDistServer { } let manifest_name = format!("dist/channel-rust-{}", channel.name); - let manifest_path = self.path.join(format!("{}", manifest_name)); + let manifest_path = self.path.join(&manifest_name); write_file(&manifest_path, &buf); let hash_path = self.path.join(format!("{}.sha256", manifest_name)); @@ -275,7 +275,7 @@ impl MockDistServer { // Also copy the manifest and hash into the archive folder let archive_manifest_name = format!("dist/{}/channel-rust-{}", channel.date, channel.name); - let archive_manifest_path = self.path.join(format!("{}", archive_manifest_name)); + let archive_manifest_path = self.path.join(&archive_manifest_name); hard_link(manifest_path, archive_manifest_path).unwrap(); let archive_hash_path = self.path.join(format!("{}.sha256", archive_manifest_name)); From a971149c13660767fb1173d50a011bb2edb8e91b Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 19 Apr 2019 16:48:56 +0700 Subject: [PATCH 10/17] clippy: Fix type_complexity --- tests/mock/dist.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/mock/dist.rs b/tests/mock/dist.rs index 232c29ced2..5cd0fe7fb9 100644 --- a/tests/mock/dist.rs +++ b/tests/mock/dist.rs @@ -197,11 +197,11 @@ impl MockDistServer { fs::create_dir_all(&installer_dir).unwrap(); + type Tarball = HashMap<(String, MockTargetedPackage, String), (Vec, String)>; // Tarball creation can be super slow, so cache created tarballs // globally to avoid recreating and recompressing tons of tarballs. lazy_static! { - static ref TARBALLS: Mutex, String)>> = - Mutex::new(HashMap::new()); + static ref TARBALLS: Mutex = Mutex::new(HashMap::new()); } let key = ( From 46f6828b6a7c4c0b48491747eac324317e28265c Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 19 Apr 2019 16:52:12 +0700 Subject: [PATCH 11/17] clippy: Fix single_match --- tests/mock/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/mock/mod.rs b/tests/mock/mod.rs index 9e639d1c01..0566aef93d 100644 --- a/tests/mock/mod.rs +++ b/tests/mock/mod.rs @@ -117,9 +117,8 @@ impl MockFile { } pub fn executable(mut self, exe: bool) -> Self { - match self.contents { - Contents::File(ref mut c) => c.executable = exe, - _ => {} + if let Contents::File(c) = &mut self.contents { + c.executable = exe; } self } From 106f673652d5063dbeb8c5efdc7af3da45a6632f Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 19 Apr 2019 19:30:44 +0700 Subject: [PATCH 12/17] clippy: Fix redundant_field_names --- tests/dist.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dist.rs b/tests/dist.rs index 71bcfca43e..186eae95a4 100644 --- a/tests/dist.rs +++ b/tests/dist.rs @@ -201,7 +201,7 @@ pub fn create_mock_channel( fn bonus_component(name: &'static str, contents: Arc>) -> MockPackage { MockPackage { - name: name, + name, version: "1.0.0", targets: vec![MockTargetedPackage { target: "x86_64-apple-darwin".to_string(), From 17ffffa08e10c16417bce09980fe941f3b74b686 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 19 Apr 2019 20:30:08 +0700 Subject: [PATCH 13/17] clippy: Fix too_many_arguments --- tests/dist.rs | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/tests/dist.rs b/tests/dist.rs index 186eae95a4..5335e6912d 100644 --- a/tests/dist.rs +++ b/tests/dist.rs @@ -379,28 +379,6 @@ fn update_from_dist( remove: &[Component], download_cfg: &DownloadCfg<'_>, temp_cfg: &temp::Cfg, -) -> Result { - update_from_dist_( - dist_server, - toolchain, - prefix, - add, - remove, - download_cfg, - temp_cfg, - false, - ) -} - -fn update_from_dist_( - dist_server: &Url, - toolchain: &ToolchainDesc, - prefix: &InstallPrefix, - add: &[Component], - remove: &[Component], - download_cfg: &DownloadCfg<'_>, - temp_cfg: &temp::Cfg, - force_update: bool, ) -> Result { // Download the dist manifest and place it into the installation prefix let manifest_url = make_manifest_url(dist_server, toolchain)?; @@ -421,7 +399,7 @@ fn update_from_dist_( manifestation.update( &manifest, changes, - force_update, + false, download_cfg, download_cfg.notify_handler, &toolchain.to_string(), From 823300fa98fea732ce5253a2cd4285d75c9a0268 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sat, 20 Apr 2019 00:05:33 +0700 Subject: [PATCH 14/17] clippy: Fix mutex_atomic --- download/tests/download-curl-resume.rs | 10 +++++----- download/tests/download-reqwest-resume.rs | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/download/tests/download-curl-resume.rs b/download/tests/download-curl-resume.rs index b5cc862f26..6b8083c00a 100644 --- a/download/tests/download-curl-resume.rs +++ b/download/tests/download-curl-resume.rs @@ -1,5 +1,6 @@ #![cfg(feature = "curl-backend")] +use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Mutex; use url::Url; @@ -35,7 +36,7 @@ fn callback_gets_all_data_as_if_the_download_happened_all_at_once() { let from_url = format!("http://{}", addr).parse().unwrap(); - let callback_partial = Mutex::new(false); + let callback_partial = AtomicBool::new(false); let callback_len = Mutex::new(None); let received_in_callback = Mutex::new(Vec::new()); @@ -47,9 +48,8 @@ fn callback_gets_all_data_as_if_the_download_happened_all_at_once() { Some(&|msg| { match msg { Event::ResumingPartialDownload => { - let mut flag = callback_partial.lock().unwrap(); - assert!(!*flag); - *flag = true; + assert!(!callback_partial.load(Ordering::SeqCst)); + callback_partial.store(true, Ordering::SeqCst); } Event::DownloadContentLengthReceived(len) => { let mut flag = callback_len.lock().unwrap(); @@ -68,7 +68,7 @@ fn callback_gets_all_data_as_if_the_download_happened_all_at_once() { ) .expect("Test download failed"); - assert!(*callback_partial.lock().unwrap()); + assert!(callback_partial.into_inner()); assert_eq!(*callback_len.lock().unwrap(), Some(5)); let observed_bytes = received_in_callback.into_inner().unwrap(); assert_eq!(observed_bytes, vec![b'1', b'2', b'3', b'4', b'5']); diff --git a/download/tests/download-reqwest-resume.rs b/download/tests/download-reqwest-resume.rs index 592cab8dda..4e83059bfc 100644 --- a/download/tests/download-reqwest-resume.rs +++ b/download/tests/download-reqwest-resume.rs @@ -1,5 +1,6 @@ #![cfg(feature = "reqwest-backend")] +use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Mutex; use url::Url; @@ -35,7 +36,7 @@ fn callback_gets_all_data_as_if_the_download_happened_all_at_once() { let from_url = format!("http://{}", addr).parse().unwrap(); - let callback_partial = Mutex::new(false); + let callback_partial = AtomicBool::new(false); let callback_len = Mutex::new(None); let received_in_callback = Mutex::new(Vec::new()); @@ -47,9 +48,8 @@ fn callback_gets_all_data_as_if_the_download_happened_all_at_once() { Some(&|msg| { match msg { Event::ResumingPartialDownload => { - let mut flag = callback_partial.lock().unwrap(); - assert!(!*flag); - *flag = true; + assert!(!callback_partial.load(Ordering::SeqCst)); + callback_partial.store(true, Ordering::SeqCst); } Event::DownloadContentLengthReceived(len) => { let mut flag = callback_len.lock().unwrap(); @@ -68,7 +68,7 @@ fn callback_gets_all_data_as_if_the_download_happened_all_at_once() { ) .expect("Test download failed"); - assert!(*callback_partial.lock().unwrap()); + assert!(callback_partial.into_inner()); assert_eq!(*callback_len.lock().unwrap(), Some(5)); let observed_bytes = received_in_callback.into_inner().unwrap(); assert_eq!(observed_bytes, vec![b'1', b'2', b'3', b'4', b'5']); From f0d14d5de36c70719cba54fc9c899d8b8864a1c0 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sat, 20 Apr 2019 00:48:53 +0700 Subject: [PATCH 15/17] clippy: Fix const_static_lifetime --- tests/cli-self-upd.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cli-self-upd.rs b/tests/cli-self-upd.rs index 84c1406431..a5bfd8a0d1 100644 --- a/tests/cli-self-upd.rs +++ b/tests/cli-self-upd.rs @@ -25,7 +25,7 @@ macro_rules! for_host { }; } -const TEST_VERSION: &'static str = "1.1.1"; +const TEST_VERSION: &str = "1.1.1"; pub fn setup(f: &dyn Fn(&Config)) { clitools::setup(Scenario::SimpleV2, &|config| { From 941bf46492ab2e7e1965991ecb93760e08c0b2b8 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sun, 21 Apr 2019 10:28:00 +0700 Subject: [PATCH 16/17] Fix unnecessary `ref` and `ref mut` --- src/cli/term2.rs | 10 +++++----- src/config.rs | 8 +++----- src/dist/component/transaction.rs | 12 ++++++------ src/dist/manifest.rs | 12 ++++++------ src/dist/notifications.rs | 22 +++++++++++----------- src/dist/temp.rs | 28 ++++++++++++++-------------- src/notifications.rs | 18 +++++++++--------- src/utils/notifications.rs | 4 ++-- src/utils/raw.rs | 12 ++++++------ src/utils/utils.rs | 2 +- 10 files changed, 63 insertions(+), 65 deletions(-) diff --git a/src/cli/term2.rs b/src/cli/term2.rs index aba93bd8b4..f3f6ed8bd9 100644 --- a/src/cli/term2.rs +++ b/src/cli/term2.rs @@ -228,7 +228,7 @@ impl<'a, T: Instantiable + Isatty + io::Write + 'a> LineFormatter<'a, T> { impl io::Write for Terminal { fn write(&mut self, buf: &[u8]) -> Result { - if let Some(ref mut t) = self.0 { + if let Some(t) = self.0.as_mut() { t.write(buf) } else { let mut t = T::instance(); @@ -237,7 +237,7 @@ impl io::Write for Terminal { } fn flush(&mut self) -> Result<(), io::Error> { - if let Some(ref mut t) = self.0 { + if let Some(t) = self.0.as_mut() { t.flush() } else { let mut t = T::instance(); @@ -262,7 +262,7 @@ impl Terminal { return Ok(()); } - if let Some(ref mut t) = self.0 { + if let Some(t) = self.0.as_mut() { swallow_unsupported!(t.fg(color)) } else { Ok(()) @@ -274,7 +274,7 @@ impl Terminal { return Ok(()); } - if let Some(ref mut t) = self.0 { + if let Some(t) = self.0.as_mut() { if let Err(e) = t.attr(attr) { // If `attr` is not supported, try to emulate it match attr { @@ -294,7 +294,7 @@ impl Terminal { return Ok(()); } - if let Some(ref mut t) = self.0 { + if let Some(t) = self.0.as_mut() { swallow_unsupported!(t.reset()) } else { Ok(()) diff --git a/src/config.rs b/src/config.rs index 1800152e43..3b6ce85c44 100644 --- a/src/config.rs +++ b/src/config.rs @@ -22,14 +22,12 @@ pub enum OverrideReason { impl Display for OverrideReason { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> ::std::result::Result<(), fmt::Error> { - match *self { + match self { OverrideReason::Environment => write!(f, "environment override by RUSTUP_TOOLCHAIN"), - OverrideReason::OverrideDB(ref path) => { + OverrideReason::OverrideDB(path) => { write!(f, "directory override for '{}'", path.display()) } - OverrideReason::ToolchainFile(ref path) => { - write!(f, "overridden by '{}'", path.display()) - } + OverrideReason::ToolchainFile(path) => write!(f, "overridden by '{}'", path.display()), } } } diff --git a/src/dist/component/transaction.rs b/src/dist/component/transaction.rs index ca4f57071c..0c0366bfc1 100644 --- a/src/dist/component/transaction.rs +++ b/src/dist/component/transaction.rs @@ -193,16 +193,16 @@ enum ChangedItem<'a> { impl<'a> ChangedItem<'a> { fn roll_back(&self, prefix: &InstallPrefix) -> Result<()> { use self::ChangedItem::*; - match *self { - AddedFile(ref path) => utils::remove_file("component", &prefix.abs_path(path))?, - AddedDir(ref path) => utils::remove_dir("component", &prefix.abs_path(path), &|_| ())?, - RemovedFile(ref path, ref tmp) | ModifiedFile(ref path, Some(ref tmp)) => { + match self { + AddedFile(path) => utils::remove_file("component", &prefix.abs_path(path))?, + AddedDir(path) => utils::remove_dir("component", &prefix.abs_path(path), &|_| ())?, + RemovedFile(path, tmp) | ModifiedFile(path, Some(tmp)) => { utils::rename_file("component", &tmp, &prefix.abs_path(path))? } - RemovedDir(ref path, ref tmp) => { + RemovedDir(path, tmp) => { utils::rename_dir("component", &tmp.join("bk"), &prefix.abs_path(path))? } - ModifiedFile(ref path, None) => { + ModifiedFile(path, None) => { let abs_path = prefix.abs_path(path); if utils::is_file(&abs_path) { utils::remove_file("component", &abs_path)?; diff --git a/src/dist/manifest.rs b/src/dist/manifest.rs index eed7f133a2..9c861ea0e1 100644 --- a/src/dist/manifest.rs +++ b/src/dist/manifest.rs @@ -287,15 +287,15 @@ impl Package { impl PackageTargets { pub fn get<'a>(&'a self, target: &TargetTriple) -> Option<&'a TargetedPackage> { - match *self { - PackageTargets::Wildcard(ref tpkg) => Some(tpkg), - PackageTargets::Targeted(ref tpkgs) => tpkgs.get(target), + match self { + PackageTargets::Wildcard(tpkg) => Some(tpkg), + PackageTargets::Targeted(tpkgs) => tpkgs.get(target), } } pub fn get_mut<'a>(&'a mut self, target: &TargetTriple) -> Option<&'a mut TargetedPackage> { - match *self { - PackageTargets::Wildcard(ref mut tpkg) => Some(tpkg), - PackageTargets::Targeted(ref mut tpkgs) => tpkgs.get_mut(target), + match self { + PackageTargets::Wildcard(tpkg) => Some(tpkg), + PackageTargets::Targeted(tpkgs) => tpkgs.get_mut(target), } } } diff --git a/src/dist/notifications.rs b/src/dist/notifications.rs index b94bf8298b..4f05559f57 100644 --- a/src/dist/notifications.rs +++ b/src/dist/notifications.rs @@ -48,9 +48,9 @@ impl<'a> From> for Notification<'a> { impl<'a> Notification<'a> { pub fn level(&self) -> NotificationLevel { use self::Notification::*; - match *self { - Temp(ref n) => n.level(), - Utils(ref n) => n.level(), + match self { + Temp(n) => n.level(), + Utils(n) => n.level(), ChecksumValid(_) | NoUpdateHash(_) | FileAlreadyDownloaded @@ -79,11 +79,11 @@ impl<'a> Notification<'a> { impl<'a> Display for Notification<'a> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> ::std::result::Result<(), fmt::Error> { use self::Notification::*; - match *self { - Temp(ref n) => n.fmt(f), - Utils(ref n) => n.fmt(f), + match self { + Temp(n) => n.fmt(f), + Utils(n) => n.fmt(f), Extracting(_, _) => write!(f, "extracting..."), - ComponentAlreadyInstalled(ref c) => write!(f, "component {} is up to date", c), + ComponentAlreadyInstalled(c) => write!(f, "component {} is up to date", c), CantReadUpdateHash(path) => write!( f, "can't read update hash file: '{}', can't skip update...", @@ -101,28 +101,28 @@ impl<'a> Display for Notification<'a> { write!(f, "during uninstall component {} was not found", c) } DownloadingComponent(c, h, t) => { - if Some(h) == t || t.is_none() { + if Some(h) == t.as_ref() || t.is_none() { write!(f, "downloading component '{}'", c) } else { write!(f, "downloading component '{}' for '{}'", c, t.unwrap()) } } InstallingComponent(c, h, t) => { - if Some(h) == t || t.is_none() { + if Some(h) == t.as_ref() || t.is_none() { write!(f, "installing component '{}'", c) } else { write!(f, "installing component '{}' for '{}'", c, t.unwrap()) } } RemovingComponent(c, h, t) => { - if Some(h) == t || t.is_none() { + if Some(h) == t.as_ref() || t.is_none() { write!(f, "removing component '{}'", c) } else { write!(f, "removing component '{}' for '{}'", c, t.unwrap()) } } RemovingOldComponent(c, h, t) => { - if Some(h) == t || t.is_none() { + if Some(h) == t.as_ref() || t.is_none() { write!(f, "removing previous version of component '{}'", c) } else { write!( diff --git a/src/dist/temp.rs b/src/dist/temp.rs index 3ea60ed516..936c17a1ab 100644 --- a/src/dist/temp.rs +++ b/src/dist/temp.rs @@ -47,9 +47,9 @@ pub struct File<'a> { impl<'a> Notification<'a> { pub fn level(&self) -> NotificationLevel { use self::Notification::*; - match *self { + match self { CreatingRoot(_) | CreatingFile(_) | CreatingDirectory(_) => NotificationLevel::Verbose, - FileDeletion(_, ref result) | DirectoryDeletion(_, ref result) => { + FileDeletion(_, result) | DirectoryDeletion(_, result) => { if result.is_ok() { NotificationLevel::Verbose } else { @@ -63,18 +63,18 @@ impl<'a> Notification<'a> { impl<'a> Display for Notification<'a> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> ::std::result::Result<(), fmt::Error> { use self::Notification::*; - match *self { + match self { CreatingRoot(path) => write!(f, "creating temp root: {}", path.display()), CreatingFile(path) => write!(f, "creating temp file: {}", path.display()), CreatingDirectory(path) => write!(f, "creating temp directory: {}", path.display()), - FileDeletion(path, ref result) => { + FileDeletion(path, result) => { if result.is_ok() { write!(f, "deleted temp file: {}", path.display()) } else { write!(f, "could not delete temp file: {}", path.display()) } } - DirectoryDeletion(path, ref result) => { + DirectoryDeletion(path, result) => { if result.is_ok() { write!(f, "deleted temp directory: {}", path.display()) } else { @@ -88,7 +88,7 @@ impl<'a> Display for Notification<'a> { impl error::Error for Error { fn description(&self) -> &str { use self::Error::*; - match *self { + match self { CreatingRoot { .. } => "could not create temp root", CreatingFile { .. } => "could not create temp file", CreatingDirectory { .. } => "could not create temp directory", @@ -97,10 +97,10 @@ impl error::Error for Error { fn cause(&self) -> Option<&dyn error::Error> { use self::Error::*; - match *self { - CreatingRoot { ref error, .. } - | CreatingFile { ref error, .. } - | CreatingDirectory { ref error, .. } => Some(error), + match self { + CreatingRoot { error, .. } + | CreatingFile { error, .. } + | CreatingDirectory { error, .. } => Some(error), } } } @@ -108,14 +108,14 @@ impl error::Error for Error { impl Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> ::std::result::Result<(), fmt::Error> { use self::Error::*; - match *self { - CreatingRoot { ref path, .. } => { + match self { + CreatingRoot { path, .. } => { write!(f, "could not create temp root: {}", path.display()) } - CreatingFile { ref path, .. } => { + CreatingFile { path, .. } => { write!(f, "could not create temp file: {}", path.display()) } - CreatingDirectory { ref path, .. } => { + CreatingDirectory { path, .. } => { write!(f, "could not create temp directory: {}", path.display()) } } diff --git a/src/notifications.rs b/src/notifications.rs index 21b03ad086..0d73464a97 100644 --- a/src/notifications.rs +++ b/src/notifications.rs @@ -52,10 +52,10 @@ impl<'a> From> for Notification<'a> { impl<'a> Notification<'a> { pub fn level(&self) -> NotificationLevel { use self::Notification::*; - match *self { - Install(ref n) => n.level(), - Utils(ref n) => n.level(), - Temp(ref n) => n.level(), + match self { + Install(n) => n.level(), + Utils(n) => n.level(), + Temp(n) => n.level(), ToolchainDirectory(_, _) | LookingForToolchain(_) | WritingMetadataVersion(_) @@ -81,10 +81,10 @@ impl<'a> Notification<'a> { impl<'a> Display for Notification<'a> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> ::std::result::Result<(), fmt::Error> { use self::Notification::*; - match *self { - Install(ref n) => n.fmt(f), - Utils(ref n) => n.fmt(f), - Temp(ref n) => n.fmt(f), + match self { + Install(n) => n.fmt(f), + Utils(n) => n.fmt(f), + Temp(n) => n.fmt(f), SetDefaultToolchain(name) => write!(f, "default toolchain set to '{}'", name), SetOverrideToolchain(path, name) => write!( f, @@ -119,7 +119,7 @@ impl<'a> Display for Notification<'a> { f, "this upgrade will remove all existing toolchains. you will need to reinstall them" ), - MissingFileDuringSelfUninstall(ref p) => write!( + MissingFileDuringSelfUninstall(p) => write!( f, "expected file does not exist to uninstall: {}", p.display() diff --git a/src/utils/notifications.rs b/src/utils/notifications.rs index 9775cab803..49e5361e5b 100644 --- a/src/utils/notifications.rs +++ b/src/utils/notifications.rs @@ -27,7 +27,7 @@ pub enum Notification<'a> { impl<'a> Notification<'a> { pub fn level(&self) -> NotificationLevel { use self::Notification::*; - match *self { + match self { CreatingDirectory(_, _) | RemovingDirectory(_, _) => NotificationLevel::Verbose, LinkingDirectory(_, _) | CopyingDirectory(_, _) @@ -46,7 +46,7 @@ impl<'a> Notification<'a> { impl<'a> Display for Notification<'a> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> ::std::result::Result<(), fmt::Error> { use self::Notification::*; - match *self { + match self { CreatingDirectory(name, path) => { write!(f, "creating {} directory: '{}'", name, path.display()) } diff --git a/src/utils/raw.rs b/src/utils/raw.rs index 8435173750..dde27897be 100644 --- a/src/utils/raw.rs +++ b/src/utils/raw.rs @@ -269,7 +269,7 @@ pub type CommandResult = ::std::result::Result; impl error::Error for CommandError { fn description(&self) -> &str { use self::CommandError::*; - match *self { + match self { Io(_) => "could not execute command", Status(_) => "command exited with unsuccessful status", } @@ -277,8 +277,8 @@ impl error::Error for CommandError { fn cause(&self) -> Option<&dyn error::Error> { use self::CommandError::*; - match *self { - Io(ref e) => Some(e), + match self { + Io(e) => Some(e), Status(_) => None, } } @@ -286,9 +286,9 @@ impl error::Error for CommandError { impl fmt::Display for CommandError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match *self { - CommandError::Io(ref e) => write!(f, "Io: {}", e), - CommandError::Status(ref s) => write!(f, "Status: {}", s), + match self { + CommandError::Io(e) => write!(f, "Io: {}", e), + CommandError::Status(s) => write!(f, "Status: {}", s), } } } diff --git a/src/utils/utils.rs b/src/utils/utils.rs index 9e5394968a..e7edf5e48d 100644 --- a/src/utils/utils.rs +++ b/src/utils/utils.rs @@ -177,7 +177,7 @@ fn download_file_( // hash the contents, then forward the notification up the stack let callback: &dyn Fn(Event<'_>) -> download::Result<()> = &|msg| { if let Event::DownloadDataReceived(data) = msg { - if let Some(ref mut h) = *hasher.borrow_mut() { + if let Some(h) = hasher.borrow_mut().as_mut() { h.input(data); } } From 9284671363a3947b0683fb8ae419dec6f755a575 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sun, 21 Apr 2019 10:28:32 +0700 Subject: [PATCH 17/17] tests: Use `RefCell::replace` in place of `mem::replace` --- tests/mock/clitools.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/mock/clitools.rs b/tests/mock/clitools.rs index 4b1ae04aab..6bdcca49f6 100644 --- a/tests/mock/clitools.rs +++ b/tests/mock/clitools.rs @@ -14,7 +14,6 @@ use std::env::consts::EXE_SUFFIX; use std::ffi::OsStr; use std::fs::{self, File}; use std::io::{self, Read, Write}; -use std::mem; use std::path::{Path, PathBuf}; use std::process::Command; use std::sync::Arc; @@ -155,7 +154,7 @@ impl Config { } fn _change_dir(&self, path: &Path, f: &mut dyn FnMut()) { - let prev = mem::replace(&mut *self.workdir.borrow_mut(), path.to_owned()); + let prev = self.workdir.replace(path.to_owned()); f(); *self.workdir.borrow_mut() = prev; }