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

0 commit comments

Comments
 (0)