Skip to content

Commit ec21e12

Browse files
committed
Some clippy fixes.
1 parent 00e4c69 commit ec21e12

File tree

13 files changed

+42
-29
lines changed

13 files changed

+42
-29
lines changed

src/cargo/core/compiler/context/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
219219
self.compilation
220220
.rustdocflags
221221
.entry(unit.pkg.package_id())
222-
.or_insert(rustdocflags.to_vec());
222+
.or_insert_with(|| rustdocflags.to_vec());
223223
}
224224

225225
super::output_depinfo(&mut self, unit)?;

src/cargo/core/compiler/job_queue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
216216

217217
self.queue.queue(*unit, job, queue_deps);
218218
*self.counts.entry(unit.pkg.package_id()).or_insert(0) += 1;
219-
return Ok(());
219+
Ok(())
220220
}
221221

222222
/// Executes all jobs necessary to build the dependency graph.

src/cargo/core/compiler/unit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,6 @@ impl<'a> UnitInterner<'a> {
166166
}
167167
me.cache.insert(Box::new(item.clone()));
168168
let item = me.cache.get(item).unwrap();
169-
return unsafe { &*(&**item as *const UnitInner<'a>) };
169+
unsafe { &*(&**item as *const UnitInner<'a>) }
170170
}
171171
}

src/cargo/core/resolver/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ fn activate(
657657

658658
let candidate = match registry.replacement_summary(candidate_pid) {
659659
Some(replace) => {
660-
if cx.flag_activated(&replace, &method)? && activated {
660+
if cx.flag_activated(replace, &method)? && activated {
661661
return Ok(None);
662662
}
663663
trace!(

src/cargo/core/resolver/resolve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl Resolve {
5555
.find(|d| d.kind() == Kind::Normal)
5656
.and_then(|d| {
5757
if d.is_public() {
58-
Some(dep_package.clone())
58+
Some(*dep_package)
5959
} else {
6060
None
6161
}
@@ -64,7 +64,7 @@ impl Resolve {
6464
})
6565
.collect::<HashSet<PackageId>>();
6666

67-
(p.clone(), public_deps)
67+
(*p, public_deps)
6868
})
6969
.collect();
7070

src/cargo/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
#![cfg_attr(test, deny(warnings))]
2-
#![warn(rust_2018_idioms)]
32
// While we're getting used to 2018:
3+
#![warn(rust_2018_idioms)]
44
// Clippy isn't enforced by CI (@alexcrichton isn't a fan).
5-
#![allow(clippy::boxed_local)] // bug rust-lang-nursery/rust-clippy#1123
5+
#![allow(clippy::blacklisted_name)] // frequently used in tests
66
#![allow(clippy::cyclomatic_complexity)] // large project
77
#![allow(clippy::derive_hash_xor_eq)] // there's an intentional incoherence
88
#![allow(clippy::explicit_into_iter_loop)] // explicit loops are clearer
99
#![allow(clippy::explicit_iter_loop)] // explicit loops are clearer
1010
#![allow(clippy::identity_op)] // used for vertical alignment
1111
#![allow(clippy::implicit_hasher)] // large project
1212
#![allow(clippy::large_enum_variant)] // large project
13+
#![allow(clippy::new_without_default)] // explicit is maybe clearer
1314
#![allow(clippy::redundant_closure)] // closures can be less verbose
1415
#![allow(clippy::redundant_closure_call)] // closures over try catch blocks
1516
#![allow(clippy::too_many_arguments)] // large project
1617
#![allow(clippy::type_complexity)] // there's an exceptionally complex type
1718
#![allow(clippy::wrong_self_convention)] // perhaps `Rc` should be special-cased in Clippy?
1819
#![warn(clippy::needless_borrow)]
1920
#![warn(clippy::redundant_clone)]
21+
// Unit is now interned, and would probably be better as pass-by-copy, but
22+
// doing so causes a lot of & and * shenanigans that makes the code arguably
23+
// less clear and harder to read.
24+
#![allow(clippy::trivially_copy_pass_by_ref)]
25+
// exhaustively destructuring ensures future fields are handled
26+
#![allow(clippy::unneeded_field_pattern)]
2027

2128
use std::fmt;
2229

src/cargo/ops/cargo_package.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ fn tar(
440440
}
441441

442442
if pkg.include_lockfile() {
443-
let new_lock = build_lock(&ws)?;
443+
let new_lock = build_lock(ws)?;
444444

445445
config
446446
.shell()
@@ -609,7 +609,7 @@ fn run_verify(ws: &Workspace<'_>, tar: &FileLock, opts: &PackageOpts<'_>) -> Car
609609
{
610610
// FIXME: Turn this on at some point in the future
611611
//Some(vec!["-D exported_private_dependencies".to_string()])
612-
None
612+
Some(vec![])
613613
} else {
614614
None
615615
};

src/cargo/ops/common_for_install_and_uninstall.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl InstallTracker {
211211
// `cargo install --path ...` is always rebuilt.
212212
return Ok((Freshness::Dirty, duplicates));
213213
}
214-
if matching_duplicates.iter().all(|dupe_pkg_id| {
214+
let is_up_to_date = |dupe_pkg_id| {
215215
let info = self
216216
.v2
217217
.installs
@@ -229,7 +229,8 @@ impl InstallTracker {
229229
&& dupe_pkg_id.source_id() == source_id
230230
&& precise_equal
231231
&& info.is_up_to_date(opts, target, &exes)
232-
}) {
232+
};
233+
if matching_duplicates.iter().all(is_up_to_date) {
233234
Ok((Freshness::Fresh, duplicates))
234235
} else {
235236
Ok((Freshness::Dirty, duplicates))

src/cargo/sources/path.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl<'cfg> PathSource<'cfg> {
145145
.exclude()
146146
.iter()
147147
.chain(pkg.manifest().include().iter())
148-
.any(|p| p.starts_with("!"));
148+
.any(|p| p.starts_with('!'));
149149
// Don't warn about glob mismatch if it doesn't parse.
150150
let glob_is_valid = glob_exclude.is_ok() && glob_include.is_ok() && !has_negate;
151151
let glob_exclude = glob_exclude.unwrap_or_else(|_| Vec::new());
@@ -479,12 +479,9 @@ impl<'cfg> PathSource<'cfg> {
479479
if name.map(|s| s.starts_with('.')) == Some(true) {
480480
continue;
481481
}
482-
if is_root {
482+
if is_root && name == Some("target") {
483483
// Skip Cargo artifacts.
484-
match name {
485-
Some("target") => continue,
486-
_ => {}
487-
}
484+
continue;
488485
}
489486
PathSource::walk(&path, ret, false, filter)?;
490487
}

src/cargo/sources/registry/index.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl<'cfg> RegistryIndex<'cfg> {
268268
where
269269
'a: 'b,
270270
{
271-
let source_id = self.source_id.clone();
271+
let source_id = self.source_id;
272272

273273
// First up actually parse what summaries we have available. If Cargo
274274
// has run previously this will parse a Cargo-specific cache file rather
@@ -337,7 +337,7 @@ impl<'cfg> RegistryIndex<'cfg> {
337337
for path in UncanonicalizedIter::new(&raw_path).take(1024) {
338338
let summaries = Summaries::parse(
339339
index_version.as_ref().map(|s| &**s),
340-
&root,
340+
root,
341341
&cache_root,
342342
path.as_ref(),
343343
self.source_id,
@@ -671,7 +671,7 @@ impl<'a> SummariesCache<'a> {
671671
contents.extend_from_slice(data);
672672
contents.push(0);
673673
}
674-
return contents;
674+
contents
675675
}
676676
}
677677

src/cargo/util/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ impl Config {
704704
fn resolve_registry_index(&self, index: Value<String>) -> CargoResult<Url> {
705705
let base = index
706706
.definition
707-
.root(&self)
707+
.root(self)
708708
.join("truncated-by-url_with_base");
709709
// Parse val to check it is a URL, not a relative path without a protocol.
710710
let _parsed = index.val.to_url()?;
@@ -857,7 +857,7 @@ impl Config {
857857
`acquire_package_cache_lock` before we got to this stack frame",
858858
);
859859
assert!(ret.starts_with(self.home_path.as_path_unlocked()));
860-
return ret;
860+
ret
861861
}
862862

863863
/// Acquires an exclusive lock on the global "package cache"

tests/testsuite/freshness.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use filetime::FileTime;
22
use std::fs::{self, File, OpenOptions};
3+
use std::io;
34
use std::io::prelude::*;
45
use std::net::TcpListener;
56
use std::path::{Path, PathBuf};
@@ -1269,10 +1270,11 @@ fn fingerprint_cleaner(mut dir: PathBuf, timestamp: filetime::FileTime) {
12691270
for fing in fs::read_dir(&dir).unwrap() {
12701271
let fing = fing.unwrap();
12711272

1272-
if fs::read_dir(fing.path()).unwrap().all(|f| {
1273+
let outdated = |f: io::Result<fs::DirEntry>| {
12731274
filetime::FileTime::from_last_modification_time(&f.unwrap().metadata().unwrap())
12741275
<= timestamp
1275-
}) {
1276+
};
1277+
if fs::read_dir(fing.path()).unwrap().all(outdated) {
12761278
fs::remove_dir_all(fing.path()).unwrap();
12771279
println!("remove: {:?}", fing.path());
12781280
// a real cleaner would remove the big files in deps and build as well

tests/testsuite/support/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -884,8 +884,14 @@ impl Execs {
884884
panic!("`.stream()` is for local debugging")
885885
}
886886
process.exec_with_streaming(
887-
&mut |out| Ok(println!("{}", out)),
888-
&mut |err| Ok(eprintln!("{}", err)),
887+
&mut |out| {
888+
println!("{}", out);
889+
Ok(())
890+
},
891+
&mut |err| {
892+
eprintln!("{}", err);
893+
Ok(())
894+
},
889895
true,
890896
)
891897
} else {
@@ -1166,7 +1172,7 @@ impl Execs {
11661172
let e = out.lines();
11671173

11681174
let mut diffs = self.diff_lines(a.clone(), e.clone(), true);
1169-
while let Some(..) = a.next() {
1175+
while a.next().is_some() {
11701176
let a = self.diff_lines(a.clone(), e.clone(), true);
11711177
if a.len() < diffs.len() {
11721178
diffs = a;
@@ -1214,7 +1220,7 @@ impl Execs {
12141220
let e = out.lines();
12151221

12161222
let mut diffs = self.diff_lines(a.clone(), e.clone(), true);
1217-
while let Some(..) = a.next() {
1223+
while a.next().is_some() {
12181224
let a = self.diff_lines(a.clone(), e.clone(), true);
12191225
if a.len() < diffs.len() {
12201226
diffs = a;

0 commit comments

Comments
 (0)