Skip to content

Commit 2cb4e91

Browse files
committed
Auto merge of #2282 - mcarton:clippy, r=alexcrichton
For information, here is the [log before and after](https://gist.github.com/mcarton/684c030321c4c60d6bc9) with Clippy. Remaining warnings from Clippy are mostly false positive or `str` to `string` conversion (too many of them for this PR). ``` warnings before: cmp_owned : 2 cyclomatic_complexity : 1 deprecated : 11 explicit_iter_loop : 57 identity_op : 3 len_without_is_empty : 3 len_zero : 20 let_and_return : 3 map_clone : 14 needless_lifetimes : 4 needless_return : 24 ok_expect : 2 option_map_unwrap_or : 10 private_in_public : 28 redundant_closure : 2 should_implement_trait : 2 single_match : 3 str_to_string : 112 string_to_string : 12 type_complexity : 3 unnecessary_mut_passed : 2 unneeded_field_pattern : 3 unused_lifetimes : 1 unused_variables : 2 while_let_loop : 2 warnings after: cmp_owned : 2 cyclomatic_complexity : 1 identity_op : 1 let_and_return : 3 map_clone : 1 needless_return : 3 ok_expect : 2 option_map_unwrap_or : 1 private_in_public : 28 should_implement_trait : 2 str_to_string : 80 type_complexity : 3 while_let_loop : 2 ```
2 parents 9ebfb9b + ebceb9b commit 2cb4e91

33 files changed

+103
-100
lines changed

src/cargo/core/package.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ impl PackageSet {
129129
PackageSet { packages: packages.to_vec() }
130130
}
131131

132+
pub fn is_empty(&self) -> bool {
133+
self.packages.is_empty()
134+
}
135+
132136
pub fn len(&self) -> usize {
133137
self.packages.len()
134138
}

src/cargo/core/registry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub trait Registry {
1515
impl Registry for Vec<Summary> {
1616
fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
1717
Ok(self.iter().filter(|summary| dep.matches(*summary))
18-
.map(|summary| summary.clone()).collect())
18+
.cloned().collect())
1919
}
2020
}
2121

@@ -295,7 +295,7 @@ impl<'cfg> Registry for PackageRegistry<'cfg> {
295295
fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
296296
let overrides = try!(self.query_overrides(dep));
297297

298-
let ret = if overrides.len() == 0 {
298+
let ret = if overrides.is_empty() {
299299
// Ensure the requested source_id is loaded
300300
try!(self.ensure_loaded(dep.source_id(), Kind::Normal));
301301
let mut ret = Vec::new();

src/cargo/core/resolver/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ fn find_candidate(backtrack_stack: &mut Vec<BacktrackFrame>,
384384
return Some(candidate)
385385
}
386386
}
387-
return None
387+
None
388388
}
389389

390390
#[allow(deprecated)] // connect => join in 1.3
@@ -453,7 +453,7 @@ fn activation_error(cx: &Context,
453453
candidates.sort_by(|a, b| {
454454
b.version().cmp(a.version())
455455
});
456-
if candidates.len() > 0 {
456+
if !candidates.is_empty() {
457457
msg.push_str("\nversions found: ");
458458
for (i, c) in candidates.iter().take(3).enumerate() {
459459
if i != 0 { msg.push_str(", "); }
@@ -469,7 +469,7 @@ fn activation_error(cx: &Context,
469469
// update`. In this case try to print a helpful error!
470470
if dep.source_id().is_path() &&
471471
dep.version_req().to_string().starts_with("=") &&
472-
candidates.len() > 0 {
472+
!candidates.is_empty() {
473473
msg.push_str("\nconsider running `cargo update` to update \
474474
a path dependency's locked version");
475475

@@ -607,7 +607,7 @@ impl Context {
607607
(!use_default || prev.contains("default") ||
608608
!has_default_feature)
609609
}
610-
None => features.len() == 0 && (!use_default || !has_default_feature)
610+
None => features.is_empty() && (!use_default || !has_default_feature)
611611
}
612612
}
613613

@@ -686,18 +686,18 @@ impl Context {
686686
// they should have all been weeded out by the above iteration. Any
687687
// remaining features are bugs in that the package does not actually
688688
// have those features.
689-
if feature_deps.len() > 0 {
689+
if !feature_deps.is_empty() {
690690
let unknown = feature_deps.keys().map(|s| &s[..])
691691
.collect::<Vec<&str>>();
692-
if unknown.len() > 0 {
692+
if !unknown.is_empty() {
693693
let features = unknown.connect(", ");
694694
bail!("Package `{}` does not have these features: `{}`",
695695
parent.package_id(), features)
696696
}
697697
}
698698

699699
// Record what list of features is active for this package.
700-
if used_features.len() > 0 {
700+
if !used_features.is_empty() {
701701
let pkgid = parent.package_id();
702702
self.resolve.features.entry(pkgid.clone())
703703
.or_insert(HashSet::new())

src/cargo/core/shell.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl MultiShell {
8181
where F: FnMut(&mut MultiShell) -> io::Result<()>
8282
{
8383
match self.verbosity {
84-
Verbose => return callback(self),
84+
Verbose => callback(self),
8585
_ => Ok(())
8686
}
8787
}
@@ -91,7 +91,7 @@ impl MultiShell {
9191
{
9292
match self.verbosity {
9393
Verbose => Ok(()),
94-
_ => return callback(self)
94+
_ => callback(self)
9595
}
9696
}
9797

src/cargo/core/source.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,10 @@ impl<'src> SourceMap<'src> {
419419
self.map.insert(id.clone(), source);
420420
}
421421

422+
pub fn is_empty(&self) -> bool {
423+
self.map.is_empty()
424+
}
425+
422426
pub fn len(&self) -> usize {
423427
self.map.len()
424428
}

src/cargo/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ pub fn version() -> String {
241241
})
242242
}
243243

244-
fn flags_from_args<'a, T>(usage: &str, args: &[String],
244+
fn flags_from_args<T>(usage: &str, args: &[String],
245245
options_first: bool) -> CliResult<T>
246246
where T: Decodable
247247
{

src/cargo/ops/cargo_clean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub fn clean(manifest_path: &Path, opts: &CleanOptions) -> CargoResult<()> {
2222

2323
// If we have a spec, then we need to delete some packages, otherwise, just
2424
// remove the whole target directory and be done with it!
25-
if opts.spec.len() == 0 {
25+
if opts.spec.is_empty() {
2626
return rm_rf(&target_dir);
2727
}
2828

src/cargo/ops/cargo_compile.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ pub fn compile_pkg<'a>(root_package: &Package,
176176
vec![root_package.package_id()]
177177
};
178178

179-
if spec.len() > 0 && invalid_spec.len() > 0 {
179+
if !spec.is_empty() && !invalid_spec.is_empty() {
180180
bail!("could not find package matching spec `{}`",
181181
invalid_spec.connect(", "))
182182
}
@@ -257,7 +257,7 @@ pub fn compile_pkg<'a>(root_package: &Package,
257257

258258
ret.to_doc_test = to_builds.iter().map(|&p| p.clone()).collect();
259259

260-
return Ok(ret);
260+
Ok(ret)
261261
}
262262

263263
impl<'a> CompileFilter<'a> {
@@ -311,7 +311,7 @@ fn generate_targets<'a>(pkg: &'a Package,
311311
CompileMode::Build => build,
312312
CompileMode::Doc { .. } => &profiles.doc,
313313
};
314-
return match *filter {
314+
match *filter {
315315
CompileFilter::Everything => {
316316
match mode {
317317
CompileMode::Bench => {
@@ -379,7 +379,7 @@ fn generate_targets<'a>(pkg: &'a Package,
379379
}
380380
Ok(targets)
381381
}
382-
};
382+
}
383383
}
384384

385385
/// Read the `paths` configuration variable to discover all path overrides that

src/cargo/ops/cargo_doc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn doc(manifest_path: &Path,
1818

1919
let mut lib_names = HashSet::new();
2020
let mut bin_names = HashSet::new();
21-
if options.compile_opts.spec.len() == 0 {
21+
if options.compile_opts.spec.is_empty() {
2222
for target in package.targets().iter().filter(|t| t.documented()) {
2323
if target.is_lib() {
2424
assert!(lib_names.insert(target.crate_name()));
@@ -42,7 +42,7 @@ pub fn doc(manifest_path: &Path,
4242
bail!("Passing multiple packages and `open` is not supported")
4343
} else if options.compile_opts.spec.len() == 1 {
4444
try!(PackageIdSpec::parse(&options.compile_opts.spec[0]))
45-
.name().replace("-", "_").to_string()
45+
.name().replace("-", "_")
4646
} else {
4747
match lib_names.iter().chain(bin_names.iter()).nth(0) {
4848
Some(s) => s.to_string(),

src/cargo/ops/cargo_generate_lockfile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn update_lockfile(manifest_path: &Path,
4343
let mut registry = PackageRegistry::new(opts.config);
4444
let mut to_avoid = HashSet::new();
4545

46-
if opts.to_update.len() == 0 {
46+
if opts.to_update.is_empty() {
4747
to_avoid.extend(previous_resolve.iter());
4848
} else {
4949
let mut sources = Vec::new();

0 commit comments

Comments
 (0)