Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clippy fixes #6970

Merged
merged 2 commits into from
May 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
self.compilation
.rustdocflags
.entry(unit.pkg.package_id())
.or_insert(rustdocflags.to_vec());
.or_insert_with(|| rustdocflags.to_vec());
}

super::output_depinfo(&mut self, unit)?;
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/core/compiler/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ fn emit_build_output(state: &JobState<'_>, output: &BuildOutput, package_id: Pac
linked_paths: &library_paths,
cfgs: &output.cfgs,
env: &output.env,
}.to_json_string();
}
.to_json_string();
state.stdout(&msg);
}

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 @@ -216,7 +216,7 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {

self.queue.queue(*unit, job, queue_deps);
*self.counts.entry(unit.pkg.package_id()).or_insert(0) += 1;
return Ok(());
Ok(())
}

/// Executes all jobs necessary to build the dependency graph.
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,6 @@ impl<'a> UnitInterner<'a> {
}
me.cache.insert(Box::new(item.clone()));
let item = me.cache.get(item).unwrap();
return unsafe { &*(&**item as *const UnitInner<'a>) };
unsafe { &*(&**item as *const UnitInner<'a>) }
}
}
2 changes: 1 addition & 1 deletion src/cargo/core/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ fn activate(

let candidate = match registry.replacement_summary(candidate_pid) {
Some(replace) => {
if cx.flag_activated(&replace, &method)? && activated {
if cx.flag_activated(replace, &method)? && activated {
return Ok(None);
}
trace!(
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/resolver/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Resolve {
.find(|d| d.kind() == Kind::Normal)
.and_then(|d| {
if d.is_public() {
Some(dep_package.clone())
Some(*dep_package)
} else {
None
}
Expand All @@ -64,7 +64,7 @@ impl Resolve {
})
.collect::<HashSet<PackageId>>();

(p.clone(), public_deps)
(*p, public_deps)
})
.collect();

Expand Down
11 changes: 9 additions & 2 deletions src/cargo/lib.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
#![cfg_attr(test, deny(warnings))]
#![warn(rust_2018_idioms)]
// While we're getting used to 2018:
#![warn(rust_2018_idioms)]
// Clippy isn't enforced by CI (@alexcrichton isn't a fan).
#![allow(clippy::boxed_local)] // bug rust-lang-nursery/rust-clippy#1123
#![allow(clippy::blacklisted_name)] // frequently used in tests
#![allow(clippy::cyclomatic_complexity)] // large project
#![allow(clippy::derive_hash_xor_eq)] // there's an intentional incoherence
#![allow(clippy::explicit_into_iter_loop)] // explicit loops are clearer
#![allow(clippy::explicit_iter_loop)] // explicit loops are clearer
#![allow(clippy::identity_op)] // used for vertical alignment
#![allow(clippy::implicit_hasher)] // large project
#![allow(clippy::large_enum_variant)] // large project
#![allow(clippy::new_without_default)] // explicit is maybe clearer
#![allow(clippy::redundant_closure)] // closures can be less verbose
#![allow(clippy::redundant_closure_call)] // closures over try catch blocks
#![allow(clippy::too_many_arguments)] // large project
#![allow(clippy::type_complexity)] // there's an exceptionally complex type
#![allow(clippy::wrong_self_convention)] // perhaps `Rc` should be special-cased in Clippy?
#![warn(clippy::needless_borrow)]
#![warn(clippy::redundant_clone)]
// Unit is now interned, and would probably be better as pass-by-copy, but
// doing so causes a lot of & and * shenanigans that makes the code arguably
// less clear and harder to read.
#![allow(clippy::trivially_copy_pass_by_ref)]
// exhaustively destructuring ensures future fields are handled
#![allow(clippy::unneeded_field_pattern)]

use std::fmt;

Expand Down
11 changes: 9 additions & 2 deletions src/cargo/ops/cargo_generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,15 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
// by precise package update later.
Some(_) => {
let mut registry = PackageRegistry::new(opts.config)?;
ops::resolve_with_previous(&mut registry, ws, Method::Everything,
None, None, &[], true)?
ops::resolve_with_previous(
&mut registry,
ws,
Method::Everything,
None,
None,
&[],
true,
)?
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ fn tar(
}

if pkg.include_lockfile() {
let new_lock = build_lock(&ws)?;
let new_lock = build_lock(ws)?;

config
.shell()
Expand Down Expand Up @@ -609,7 +609,7 @@ fn run_verify(ws: &Workspace<'_>, tar: &FileLock, opts: &PackageOpts<'_>) -> Car
{
// FIXME: Turn this on at some point in the future
//Some(vec!["-D exported_private_dependencies".to_string()])
None
Some(vec![])
} else {
None
};
Expand Down
5 changes: 3 additions & 2 deletions src/cargo/ops/common_for_install_and_uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl InstallTracker {
// `cargo install --path ...` is always rebuilt.
return Ok((Freshness::Dirty, duplicates));
}
if matching_duplicates.iter().all(|dupe_pkg_id| {
let is_up_to_date = |dupe_pkg_id| {
let info = self
.v2
.installs
Expand All @@ -229,7 +229,8 @@ impl InstallTracker {
&& dupe_pkg_id.source_id() == source_id
&& precise_equal
&& info.is_up_to_date(opts, target, &exes)
}) {
};
if matching_duplicates.iter().all(is_up_to_date) {
Ok((Freshness::Fresh, duplicates))
} else {
Ok((Freshness::Dirty, duplicates))
Expand Down
9 changes: 3 additions & 6 deletions src/cargo/sources/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<'cfg> PathSource<'cfg> {
.exclude()
.iter()
.chain(pkg.manifest().include().iter())
.any(|p| p.starts_with("!"));
.any(|p| p.starts_with('!'));
// Don't warn about glob mismatch if it doesn't parse.
let glob_is_valid = glob_exclude.is_ok() && glob_include.is_ok() && !has_negate;
let glob_exclude = glob_exclude.unwrap_or_else(|_| Vec::new());
Expand Down Expand Up @@ -479,12 +479,9 @@ impl<'cfg> PathSource<'cfg> {
if name.map(|s| s.starts_with('.')) == Some(true) {
continue;
}
if is_root {
if is_root && name == Some("target") {
// Skip Cargo artifacts.
match name {
Some("target") => continue,
_ => {}
}
continue;
}
PathSource::walk(&path, ret, false, filter)?;
}
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/sources/registry/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl<'cfg> RegistryIndex<'cfg> {
where
'a: 'b,
{
let source_id = self.source_id.clone();
let source_id = self.source_id;

// First up actually parse what summaries we have available. If Cargo
// has run previously this will parse a Cargo-specific cache file rather
Expand Down Expand Up @@ -337,7 +337,7 @@ impl<'cfg> RegistryIndex<'cfg> {
for path in UncanonicalizedIter::new(&raw_path).take(1024) {
let summaries = Summaries::parse(
index_version.as_ref().map(|s| &**s),
&root,
root,
&cache_root,
path.as_ref(),
self.source_id,
Expand Down Expand Up @@ -671,7 +671,7 @@ impl<'a> SummariesCache<'a> {
contents.extend_from_slice(data);
contents.push(0);
}
return contents;
contents
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/cargo/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ impl Config {
fn resolve_registry_index(&self, index: Value<String>) -> CargoResult<Url> {
let base = index
.definition
.root(&self)
.root(self)
.join("truncated-by-url_with_base");
// Parse val to check it is a URL, not a relative path without a protocol.
let _parsed = index.val.to_url()?;
Expand Down Expand Up @@ -857,7 +857,7 @@ impl Config {
`acquire_package_cache_lock` before we got to this stack frame",
);
assert!(ret.starts_with(self.home_path.as_path_unlocked()));
return ret;
ret
}

/// Acquires an exclusive lock on the global "package cache"
Expand Down
12 changes: 8 additions & 4 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4573,11 +4573,13 @@ fn pipelining_works() {
foo.cargo("build")
.env("CARGO_BUILD_PIPELINING", "true")
.with_stdout("")
.with_stderr("\
.with_stderr(
"\
[COMPILING] [..]
[COMPILING] [..]
[FINISHED] [..]
")
",
)
.run();
}

Expand Down Expand Up @@ -4628,13 +4630,15 @@ fn forward_rustc_output() {

foo.cargo("build")
.with_stdout("a\nb\n{}")
.with_stderr("\
.with_stderr(
"\
[COMPILING] [..]
[COMPILING] [..]
c
d
{a
[FINISHED] [..]
")
",
)
.run();
}
6 changes: 4 additions & 2 deletions tests/testsuite/freshness.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use filetime::FileTime;
use std::fs::{self, File, OpenOptions};
use std::io;
use std::io::prelude::*;
use std::net::TcpListener;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -1269,10 +1270,11 @@ fn fingerprint_cleaner(mut dir: PathBuf, timestamp: filetime::FileTime) {
for fing in fs::read_dir(&dir).unwrap() {
let fing = fing.unwrap();

if fs::read_dir(fing.path()).unwrap().all(|f| {
let outdated = |f: io::Result<fs::DirEntry>| {
filetime::FileTime::from_last_modification_time(&f.unwrap().metadata().unwrap())
<= timestamp
}) {
};
if fs::read_dir(fing.path()).unwrap().all(outdated) {
fs::remove_dir_all(fing.path()).unwrap();
println!("remove: {:?}", fing.path());
// a real cleaner would remove the big files in deps and build as well
Expand Down
1 change: 0 additions & 1 deletion tests/testsuite/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2008,7 +2008,6 @@ fn readonly_registry_still_works() {
// make sure we un-readonly the files afterwards so "cargo clean" can remove them (#6934)
chmod_readonly(&paths::home(), false);


fn chmod_readonly(path: &Path, readonly: bool) {
for entry in t!(path.read_dir()) {
let entry = t!(entry);
Expand Down
3 changes: 2 additions & 1 deletion tests/testsuite/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ fn build_with_args_to_one_of_multiple_binaries() {
-C debuginfo=2 -C debug-assertions [..]`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
).run();
)
.run();
}

#[test]
Expand Down
14 changes: 10 additions & 4 deletions tests/testsuite/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,14 @@ impl Execs {
panic!("`.stream()` is for local debugging")
}
process.exec_with_streaming(
&mut |out| Ok(println!("{}", out)),
&mut |err| Ok(eprintln!("{}", err)),
&mut |out| {
println!("{}", out);
Ok(())
},
&mut |err| {
eprintln!("{}", err);
Ok(())
},
true,
)
} else {
Expand Down Expand Up @@ -1166,7 +1172,7 @@ impl Execs {
let e = out.lines();

let mut diffs = self.diff_lines(a.clone(), e.clone(), true);
while let Some(..) = a.next() {
while a.next().is_some() {
let a = self.diff_lines(a.clone(), e.clone(), true);
if a.len() < diffs.len() {
diffs = a;
Expand Down Expand Up @@ -1214,7 +1220,7 @@ impl Execs {
let e = out.lines();

let mut diffs = self.diff_lines(a.clone(), e.clone(), true);
while let Some(..) = a.next() {
while a.next().is_some() {
let a = self.diff_lines(a.clone(), e.clone(), true);
if a.len() < diffs.len() {
diffs = a;
Expand Down
1 change: 0 additions & 1 deletion tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ fn update_precise_first_run() {
",
)
.run();

}

#[test]
Expand Down