Skip to content

Commit

Permalink
Merge pull request #3096 from hi-rustin/rustin-patch-clippy
Browse files Browse the repository at this point in the history
Clippy satisfying changes - unneeded & and &*.
  • Loading branch information
rbtcollins authored Dec 5, 2022
2 parents b3d5325 + e7395b8 commit 3331f34
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 50 deletions.
6 changes: 3 additions & 3 deletions download/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn download_to_path_with_backend(

|| -> Result<()> {
let (file, resume_from) = if resume_from_partial {
let possible_partial = OpenOptions::new().read(true).open(&path);
let possible_partial = OpenOptions::new().read(true).open(path);

let downloaded_so_far = if let Ok(mut partial) = possible_partial {
if let Some(cb) = callback {
Expand Down Expand Up @@ -90,7 +90,7 @@ pub fn download_to_path_with_backend(
let mut possible_partial = OpenOptions::new()
.write(true)
.create(true)
.open(&path)
.open(path)
.context("error opening file for download")?;

possible_partial.seek(SeekFrom::End(0))?;
Expand All @@ -101,7 +101,7 @@ pub fn download_to_path_with_backend(
OpenOptions::new()
.write(true)
.create(true)
.open(&path)
.open(path)
.context("error creating file for download")?,
0,
)
Expand Down
2 changes: 1 addition & 1 deletion src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ fn print_toolchain_path(
) -> Result<()> {
let toolchain_path = {
let mut t_path = cfg.toolchains_dir.clone();
t_path.push(&toolchain);
t_path.push(toolchain);
t_path
};
let toolchain_meta = fs::symlink_metadata(&toolchain_path)?;
Expand Down
2 changes: 1 addition & 1 deletion src/cli/self_update/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl Zsh {
}
} else {
match std::process::Command::new("zsh")
.args(&["-c", "'echo $ZDOTDIR'"])
.args(["-c", "'echo $ZDOTDIR'"])
.output()
{
Ok(io) if !io.stdout.is_empty() => Ok(PathBuf::from(OsStr::from_bytes(&io.stdout))),
Expand Down
2 changes: 1 addition & 1 deletion src/cli/topical_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn dir_into_vec(dir: &Path) -> Result<Vec<OsString>> {
}

fn search_path(doc: &DocData<'_>, wpath: &Path, keywords: &[&str]) -> Result<PathBuf> {
let dir = &doc.root.join(&wpath);
let dir = &doc.root.join(wpath);
if dir.is_dir() {
let entries = dir_into_vec(dir)?;
for k in keywords {
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl PgpPublicKey {
/// Retrieve the key.
pub(crate) fn cert(&self) -> &Cert {
match self {
Self::Builtin => &*BUILTIN_PGP_KEY,
Self::Builtin => &BUILTIN_PGP_KEY,
Self::FromEnvironment(_, k) => k,
Self::FromConfiguration(_, k) => k,
}
Expand Down
2 changes: 1 addition & 1 deletion src/diskio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ pub(crate) fn perform<F: Fn(usize)>(item: &mut Item, chunk_complete_callback: F)
contents.clear();
match contents {
FileBuffer::Immediate(ref contents) => {
write_file(&item.full_path, &contents, item.mode)
write_file(&item.full_path, contents, item.mode)
}
FileBuffer::Threaded(ref mut contents) => {
write_file(&item.full_path, &contents, item.mode)
Expand Down
4 changes: 2 additions & 2 deletions src/dist/component/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl<'a> TarPackage<'a> {
// The rust-installer packages unpack to a directory called
// $pkgname-$version-$target. Skip that directory when
// unpacking.
unpack_without_first_dir(&mut archive, &*temp_dir, notify_handler)
unpack_without_first_dir(&mut archive, &temp_dir, notify_handler)
.context("failed to extract package (perhaps you ran out of disk space?)")?;

Ok(TarPackage(
Expand Down Expand Up @@ -334,7 +334,7 @@ fn unpack_without_first_dir<'a, R: Read>(
let mut components = relpath.components();
// Throw away the first path component: our root was supplied.
components.next();
let full_path = path.join(&components.as_path());
let full_path = path.join(components.as_path());
if full_path == path {
// The tmp dir code makes the root dir for us.
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl<'a> InstalledCommonToolchain<'a> {
}
Path::new(&binary)
};
let mut cmd = Command::new(&path);
let mut cmd = Command::new(path);
self.set_env(&mut cmd);
Ok(cmd)
}
Expand Down
20 changes: 10 additions & 10 deletions tests/cli-misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn update_all_no_update_whitespace() {
#[test]
fn update_works_without_term() {
setup(&|config| {
let mut cmd = clitools::cmd(config, "rustup", &["update", "nightly"]);
let mut cmd = clitools::cmd(config, "rustup", ["update", "nightly"]);
clitools::env(config, &mut cmd);
cmd.env_remove("TERM");

Expand All @@ -140,7 +140,7 @@ fn update_works_without_term() {
#[test]
fn show_works_with_dumb_term() {
setup(&|config| {
let mut cmd = clitools::cmd(config, "rustup", &["show"]);
let mut cmd = clitools::cmd(config, "rustup", ["show"]);
clitools::env(config, &mut cmd);
cmd.env("TERM", "dumb");
assert!(cmd.spawn().unwrap().wait().unwrap().success());
Expand All @@ -152,12 +152,12 @@ fn show_works_with_dumb_term() {
#[test]
fn subcommand_required_for_target() {
setup(&|config| {
let mut cmd = clitools::cmd(config, "rustup", &["target"]);
let mut cmd = clitools::cmd(config, "rustup", ["target"]);
clitools::env(config, &mut cmd);
let out = cmd.output().unwrap();
assert!(!out.status.success());
assert_eq!(out.status.code().unwrap(), 1);
assert!(str::from_utf8(&out.stdout).unwrap().contains(&"USAGE"));
assert!(str::from_utf8(&out.stdout).unwrap().contains("USAGE"));
});
}

Expand All @@ -166,12 +166,12 @@ fn subcommand_required_for_target() {
#[test]
fn subcommand_required_for_toolchain() {
setup(&|config| {
let mut cmd = clitools::cmd(config, "rustup", &["toolchain"]);
let mut cmd = clitools::cmd(config, "rustup", ["toolchain"]);
clitools::env(config, &mut cmd);
let out = cmd.output().unwrap();
assert!(!out.status.success());
assert_eq!(out.status.code().unwrap(), 1);
assert!(str::from_utf8(&out.stdout).unwrap().contains(&"USAGE"));
assert!(str::from_utf8(&out.stdout).unwrap().contains("USAGE"));
});
}

Expand All @@ -180,12 +180,12 @@ fn subcommand_required_for_toolchain() {
#[test]
fn subcommand_required_for_override() {
setup(&|config| {
let mut cmd = clitools::cmd(config, "rustup", &["override"]);
let mut cmd = clitools::cmd(config, "rustup", ["override"]);
clitools::env(config, &mut cmd);
let out = cmd.output().unwrap();
assert!(!out.status.success());
assert_eq!(out.status.code().unwrap(), 1);
assert!(str::from_utf8(&out.stdout).unwrap().contains(&"USAGE"));
assert!(str::from_utf8(&out.stdout).unwrap().contains("USAGE"));
});
}

Expand All @@ -194,12 +194,12 @@ fn subcommand_required_for_override() {
#[test]
fn subcommand_required_for_self() {
setup(&|config| {
let mut cmd = clitools::cmd(config, "rustup", &["self"]);
let mut cmd = clitools::cmd(config, "rustup", ["self"]);
clitools::env(config, &mut cmd);
let out = cmd.output().unwrap();
assert!(!out.status.success());
assert_eq!(out.status.code().unwrap(), 1);
assert!(str::from_utf8(&out.stdout).unwrap().contains(&"USAGE"));
assert!(str::from_utf8(&out.stdout).unwrap().contains("USAGE"));
});
}

Expand Down
22 changes: 11 additions & 11 deletions tests/cli-paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ export PATH="$HOME/apple/bin"
assert!(cmd.output().unwrap().status.success());
let mut rcs = files.iter();
let env = rcs.next().unwrap();
let envfile = fs::read_to_string(&env).unwrap();
let envfile = fs::read_to_string(env).unwrap();
let (_, envfile_export) = envfile.split_at(envfile.find("export PATH").unwrap_or(0));
assert_eq!(&envfile_export[..DEFAULT_EXPORT.len()], DEFAULT_EXPORT);

for rc in rcs {
let expected = source("$HOME/.cargo", POSIX_SH);
let new_profile = fs::read_to_string(&rc).unwrap();
let new_profile = fs::read_to_string(rc).unwrap();
assert_eq!(new_profile, expected);
}
});
Expand All @@ -86,7 +86,7 @@ export PATH="$HOME/apple/bin"

let expected = FAKE_RC.to_owned() + &source(config.cargodir.display(), POSIX_SH);
for rc in &rcs {
let new_rc = fs::read_to_string(&rc).unwrap();
let new_rc = fs::read_to_string(rc).unwrap();
assert_eq!(new_rc, expected);
}
})
Expand Down Expand Up @@ -191,9 +191,9 @@ export PATH="$HOME/apple/bin"

expect_ok(config, &INIT_NONE);

let new1 = fs::read_to_string(&path1).unwrap();
let new1 = fs::read_to_string(path1).unwrap();
assert_eq!(new1, expected);
let new2 = fs::read_to_string(&path2).unwrap();
let new2 = fs::read_to_string(path2).unwrap();
assert_eq!(new2, expected);
}
});
Expand Down Expand Up @@ -221,7 +221,7 @@ export PATH="$HOME/apple/bin"
expect_ok(config, &["rustup", "self", "uninstall", "-y"]);

for rc in &rcs {
let new_rc = fs::read_to_string(&rc).unwrap();
let new_rc = fs::read_to_string(rc).unwrap();
assert_eq!(new_rc, FAKE_RC);
}
})
Expand Down Expand Up @@ -255,11 +255,11 @@ export PATH="$HOME/apple/bin"
assert!(cmd.output().unwrap().status.success());
let fixed_rc = FAKE_RC.to_owned() + &source("$HOME/.cargo", POSIX_SH);
for rc in &rcs {
let new_rc = fs::read_to_string(&rc).unwrap();
let new_rc = fs::read_to_string(rc).unwrap();
assert_eq!(new_rc, fixed_rc);
}
for rc in &zprofiles {
let new_rc = fs::read_to_string(&rc).unwrap();
let new_rc = fs::read_to_string(rc).unwrap();
assert_eq!(new_rc, FAKE_RC);
}
})
Expand Down Expand Up @@ -291,14 +291,14 @@ export PATH="$HOME/apple/bin"
raw::write_file(rc, &old_rc).unwrap();
}

let mut cmd = clitools::cmd(config, "rustup", &["self", "uninstall", "-y"]);
let mut cmd = clitools::cmd(config, "rustup", ["self", "uninstall", "-y"]);
cmd.env("SHELL", "zsh");
cmd.env("ZDOTDIR", zdotdir.path());
cmd.env_remove("CARGO_HOME");
assert!(cmd.output().unwrap().status.success());

for rc in &rcs {
let new_rc = fs::read_to_string(&rc).unwrap();
let new_rc = fs::read_to_string(rc).unwrap();
// It's not ideal, but it's OK, if we leave whitespace.
assert_eq!(new_rc, FAKE_RC);
}
Expand All @@ -324,7 +324,7 @@ export PATH="$HOME/apple/bin"
let expected = format!("{}. \"$HOME/.cargo/env\"\n", FAKE_RC);
assert_eq!(new_profile, expected);

let mut cmd = clitools::cmd(config, "rustup", &["self", "uninstall", "-y"]);
let mut cmd = clitools::cmd(config, "rustup", ["self", "uninstall", "-y"]);
cmd.env_remove("CARGO_HOME");
assert!(cmd.output().unwrap().status.success());

Expand Down
30 changes: 15 additions & 15 deletions tests/cli-rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ fn show_toolchain_toolchain_file_override_not_installed() {

// I'm not sure this should really be erroring when the toolchain
// is not installed; just capturing the behavior.
let mut cmd = clitools::cmd(config, "rustup", &["show"]);
let mut cmd = clitools::cmd(config, "rustup", ["show"]);
clitools::env(config, &mut cmd);
let out = cmd.output().unwrap();
assert!(!out.status.success());
Expand All @@ -965,7 +965,7 @@ fn show_toolchain_override_not_installed() {
setup(&|config| {
expect_ok(config, &["rustup", "override", "add", "nightly"]);
expect_ok(config, &["rustup", "toolchain", "remove", "nightly"]);
let mut cmd = clitools::cmd(config, "rustup", &["show"]);
let mut cmd = clitools::cmd(config, "rustup", ["show"]);
clitools::env(config, &mut cmd);
let out = cmd.output().unwrap();
assert!(out.status.success());
Expand Down Expand Up @@ -1015,7 +1015,7 @@ fn override_set_unset_with_path() {
fn show_toolchain_env() {
setup(&|config| {
expect_ok(config, &["rustup", "default", "nightly"]);
let mut cmd = clitools::cmd(config, "rustup", &["show"]);
let mut cmd = clitools::cmd(config, "rustup", ["show"]);
clitools::env(config, &mut cmd);
cmd.env("RUSTUP_TOOLCHAIN", "nightly");
let out = cmd.output().unwrap();
Expand All @@ -1039,7 +1039,7 @@ nightly-{0} (environment override by RUSTUP_TOOLCHAIN)
#[test]
fn show_toolchain_env_not_installed() {
setup(&|config| {
let mut cmd = clitools::cmd(config, "rustup", &["show"]);
let mut cmd = clitools::cmd(config, "rustup", ["show"]);
clitools::env(config, &mut cmd);
cmd.env("RUSTUP_TOOLCHAIN", "nightly");
let out = cmd.output().unwrap();
Expand Down Expand Up @@ -1197,7 +1197,7 @@ fn update_doesnt_update_non_tracking_channels() {
setup(&|config| {
expect_ok(config, &["rustup", "default", "nightly"]);
expect_ok(config, &["rustup", "update", "nightly-2015-01-01"]);
let mut cmd = clitools::cmd(config, "rustup", &["update"]);
let mut cmd = clitools::cmd(config, "rustup", ["update"]);
clitools::env(config, &mut cmd);
let out = cmd.output().unwrap();
let stderr = String::from_utf8(out.stderr).unwrap();
Expand Down Expand Up @@ -1261,7 +1261,7 @@ fn toolchain_update_is_like_update() {
fn toolchain_uninstall_is_like_uninstall() {
setup(&|config| {
expect_ok(config, &["rustup", "uninstall", "nightly"]);
let mut cmd = clitools::cmd(config, "rustup", &["show"]);
let mut cmd = clitools::cmd(config, "rustup", ["show"]);
clitools::env(config, &mut cmd);
let out = cmd.output().unwrap();
assert!(out.status.success());
Expand Down Expand Up @@ -1324,7 +1324,7 @@ fn remove_component() {
));
assert!(config.rustupdir.has(&path));
expect_ok(config, &["rustup", "component", "remove", "rust-src"]);
assert!(!config.rustupdir.has(&path.parent().unwrap()));
assert!(!config.rustupdir.has(path.parent().unwrap()));
});
}

Expand Down Expand Up @@ -1355,7 +1355,7 @@ fn add_remove_multiple_components() {
this_host_triple(),
file
));
assert!(!config.rustupdir.has(&path.parent().unwrap()));
assert!(!config.rustupdir.has(path.parent().unwrap()));
}
});
}
Expand Down Expand Up @@ -1387,7 +1387,7 @@ fn env_override_path() {
.join("toolchains")
.join(format!("nightly-{}", this_host_triple()));

let mut cmd = clitools::cmd(config, "rustc", &["--version"]);
let mut cmd = clitools::cmd(config, "rustc", ["--version"]);
clitools::env(config, &mut cmd);
cmd.env("RUSTUP_TOOLCHAIN", toolchain_path.to_str().unwrap());

Expand Down Expand Up @@ -1871,7 +1871,7 @@ fn env_override_beats_file_override() {
let toolchain_file = cwd.join("rust-toolchain");
raw::write_file(&toolchain_file, "nightly").unwrap();

let mut cmd = clitools::cmd(config, "rustc", &["--version"]);
let mut cmd = clitools::cmd(config, "rustc", ["--version"]);
clitools::env(config, &mut cmd);
cmd.env("RUSTUP_TOOLCHAIN", "beta");

Expand Down Expand Up @@ -1963,7 +1963,7 @@ fn docs_with_path() {
expect_ok(config, &["rustup", "default", "stable"]);
expect_ok(config, &["rustup", "toolchain", "install", "nightly"]);

let mut cmd = clitools::cmd(config, "rustup", &["doc", "--path"]);
let mut cmd = clitools::cmd(config, "rustup", ["doc", "--path"]);
clitools::env(config, &mut cmd);

let out = cmd.output().unwrap();
Expand All @@ -1973,7 +1973,7 @@ fn docs_with_path() {
let mut cmd = clitools::cmd(
config,
"rustup",
&["doc", "--path", "--toolchain", "nightly"],
["doc", "--path", "--toolchain", "nightly"],
);
clitools::env(config, &mut cmd);

Expand All @@ -1989,7 +1989,7 @@ fn docs_topical_with_path() {
expect_ok(config, &["rustup", "toolchain", "install", "nightly"]);

for (topic, path) in mock::topical_doc_data::test_cases() {
let mut cmd = clitools::cmd(config, "rustup", &["doc", "--path", topic]);
let mut cmd = clitools::cmd(config, "rustup", ["doc", "--path", topic]);
clitools::env(config, &mut cmd);

let out = cmd.output().unwrap();
Expand Down Expand Up @@ -2143,7 +2143,7 @@ fn check_unix_settings_fallback() {
)
.unwrap();

let mut cmd = clitools::cmd(config, "rustup", &["default"]);
let mut cmd = clitools::cmd(config, "rustup", ["default"]);
clitools::env(config, &mut cmd);

// Override the path to the fallback settings file to be the mock file
Expand Down Expand Up @@ -2191,7 +2191,7 @@ fn dont_warn_on_partial_build() {
let mut cmd = clitools::cmd(
config,
"rustup",
&["toolchain", "install", &format!("nightly-{}", arch)],
["toolchain", "install", &format!("nightly-{}", arch)],
);
clitools::env(config, &mut cmd);
let out = cmd.output().unwrap();
Expand Down
Loading

0 comments on commit 3331f34

Please sign in to comment.