Skip to content

Commit 13e43aa

Browse files
committed
Auto merge of #6970 - ehuss:clippy-fixes, r=Eh2406
Clippy fixes Some of these are arguably not strictly better, but didn't really seem worse to me either. I tried changing all `&Unit` to `Unit`, but I felt like the code was worse with more frequent use of `*` and `&`.
2 parents 1d75407 + 6b07c8d commit 13e43aa

File tree

19 files changed

+63
-39
lines changed

19 files changed

+63
-39
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/custom_build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ fn emit_build_output(state: &JobState<'_>, output: &BuildOutput, package_id: Pac
110110
linked_paths: &library_paths,
111111
cfgs: &output.cfgs,
112112
env: &output.env,
113-
}.to_json_string();
113+
}
114+
.to_json_string();
114115
state.stdout(&msg);
115116
}
116117

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_generate_lockfile.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,15 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
5454
// by precise package update later.
5555
Some(_) => {
5656
let mut registry = PackageRegistry::new(opts.config)?;
57-
ops::resolve_with_previous(&mut registry, ws, Method::Everything,
58-
None, None, &[], true)?
57+
ops::resolve_with_previous(
58+
&mut registry,
59+
ws,
60+
Method::Everything,
61+
None,
62+
None,
63+
&[],
64+
true,
65+
)?
5966
}
6067
}
6168
}

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))

0 commit comments

Comments
 (0)