Skip to content

Commit

Permalink
Auto merge of #5876 - matthiaskrgr:clippy_2, r=alexcrichton
Browse files Browse the repository at this point in the history
fix a bunch of clippy warnings

 (invocation: cargo clippy --all-targets --all-features -- --cap-lints warn )
  • Loading branch information
bors committed Aug 12, 2018
2 parents 972ccba + 8798bf0 commit ae97799
Show file tree
Hide file tree
Showing 25 changed files with 89 additions and 88 deletions.
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
} else {
state.running(&cmd);
let output = if extra_verbose {
state.capture_output(cmd, true)
state.capture_output(&cmd, true)
} else {
cmd.exec_with_output()
};
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/job_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl<'a> JobState<'a> {

pub fn capture_output(
&self,
cmd: ProcessBuilder,
cmd: &ProcessBuilder,
print_output: bool,
) -> CargoResult<Output> {
cmd.exec_with_streaming(
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl Executor for DefaultExecutor {
_mode: CompileMode,
state: &job_queue::JobState<'_>,
) -> CargoResult<()> {
state.capture_output(cmd, false).map(drop)
state.capture_output(&cmd, false).map(drop)
}
}

Expand Down Expand Up @@ -643,7 +643,7 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
false,
).map(drop)
} else if should_capture_output {
state.capture_output(rustdoc, false).map(drop)
state.capture_output(&rustdoc, false).map(drop)
} else {
rustdoc.exec()
};
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl fmt::Display for VersionInfo {
if let Some(channel) = self.cfg_info.as_ref().map(|ci| &ci.release_channel) {
if channel != "stable" {
write!(f, "-{}", channel)?;
let empty = String::from("");
let empty = String::new();
write!(f, "{}", self.pre_release.as_ref().unwrap_or(&empty))?;
}
};
Expand Down
9 changes: 3 additions & 6 deletions src/cargo/ops/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ fn rustfix_crate(lock_addr: &str, rustc: &Path, filename: &Path, args: &FixArgs)
rustfix_and_fix(&mut fixes, rustc, filename, args)?;
let mut progress_yet_to_be_made = false;
for (path, file) in fixes.files.iter_mut() {
if file.errors_applying_fixes.len() == 0 {
if file.errors_applying_fixes.is_empty() {
continue
}
// If anything was successfully fixed *and* there's at least one
Expand Down Expand Up @@ -523,7 +523,7 @@ impl FixArgs {
ret.prepare_for_edition = PrepareFor::Next;
}
ret.idioms = env::var(IDIOMS_ENV).is_ok();
return ret
ret
}

fn apply(&self, cmd: &mut Command) {
Expand All @@ -535,10 +535,7 @@ impl FixArgs {
if let Some(edition) = &self.enabled_edition {
cmd.arg("--edition").arg(edition);
if self.idioms {
match &edition[..] {
"2018" => { cmd.arg("-Wrust-2018-idioms"); }
_ => {}
}
if edition == "2018" { cmd.arg("-Wrust-2018-idioms"); }
}
}
match &self.prepare_for_edition {
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/diagnostic_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ guide can be found at
file,
match edition {
Some(s) => format!("with the {} edition", s),
None => format!("without an edition"),
None => "without an edition".to_string(),
},
))?;
Ok(())
Expand Down
8 changes: 4 additions & 4 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,12 +1024,12 @@ fn cargo_compile_with_downloaded_dependency_with_offline() {
p2.cargo("build")
.masquerade_as_nightly_cargo()
.arg("-Zoffline"),
execs().with_stderr(format!(
execs().with_stderr(
"\
[COMPILING] present_dep v1.2.3
[COMPILING] bar v0.1.0 ([..])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]"
)),
),
);
}

Expand Down Expand Up @@ -4439,7 +4439,7 @@ fn target_edition_feature_gated() {

assert_that(
p.cargo("build").arg("-v").masquerade_as_nightly_cargo(),
execs().with_status(101).with_stderr(format!(
execs().with_status(101).with_stderr(
"\
error: failed to parse manifest at `[..]`
Expand All @@ -4451,7 +4451,7 @@ Caused by:
consider adding `cargo-features = [\"edition\"]` to the manifest
"
)),
),
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn multiple_installs() {

#[test]
fn concurrent_installs() {
const LOCKED_BUILD: &'static str = "waiting for file lock on build directory";
const LOCKED_BUILD: &str = "waiting for file lock on build directory";

pkg("foo", "0.0.1");
pkg("bar", "0.0.1");
Expand Down
4 changes: 3 additions & 1 deletion tests/testsuite/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use cargo::util::toml::{self, VecStringOrBool as VSOB};
use cargo::CargoError;
use support::{execs, lines_match, paths, project};
use support::hamcrest::assert_that;
use std::borrow::Borrow;
use std::collections;
use std::fs;

Expand Down Expand Up @@ -68,8 +69,9 @@ fn new_config(env: &[(&str, &str)]) -> Config {
config
}

fn assert_error(error: CargoError, msgs: &str) {
fn assert_error<E: Borrow<CargoError>>(error: E, msgs: &str) {
let causes = error
.borrow()
.iter_chain()
.map(|e| e.to_string())
.collect::<Vec<_>>()
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/corrupt_git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn deleting_database_files() {

let mut files = Vec::new();
find_files(&paths::home().join(".cargo/git/db"), &mut files);
assert!(files.len() > 0);
assert!(!files.is_empty());

let log = "cargo::sources::git=trace";
for file in files {
Expand Down Expand Up @@ -120,7 +120,7 @@ fn deleting_checkout_files() {
.join(".git");
let mut files = Vec::new();
find_files(&dir, &mut files);
assert!(files.len() > 0);
assert!(!files.is_empty());

let log = "cargo::sources::git=trace";
for file in files {
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ fn doc_same_name() {

#[test]
fn doc_target() {
const TARGET: &'static str = "arm-unknown-linux-gnueabihf";
const TARGET: &str = "arm-unknown-linux-gnueabihf";

let p = project()
.file(
Expand Down
12 changes: 6 additions & 6 deletions tests/testsuite/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn cargo_compile_simple_git_dep() {
[COMPILING] dep1 v0.5.0 ({}#[..])\n\
[COMPILING] foo v0.5.0 ({})\n\
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n",
path2url(git_root.clone()),
path2url(&git_root),
path2url(git_root),
path2url(root)
)),
Expand Down Expand Up @@ -146,7 +146,7 @@ fn cargo_compile_offline_with_cached_git_dep() {
rev = "{}"
"#,
git_project.url(),
rev1.clone()
rev1
),
)
.file("src/main.rs", "fn main(){}")
Expand All @@ -166,7 +166,7 @@ fn cargo_compile_offline_with_cached_git_dep() {
rev = "{}"
"#,
git_project.url(),
rev2.clone()
rev2
).as_bytes())
.unwrap();
assert_that(prj.cargo("build"), execs());
Expand Down Expand Up @@ -303,7 +303,7 @@ fn cargo_compile_git_dep_branch() {
[COMPILING] dep1 v0.5.0 ({}?branch=branchy#[..])\n\
[COMPILING] foo v0.5.0 ({})\n\
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n",
path2url(git_root.clone()),
path2url(&git_root),
path2url(git_root),
path2url(root)
)),
Expand Down Expand Up @@ -376,7 +376,7 @@ fn cargo_compile_git_dep_tag() {
[COMPILING] dep1 v0.5.0 ({}?tag=v0.1.0#[..])\n\
[COMPILING] foo v0.5.0 ({})\n\
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n",
path2url(git_root.clone()),
path2url(&git_root),
path2url(git_root),
path2url(root)
)),
Expand Down Expand Up @@ -2674,7 +2674,7 @@ fn invalid_git_dependency_manifest() {
\n\
Caused by:\n \
duplicate key: `categories` for key `project`",
path2url(git_root.clone()),
path2url(&git_root),
path2url(git_root),
)),
);
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ fn gitignore_no_newline_in_new() {
.unwrap()
.read_to_string(&mut contents)
.unwrap();
assert!(!contents.starts_with("\n"));
assert!(!contents.starts_with('\n'));
}

#[test]
Expand Down Expand Up @@ -446,7 +446,7 @@ fn mercurial_no_newline_in_new() {
.unwrap()
.read_to_string(&mut contents)
.unwrap();
assert!(!contents.starts_with("\n"));
assert!(!contents.starts_with('\n'));
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn check_token(expected_token: &str, registry: Option<&str>) -> bool {
.get("registry")
.and_then(|registry_table| registry_table.get("token"))
.and_then(|v| match v {
&toml::Value::String(ref token) => Some(token.as_str().to_string()),
toml::Value::String(ref token) => Some(token.as_str().to_string()),
_ => None,
}),
_ => None,
Expand Down
2 changes: 2 additions & 0 deletions tests/testsuite/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![deny(warnings)]
#![cfg_attr(feature = "cargo-clippy", allow(blacklisted_name))]
#![cfg_attr(feature = "cargo-clippy", allow(explicit_iter_loop))]

extern crate bufstream;
extern crate cargo;
Expand Down
10 changes: 5 additions & 5 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ fn test_edition_malformed() {

assert_that(
p.cargo("build").arg("-v").masquerade_as_nightly_cargo(),
execs().with_status(101).with_stderr(format!(
execs().with_status(101).with_stderr(
"\
error: failed to parse manifest at `[..]`
Expand All @@ -1025,8 +1025,8 @@ Caused by:
Caused by:
supported edition values are `2015` or `2018`, but `chicken` is unknown
"
)),
".to_string()
),
);
}

Expand All @@ -1048,7 +1048,7 @@ fn test_edition_nightly() {

assert_that(
p.cargo("build").arg("-v").masquerade_as_nightly_cargo(),
execs().with_status(101).with_stderr(format!(
execs().with_status(101).with_stderr(
"\
error: failed to parse manifest at `[..]`
Expand All @@ -1060,7 +1060,7 @@ Caused by:
consider adding `cargo-features = [\"edition\"]` to the manifest
"
)),
),
);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ fn remove_patch() {
File::create(p.root().join("Cargo.toml"))
.unwrap()
.write_all(
r#"
br#"
[package]
name = "foo"
version = "0.0.1"
Expand All @@ -713,7 +713,7 @@ fn remove_patch() {
[patch.crates-io]
bar = { path = 'bar' }
"#.as_bytes(),
"#,
)
.unwrap();
assert_that(p.cargo("build"), execs());
Expand Down
28 changes: 14 additions & 14 deletions tests/testsuite/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ See [..]
// Skip the metadata payload and the size of the tarball
let mut sz = [0; 4];
assert_eq!(f.read(&mut sz).unwrap(), 4);
let sz = ((sz[0] as u32) << 0) | ((sz[1] as u32) << 8) | ((sz[2] as u32) << 16)
| ((sz[3] as u32) << 24);
f.seek(SeekFrom::Current(sz as i64 + 4)).unwrap();
let sz = (u32::from(sz[0]) << 0) | (u32::from(sz[1]) << 8) | (u32::from(sz[2]) << 16)
| (u32::from(sz[3]) << 24);
f.seek(SeekFrom::Current(i64::from(sz) + 4)).unwrap();

// Verify the tarball
let mut rdr = GzDecoder::new(f);
Expand Down Expand Up @@ -127,9 +127,9 @@ See [..]
// Skip the metadata payload and the size of the tarball
let mut sz = [0; 4];
assert_eq!(f.read(&mut sz).unwrap(), 4);
let sz = ((sz[0] as u32) << 0) | ((sz[1] as u32) << 8) | ((sz[2] as u32) << 16)
| ((sz[3] as u32) << 24);
f.seek(SeekFrom::Current(sz as i64 + 4)).unwrap();
let sz = (u32::from(sz[0]) << 0) | (u32::from(sz[1]) << 8) | (u32::from(sz[2]) << 16)
| (u32::from(sz[3]) << 24);
f.seek(SeekFrom::Current(i64::from(sz) + 4)).unwrap();

// Verify the tarball
let mut rdr = GzDecoder::new(f);
Expand Down Expand Up @@ -205,15 +205,15 @@ See [..]
// Skip the metadata payload and the size of the tarball
let mut sz = [0; 4];
assert_eq!(f.read(&mut sz).unwrap(), 4);
let sz = ((sz[0] as u32) << 0) | ((sz[1] as u32) << 8) | ((sz[2] as u32) << 16)
| ((sz[3] as u32) << 24);
f.seek(SeekFrom::Current(sz as i64 + 4)).unwrap();
let sz = (u32::from(sz[0]) << 0) | (u32::from(sz[1]) << 8) | (u32::from(sz[2]) << 16)
| (u32::from(sz[3]) << 24);
f.seek(SeekFrom::Current(i64::from(sz) + 4)).unwrap();

// Verify the tarball
let mut rdr = GzDecoder::new(f);
assert_eq!(
rdr.header().unwrap().filename().unwrap(),
"foo-0.0.1.crate".as_bytes()
b"foo-0.0.1.crate"
);
let mut contents = Vec::new();
rdr.read_to_end(&mut contents).unwrap();
Expand Down Expand Up @@ -285,15 +285,15 @@ See [..]
// Skip the metadata payload and the size of the tarball
let mut sz = [0; 4];
assert_eq!(f.read(&mut sz).unwrap(), 4);
let sz = ((sz[0] as u32) << 0) | ((sz[1] as u32) << 8) | ((sz[2] as u32) << 16)
| ((sz[3] as u32) << 24);
f.seek(SeekFrom::Current(sz as i64 + 4)).unwrap();
let sz = (u32::from(sz[0]) << 0) | (u32::from(sz[1]) << 8) | (u32::from(sz[2]) << 16)
| (u32::from(sz[3]) << 24);
f.seek(SeekFrom::Current(i64::from(sz) + 4)).unwrap();

// Verify the tarball
let mut rdr = GzDecoder::new(f);
assert_eq!(
rdr.header().unwrap().filename().unwrap(),
"foo-0.0.1.crate".as_bytes()
b"foo-0.0.1.crate"
);
let mut contents = Vec::new();
rdr.read_to_end(&mut contents).unwrap();
Expand Down
Loading

0 comments on commit ae97799

Please sign in to comment.