Skip to content

Commit 8798bf0

Browse files
committed
fix a bunch of clippy warnings (invocation: cargo clippy --all-targets --all-features -- --cap-lints warn )
Special thanks to dwijnand for helping me with this! :)
1 parent 578e253 commit 8798bf0

25 files changed

+89
-88
lines changed

src/cargo/core/compiler/custom_build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
322322
} else {
323323
state.running(&cmd);
324324
let output = if extra_verbose {
325-
state.capture_output(cmd, true)
325+
state.capture_output(&cmd, true)
326326
} else {
327327
cmd.exec_with_output()
328328
};

src/cargo/core/compiler/job_queue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'a> JobState<'a> {
110110

111111
pub fn capture_output(
112112
&self,
113-
cmd: ProcessBuilder,
113+
cmd: &ProcessBuilder,
114114
print_output: bool,
115115
) -> CargoResult<Output> {
116116
cmd.exec_with_streaming(

src/cargo/core/compiler/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl Executor for DefaultExecutor {
118118
_mode: CompileMode,
119119
state: &job_queue::JobState<'_>,
120120
) -> CargoResult<()> {
121-
state.capture_output(cmd, false).map(drop)
121+
state.capture_output(&cmd, false).map(drop)
122122
}
123123
}
124124

@@ -645,7 +645,7 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
645645
false,
646646
).map(drop)
647647
} else if should_capture_output {
648-
state.capture_output(rustdoc, false).map(drop)
648+
state.capture_output(&rustdoc, false).map(drop)
649649
} else {
650650
rustdoc.exec()
651651
};

src/cargo/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl fmt::Display for VersionInfo {
110110
if let Some(channel) = self.cfg_info.as_ref().map(|ci| &ci.release_channel) {
111111
if channel != "stable" {
112112
write!(f, "-{}", channel)?;
113-
let empty = String::from("");
113+
let empty = String::new();
114114
write!(f, "{}", self.pre_release.as_ref().unwrap_or(&empty))?;
115115
}
116116
};

src/cargo/ops/fix.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ fn rustfix_crate(lock_addr: &str, rustc: &Path, filename: &Path, args: &FixArgs)
270270
rustfix_and_fix(&mut fixes, rustc, filename, args)?;
271271
let mut progress_yet_to_be_made = false;
272272
for (path, file) in fixes.files.iter_mut() {
273-
if file.errors_applying_fixes.len() == 0 {
273+
if file.errors_applying_fixes.is_empty() {
274274
continue
275275
}
276276
// If anything was successfully fixed *and* there's at least one
@@ -523,7 +523,7 @@ impl FixArgs {
523523
ret.prepare_for_edition = PrepareFor::Next;
524524
}
525525
ret.idioms = env::var(IDIOMS_ENV).is_ok();
526-
return ret
526+
ret
527527
}
528528

529529
fn apply(&self, cmd: &mut Command) {
@@ -535,10 +535,7 @@ impl FixArgs {
535535
if let Some(edition) = &self.enabled_edition {
536536
cmd.arg("--edition").arg(edition);
537537
if self.idioms {
538-
match &edition[..] {
539-
"2018" => { cmd.arg("-Wrust-2018-idioms"); }
540-
_ => {}
541-
}
538+
if edition == "2018" { cmd.arg("-Wrust-2018-idioms"); }
542539
}
543540
}
544541
match &self.prepare_for_edition {

src/cargo/util/diagnostic_server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ guide can be found at
199199
file,
200200
match edition {
201201
Some(s) => format!("with the {} edition", s),
202-
None => format!("without an edition"),
202+
None => "without an edition".to_string(),
203203
},
204204
))?;
205205
Ok(())

tests/testsuite/build.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,12 +1024,12 @@ fn cargo_compile_with_downloaded_dependency_with_offline() {
10241024
p2.cargo("build")
10251025
.masquerade_as_nightly_cargo()
10261026
.arg("-Zoffline"),
1027-
execs().with_stderr(format!(
1027+
execs().with_stderr(
10281028
"\
10291029
[COMPILING] present_dep v1.2.3
10301030
[COMPILING] bar v0.1.0 ([..])
10311031
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]"
1032-
)),
1032+
),
10331033
);
10341034
}
10351035

@@ -4439,7 +4439,7 @@ fn target_edition_feature_gated() {
44394439

44404440
assert_that(
44414441
p.cargo("build").arg("-v").masquerade_as_nightly_cargo(),
4442-
execs().with_status(101).with_stderr(format!(
4442+
execs().with_status(101).with_stderr(
44434443
"\
44444444
error: failed to parse manifest at `[..]`
44454445
@@ -4451,7 +4451,7 @@ Caused by:
44514451
44524452
consider adding `cargo-features = [\"edition\"]` to the manifest
44534453
"
4454-
)),
4454+
),
44554455
);
44564456
}
44574457

tests/testsuite/concurrent.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn multiple_installs() {
5252

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

5757
pkg("foo", "0.0.1");
5858
pkg("bar", "0.0.1");

tests/testsuite/config.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use cargo::util::toml::{self, VecStringOrBool as VSOB};
44
use cargo::CargoError;
55
use support::{execs, lines_match, paths, project};
66
use support::hamcrest::assert_that;
7+
use std::borrow::Borrow;
78
use std::collections;
89
use std::fs;
910

@@ -68,8 +69,9 @@ fn new_config(env: &[(&str, &str)]) -> Config {
6869
config
6970
}
7071

71-
fn assert_error(error: CargoError, msgs: &str) {
72+
fn assert_error<E: Borrow<CargoError>>(error: E, msgs: &str) {
7273
let causes = error
74+
.borrow()
7375
.iter_chain()
7476
.map(|e| e.to_string())
7577
.collect::<Vec<_>>()

tests/testsuite/corrupt_git.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn deleting_database_files() {
3838

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

4343
let log = "cargo::sources::git=trace";
4444
for file in files {
@@ -120,7 +120,7 @@ fn deleting_checkout_files() {
120120
.join(".git");
121121
let mut files = Vec::new();
122122
find_files(&dir, &mut files);
123-
assert!(files.len() > 0);
123+
assert!(!files.is_empty());
124124

125125
let log = "cargo::sources::git=trace";
126126
for file in files {

tests/testsuite/doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ fn doc_same_name() {
626626

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

631631
let p = project()
632632
.file(

tests/testsuite/git.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn cargo_compile_simple_git_dep() {
6161
[COMPILING] dep1 v0.5.0 ({}#[..])\n\
6262
[COMPILING] foo v0.5.0 ({})\n\
6363
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n",
64-
path2url(git_root.clone()),
64+
path2url(&git_root),
6565
path2url(git_root),
6666
path2url(root)
6767
)),
@@ -146,7 +146,7 @@ fn cargo_compile_offline_with_cached_git_dep() {
146146
rev = "{}"
147147
"#,
148148
git_project.url(),
149-
rev1.clone()
149+
rev1
150150
),
151151
)
152152
.file("src/main.rs", "fn main(){}")
@@ -166,7 +166,7 @@ fn cargo_compile_offline_with_cached_git_dep() {
166166
rev = "{}"
167167
"#,
168168
git_project.url(),
169-
rev2.clone()
169+
rev2
170170
).as_bytes())
171171
.unwrap();
172172
assert_that(prj.cargo("build"), execs());
@@ -303,7 +303,7 @@ fn cargo_compile_git_dep_branch() {
303303
[COMPILING] dep1 v0.5.0 ({}?branch=branchy#[..])\n\
304304
[COMPILING] foo v0.5.0 ({})\n\
305305
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n",
306-
path2url(git_root.clone()),
306+
path2url(&git_root),
307307
path2url(git_root),
308308
path2url(root)
309309
)),
@@ -376,7 +376,7 @@ fn cargo_compile_git_dep_tag() {
376376
[COMPILING] dep1 v0.5.0 ({}?tag=v0.1.0#[..])\n\
377377
[COMPILING] foo v0.5.0 ({})\n\
378378
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]\n",
379-
path2url(git_root.clone()),
379+
path2url(&git_root),
380380
path2url(git_root),
381381
path2url(root)
382382
)),
@@ -2674,7 +2674,7 @@ fn invalid_git_dependency_manifest() {
26742674
\n\
26752675
Caused by:\n \
26762676
duplicate key: `categories` for key `project`",
2677-
path2url(git_root.clone()),
2677+
path2url(&git_root),
26782678
path2url(git_root),
26792679
)),
26802680
);

tests/testsuite/init.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ fn gitignore_no_newline_in_new() {
403403
.unwrap()
404404
.read_to_string(&mut contents)
405405
.unwrap();
406-
assert!(!contents.starts_with("\n"));
406+
assert!(!contents.starts_with('\n'));
407407
}
408408

409409
#[test]
@@ -446,7 +446,7 @@ fn mercurial_no_newline_in_new() {
446446
.unwrap()
447447
.read_to_string(&mut contents)
448448
.unwrap();
449-
assert!(!contents.starts_with("\n"));
449+
assert!(!contents.starts_with('\n'));
450450
}
451451

452452
#[test]

tests/testsuite/login.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn check_token(expected_token: &str, registry: Option<&str>) -> bool {
6060
.get("registry")
6161
.and_then(|registry_table| registry_table.get("token"))
6262
.and_then(|v| match v {
63-
&toml::Value::String(ref token) => Some(token.as_str().to_string()),
63+
toml::Value::String(ref token) => Some(token.as_str().to_string()),
6464
_ => None,
6565
}),
6666
_ => None,

tests/testsuite/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#![deny(warnings)]
2+
#![cfg_attr(feature = "cargo-clippy", allow(blacklisted_name))]
3+
#![cfg_attr(feature = "cargo-clippy", allow(explicit_iter_loop))]
24

35
extern crate bufstream;
46
extern crate cargo;

tests/testsuite/package.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ fn test_edition_malformed() {
10161016

10171017
assert_that(
10181018
p.cargo("build").arg("-v").masquerade_as_nightly_cargo(),
1019-
execs().with_status(101).with_stderr(format!(
1019+
execs().with_status(101).with_stderr(
10201020
"\
10211021
error: failed to parse manifest at `[..]`
10221022
@@ -1025,8 +1025,8 @@ Caused by:
10251025
10261026
Caused by:
10271027
supported edition values are `2015` or `2018`, but `chicken` is unknown
1028-
"
1029-
)),
1028+
".to_string()
1029+
),
10301030
);
10311031
}
10321032

@@ -1048,7 +1048,7 @@ fn test_edition_nightly() {
10481048

10491049
assert_that(
10501050
p.cargo("build").arg("-v").masquerade_as_nightly_cargo(),
1051-
execs().with_status(101).with_stderr(format!(
1051+
execs().with_status(101).with_stderr(
10521052
"\
10531053
error: failed to parse manifest at `[..]`
10541054
@@ -1060,7 +1060,7 @@ Caused by:
10601060
10611061
consider adding `cargo-features = [\"edition\"]` to the manifest
10621062
"
1063-
)),
1063+
),
10641064
);
10651065
}
10661066

tests/testsuite/patch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ fn remove_patch() {
702702
File::create(p.root().join("Cargo.toml"))
703703
.unwrap()
704704
.write_all(
705-
r#"
705+
br#"
706706
[package]
707707
name = "foo"
708708
version = "0.0.1"
@@ -713,7 +713,7 @@ fn remove_patch() {
713713
714714
[patch.crates-io]
715715
bar = { path = 'bar' }
716-
"#.as_bytes(),
716+
"#,
717717
)
718718
.unwrap();
719719
assert_that(p.cargo("build"), execs());

tests/testsuite/publish.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ See [..]
5151
// Skip the metadata payload and the size of the tarball
5252
let mut sz = [0; 4];
5353
assert_eq!(f.read(&mut sz).unwrap(), 4);
54-
let sz = ((sz[0] as u32) << 0) | ((sz[1] as u32) << 8) | ((sz[2] as u32) << 16)
55-
| ((sz[3] as u32) << 24);
56-
f.seek(SeekFrom::Current(sz as i64 + 4)).unwrap();
54+
let sz = (u32::from(sz[0]) << 0) | (u32::from(sz[1]) << 8) | (u32::from(sz[2]) << 16)
55+
| (u32::from(sz[3]) << 24);
56+
f.seek(SeekFrom::Current(i64::from(sz) + 4)).unwrap();
5757

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

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

212212
// Verify the tarball
213213
let mut rdr = GzDecoder::new(f);
214214
assert_eq!(
215215
rdr.header().unwrap().filename().unwrap(),
216-
"foo-0.0.1.crate".as_bytes()
216+
b"foo-0.0.1.crate"
217217
);
218218
let mut contents = Vec::new();
219219
rdr.read_to_end(&mut contents).unwrap();
@@ -285,15 +285,15 @@ See [..]
285285
// Skip the metadata payload and the size of the tarball
286286
let mut sz = [0; 4];
287287
assert_eq!(f.read(&mut sz).unwrap(), 4);
288-
let sz = ((sz[0] as u32) << 0) | ((sz[1] as u32) << 8) | ((sz[2] as u32) << 16)
289-
| ((sz[3] as u32) << 24);
290-
f.seek(SeekFrom::Current(sz as i64 + 4)).unwrap();
288+
let sz = (u32::from(sz[0]) << 0) | (u32::from(sz[1]) << 8) | (u32::from(sz[2]) << 16)
289+
| (u32::from(sz[3]) << 24);
290+
f.seek(SeekFrom::Current(i64::from(sz) + 4)).unwrap();
291291

292292
// Verify the tarball
293293
let mut rdr = GzDecoder::new(f);
294294
assert_eq!(
295295
rdr.header().unwrap().filename().unwrap(),
296-
"foo-0.0.1.crate".as_bytes()
296+
b"foo-0.0.1.crate"
297297
);
298298
let mut contents = Vec::new();
299299
rdr.read_to_end(&mut contents).unwrap();

0 commit comments

Comments
 (0)