Skip to content

Commit

Permalink
Auto merge of #1012 - neosilky:clippy-fixes, r=brson
Browse files Browse the repository at this point in the history
Fix up a bunch of things indicated by clippy

Let me know if anything should be reverted.
  • Loading branch information
bors committed Mar 27, 2017
2 parents 62037a2 + 2c41ddf commit 2ae338d
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/rustup-cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ pub fn rustc_version(toolchain: &Toolchain) -> String {
toolchain.set_ldpath(&mut cmd);

let out= cmd.output().ok();
let out = out.into_iter().filter(|o| o.status.success()).next();
let out = out.into_iter().find(|o| o.status.success());
let stdout = out.and_then(|o| String::from_utf8(o.stdout).ok());
let line1 = stdout.and_then(|o| o.lines().next().map(|l| l.to_owned()));

Expand Down Expand Up @@ -375,7 +375,7 @@ pub fn report_error(e: &Error) {
}
}

return false;
false
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/rustup-cli/download_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ impl DownloadTracker {
}

pub fn handle_notification(&mut self, n: &Notification) -> bool {
match n {
&Notification::Install(In::Utils(Un::DownloadContentLengthReceived(content_len))) => {
match *n {
Notification::Install(In::Utils(Un::DownloadContentLengthReceived(content_len))) => {
self.content_length_received(content_len);

true
}
&Notification::Install(In::Utils(Un::DownloadDataReceived(data))) => {
Notification::Install(In::Utils(Un::DownloadDataReceived(data))) => {
if tty::stdout_isatty() && self.term.is_some() {
self.data_received(data.len());
}
true
}
&Notification::Install(In::Utils(Un::DownloadFinished)) => {
Notification::Install(In::Utils(Un::DownloadFinished)) => {
self.download_finished();
true
}
Expand Down
2 changes: 1 addition & 1 deletion src/rustup-cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn run_multirust() -> Result<()> {
do_compatibility_hacks();

// The name of arg0 determines how the program is going to behave
let arg0 = env::args().next().map(|a| PathBuf::from(a));
let arg0 = env::args().next().map(PathBuf::from);
let name = arg0.as_ref()
.and_then(|a| a.file_stem())
.and_then(|a| a.to_str());
Expand Down
4 changes: 2 additions & 2 deletions src/rustup-cli/proxy_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn main() -> Result<()> {

let mut args = env::args();

let arg0 = args.next().map(|a| PathBuf::from(a));
let arg0 = args.next().map(PathBuf::from);
let arg0 = arg0.as_ref()
.and_then(|a| a.file_name())
.and_then(|a| a.to_str());
Expand All @@ -25,7 +25,7 @@ pub fn main() -> Result<()> {
let arg1 = args.next();
let toolchain = arg1.as_ref()
.and_then(|arg1| {
if arg1.starts_with("+") {
if arg1.starts_with('+') {
Some(&arg1[1..])
} else {
None
Expand Down
4 changes: 2 additions & 2 deletions src/rustup-cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ fn update_bare_triple_check(cfg: &Cfg, name: &str) -> Result<()> {
continue;
}
if let Ok(desc) = PartialToolchainDesc::from_str(&t) {
fn triple_comp_eq(given: &String, from_desc: Option<&String>) -> bool {
fn triple_comp_eq(given: &str, from_desc: Option<&String>) -> bool {
from_desc.map_or(false, |s| *s == *given)
}

Expand All @@ -407,7 +407,7 @@ fn update_bare_triple_check(cfg: &Cfg, name: &str) -> Result<()> {
1 => println!("\nyou may use the following toolchain: {}\n", candidates[0]),
_ => {
println!("\nyou may use one of the following toolchains:");
for n in candidates.iter() {
for n in &candidates {
println!("{}", n);
}
println!("");
Expand Down
26 changes: 13 additions & 13 deletions src/rustup-cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ static TOOLS: &'static [&'static str]
static UPDATE_ROOT: &'static str
= "https://static.rust-lang.org/rustup";

/// CARGO_HOME suitable for display, possibly with $HOME
/// `CARGO_HOME` suitable for display, possibly with $HOME
/// substituted for the directory prefix
fn canonical_cargo_home() -> Result<String> {
let path = try!(utils::cargo_home());
Expand All @@ -211,8 +211,8 @@ fn canonical_cargo_home() -> Result<String> {
}

/// Installing is a simple matter of coping the running binary to
/// CARGO_HOME/bin, hardlinking the various Rust tools to it,
/// and and adding CARGO_HOME/bin to PATH.
/// `CARGO_HOME`/bin, hardlinking the various Rust tools to it,
/// and and adding `CARGO_HOME`/bin to PATH.
pub fn install(no_prompt: bool, verbose: bool,
mut opts: InstallOpts) -> Result<()> {

Expand Down Expand Up @@ -344,7 +344,7 @@ fn do_pre_install_sanity_checks() -> Result<()> {
rustup_sh_version_path.map(|p| p.exists()) == Some(true);
let old_multirust_meta_exists = if let Some(ref multirust_version_path) = multirust_version_path {
multirust_version_path.exists() && {
let version = utils::read_file("old-multirust", &multirust_version_path);
let version = utils::read_file("old-multirust", multirust_version_path);
let version = version.unwrap_or(String::new());
let version = version.parse().unwrap_or(0);
let cutoff_version = 12; // First rustup version
Expand Down Expand Up @@ -417,7 +417,7 @@ fn do_anti_sudo_check(no_prompt: bool) -> Result<()> {
let mut pwd = unsafe { mem::uninitialized::<c::passwd>() };
let mut pwdp: *mut c::passwd = ptr::null_mut();
let rv = unsafe { c::getpwuid_r(c::geteuid(), &mut pwd, mem::transmute(&mut buf), buf.len(), &mut pwdp) };
if rv != 0 || pwdp == ptr::null_mut() {
if rv != 0 || pwdp.is_null() {
warn!("getpwuid_r: couldn't get user data");
return false;
}
Expand All @@ -426,7 +426,7 @@ fn do_anti_sudo_check(no_prompt: bool) -> Result<()> {
let env_home = env_home.as_ref().map(Deref::deref);
match (env_home, pw_dir) {
(None, _) | (_, None) => false,
(Some(ref eh), Some(ref pd)) => eh != pd
(Some(eh), Some(pd)) => eh != pd
}
}

Expand Down Expand Up @@ -492,7 +492,7 @@ fn pre_install_msg(no_modify_path: bool) -> Result<String> {
None
}
}).collect::<Vec<_>>();
assert!(rcfiles.len() == 1); // Only modifying .profile
assert_eq!(rcfiles.len(), 1); // Only modifying .profile
Ok(format!(pre_install_msg_unix!(),
cargo_home_bin = cargo_home_bin.display(),
rcfiles = rcfiles[0]))
Expand Down Expand Up @@ -981,7 +981,7 @@ fn get_add_path_methods() -> Vec<PathUpdateMethod> {
let profile = utils::home_dir().map(|p| p.join(".profile"));
let rcfiles = vec![profile].into_iter().filter_map(|f|f);

rcfiles.map(|f| PathUpdateMethod::RcFile(f)).collect()
rcfiles.map(PathUpdateMethod::RcFile).collect()
}

fn shell_export_string() -> Result<String> {
Expand Down Expand Up @@ -1119,7 +1119,7 @@ fn get_remove_path_methods() -> Result<Vec<PathUpdateMethod>> {
file.contains(addition)
});

Ok(matching_rcfiles.map(|f| PathUpdateMethod::RcFile(f)).collect())
Ok(matching_rcfiles.map(PathUpdateMethod::RcFile).collect())
}

#[cfg(windows)]
Expand Down Expand Up @@ -1213,7 +1213,7 @@ fn do_remove_from_path(methods: &[PathUpdateMethod]) -> Result<()> {
Ok(())
}

/// Self update downloads rustup-init to CARGO_HOME/bin/rustup-init
/// Self update downloads rustup-init to `CARGO_HOME`/bin/rustup-init
/// and runs it.
///
/// It does a few things to accomodate self-delete problems on windows:
Expand All @@ -1226,7 +1226,7 @@ fn do_remove_from_path(methods: &[PathUpdateMethod]) -> Result<()> {
///
/// Because it's again difficult for rustup-init to delete itself
/// (and on windows this process will not be running to do it),
/// rustup-init is stored in CARGO_HOME/bin, and then deleted next
/// rustup-init is stored in `CARGO_HOME`/bin, and then deleted next
/// time rustup runs.
pub fn update() -> Result<()> {
if NEVER_SELF_UPDATE {
Expand All @@ -1236,7 +1236,7 @@ pub fn update() -> Result<()> {
}
let setup_path = try!(prepare_update());
if let Some(ref p) = setup_path {
let version = match get_new_rustup_version(&p) {
let version = match get_new_rustup_version(p) {
Some(new_version) => parse_new_rustup_version(new_version),
None => {
err!("failed to get rustup version");
Expand Down Expand Up @@ -1376,7 +1376,7 @@ pub fn run_update(setup_path: &Path) -> Result<()> {
}

/// This function is as the final step of a self-upgrade. It replaces
/// CARGO_HOME/bin/rustup with the running exe, and updates the the
/// `CARGO_HOME`/bin/rustup with the running exe, and updates the the
/// links to it. On windows this will run *after* the original
/// rustup process exits.
#[cfg(unix)]
Expand Down
4 changes: 2 additions & 2 deletions src/rustup-cli/term2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! This provides wrappers around the StdoutTerminal and StderrTerminal types
//! that does not fail if StdoutTerminal etc can't be constructed, which happens
//! This provides wrappers around the `StdoutTerminal` and `StderrTerminal` types
//! that does not fail if `StdoutTerminal` etc can't be constructed, which happens
//! if TERM isn't defined.

use std::io;
Expand Down
4 changes: 2 additions & 2 deletions tests/cli-exact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ fn enable_telemetry() {
expect_ok_ex(config,
&["rustup", "telemetry", "enable"],
r"",
&format!("info: telemetry set to 'on'\n"));
"info: telemetry set to 'on'\n");
});
}

Expand All @@ -312,6 +312,6 @@ fn disable_telemetry() {
expect_ok_ex(config,
&["rustup", "telemetry", "disable"],
r"",
&format!("info: telemetry set to 'off'\n"));
"info: telemetry set to 'off'\n");
});
}
2 changes: 1 addition & 1 deletion tests/cli-inst-interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn setup(f: &Fn(&Config)) {
}

fn run_input(config: &Config, args: &[&str], input: &str) -> SanitizedOutput {
let mut cmd = clitools::cmd(config, &args[0], &args[1..]);
let mut cmd = clitools::cmd(config, args[0], &args[1..]);
clitools::env(config, &mut cmd);

cmd.stdin(Stdio::piped());
Expand Down
12 changes: 6 additions & 6 deletions tests/cli-misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ fn subcommand_required_for_target() {
clitools::env(config, &mut cmd);
let out = cmd.output().unwrap();
assert!(!out.status.success());
assert!(out.status.code().unwrap() != 101);
assert_ne!(out.status.code().unwrap(), 101);
});
}

Expand All @@ -185,7 +185,7 @@ fn subcommand_required_for_toolchain() {
clitools::env(config, &mut cmd);
let out = cmd.output().unwrap();
assert!(!out.status.success());
assert!(out.status.code().unwrap() != 101);
assert_ne!(out.status.code().unwrap(), 101);
});
}

Expand All @@ -198,7 +198,7 @@ fn subcommand_required_for_override() {
clitools::env(config, &mut cmd);
let out = cmd.output().unwrap();
assert!(!out.status.success());
assert!(out.status.code().unwrap() != 101);
assert_ne!(out.status.code().unwrap(), 101);
});
}

Expand All @@ -211,7 +211,7 @@ fn subcommand_required_for_self() {
clitools::env(config, &mut cmd);
let out = cmd.output().unwrap();
assert!(!out.status.success());
assert!(out.status.code().unwrap() != 101);
assert_ne!(out.status.code().unwrap(), 101);
});
}

Expand Down Expand Up @@ -372,7 +372,7 @@ fn telemetry_supports_huge_output() {
setup(&|config| {
expect_ok(config, &["rustup", "default", "stable"]);
expect_ok(config, &["rustup", "telemetry", "enable"]);
expect_timeout_ok(&config, StdDuration::from_secs(5), &["rustc", "--huge-output"]);
expect_timeout_ok(config, StdDuration::from_secs(5), &["rustc", "--huge-output"]);
expect_stdout_ok(config, &["rustup", "telemetry", "analyze"], "'E0428': 10000")
})
}
Expand Down Expand Up @@ -402,6 +402,6 @@ fn telemetry_cleanup_removes_old_files() {
let contents = out.unwrap();
let count = contents.count();

assert!(count == 100);
assert_eq!(count, 100);
});
}
2 changes: 1 addition & 1 deletion tests/cli-rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ fn show_toolchain_env() {
let out = cmd.output().unwrap();
assert!(out.status.success());
let stdout = String::from_utf8(out.stdout).unwrap();
assert!(&stdout == for_host!(r"Default host: {0}
assert_eq!(&stdout, for_host!(r"Default host: {0}
nightly-{0} (environment override by RUSTUP_TOOLCHAIN)
1.3.0 (hash-n-2)
Expand Down
4 changes: 2 additions & 2 deletions tests/cli-self-upd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ fn update_updates_rustup_bin() {

let after_hash = calc_hash(bin);

assert!(before_hash != after_hash);
assert_ne!(before_hash, after_hash);
});
}

Expand Down Expand Up @@ -610,7 +610,7 @@ fn rustup_self_updates() {

let after_hash = calc_hash(bin);

assert!(before_hash != after_hash);
assert_ne!(before_hash, after_hash);
})
}

Expand Down
2 changes: 1 addition & 1 deletion tests/cli-v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fn bad_sha_on_manifest() {
let sha_file = config.distdir.join("dist/channel-rust-nightly.sha256");
let sha_str = rustup_utils::raw::read_file(&sha_file).unwrap();
let mut sha_bytes = sha_str.into_bytes();
&mut sha_bytes[..10].clone_from_slice(b"aaaaaaaaaa");
sha_bytes[..10].clone_from_slice(b"aaaaaaaaaa");
let sha_str = String::from_utf8(sha_bytes).unwrap();
rustup_utils::raw::write_file(&sha_file, &sha_str).unwrap();
expect_err(config, &["rustup", "default", "nightly"],
Expand Down
2 changes: 1 addition & 1 deletion tests/cli-v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ fn bad_sha_on_manifest() {
let sha_file = config.distdir.join("dist/channel-rust-nightly.toml.sha256");
let sha_str = rustup_utils::raw::read_file(&sha_file).unwrap();
let mut sha_bytes = sha_str.into_bytes();
&mut sha_bytes[..10].clone_from_slice(b"aaaaaaaaaa");
sha_bytes[..10].clone_from_slice(b"aaaaaaaaaa");
let sha_str = String::from_utf8(sha_bytes).unwrap();
rustup_utils::raw::write_file(&sha_file, &sha_str).unwrap();
expect_err(config, &["rustup", "default", "nightly"],
Expand Down

0 comments on commit 2ae338d

Please sign in to comment.