From 3fce509208f88a70475ab909e44ac3983ea452e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Thu, 26 Sep 2019 17:51:19 +0200 Subject: [PATCH] fix a bunch of clippy warnings --- crates/cargo-test-support/src/lib.rs | 4 +--- src/cargo/core/compiler/context/compilation_files.rs | 6 +++--- src/cargo/core/compiler/custom_build.rs | 2 +- src/cargo/core/compiler/layout.rs | 2 +- src/cargo/core/resolver/errors.rs | 2 +- src/cargo/sources/registry/mod.rs | 4 ++-- src/cargo/util/dependency_queue.rs | 4 ++-- src/cargo/util/toml/mod.rs | 8 ++++---- tests/testsuite/standard_lib.rs | 4 ++-- 9 files changed, 17 insertions(+), 19 deletions(-) diff --git a/crates/cargo-test-support/src/lib.rs b/crates/cargo-test-support/src/lib.rs index 0ee88e8d4b4..d43bc96d498 100644 --- a/crates/cargo-test-support/src/lib.rs +++ b/crates/cargo-test-support/src/lib.rs @@ -1158,9 +1158,7 @@ impl Execs { // It's easier to read tabs in outputs if they don't show up as literal // hidden characters - let matcher = matcher.replace("\t", ""); - - matcher + matcher.replace("\t", "") } fn match_std( diff --git a/src/cargo/core/compiler/context/compilation_files.rs b/src/cargo/core/compiler/context/compilation_files.rs index 743d7d821c5..0178034e3ee 100644 --- a/src/cargo/core/compiler/context/compilation_files.rs +++ b/src/cargo/core/compiler/context/compilation_files.rs @@ -372,9 +372,9 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> { None } else { self.export_dir.as_ref().and_then(|export_dir| { - hardlink.as_ref().and_then(|hardlink| { - Some(export_dir.join(hardlink.file_name().unwrap())) - }) + hardlink + .as_ref() + .map(|hardlink| export_dir.join(hardlink.file_name().unwrap())) }) }; ret.push(OutputFile { diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index f727087ccfa..e5f7157dc4c 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -518,7 +518,7 @@ impl BuildOutput { // common with tools like pkg-config // e.g. -L/some/dir/local/lib or -licui18n let (flag, mut value) = flag.split_at(2); - if value.len() == 0 { + if value.is_empty() { value = match flags_iter.next() { Some(v) => v, None => failure::bail! { diff --git a/src/cargo/core/compiler/layout.rs b/src/cargo/core/compiler/layout.rs index b24c1b58e8f..14b7d17a107 100644 --- a/src/cargo/core/compiler/layout.rs +++ b/src/cargo/core/compiler/layout.rs @@ -217,7 +217,7 @@ impl Layout { paths::create_dir_all(&self.examples)?; paths::create_dir_all(&self.build)?; - return Ok(()); + Ok(()) } /// Fetch the destination path for final artifacts (`/…/target/debug`). diff --git a/src/cargo/core/resolver/errors.rs b/src/cargo/core/resolver/errors.rs index 6d56cb33ca8..823120e167b 100644 --- a/src/cargo/core/resolver/errors.rs +++ b/src/cargo/core/resolver/errors.rs @@ -252,7 +252,7 @@ pub(super) fn activation_error( // Maybe the user mistyped the name? Like `dep-thing` when `Dep_Thing` // was meant. So we try asking the registry for a `fuzzy` search for suggestions. let mut candidates = Vec::new(); - if let Err(e) = registry.query(&new_dep, &mut |s| candidates.push(s.clone()), true) { + if let Err(e) = registry.query(&new_dep, &mut |s| candidates.push(s), true) { return to_resolve_err(e); }; candidates.sort_unstable_by(|a, b| a.name().cmp(&b.name())); diff --git a/src/cargo/sources/registry/mod.rs b/src/cargo/sources/registry/mod.rs index 7b28e9ae5a3..533f987998b 100644 --- a/src/cargo/sources/registry/mod.rs +++ b/src/cargo/sources/registry/mod.rs @@ -604,7 +604,7 @@ impl<'cfg> Source for RegistrySource<'cfg> { fn download(&mut self, package: PackageId) -> CargoResult { let hash = self.index.hash(package, &mut *self.ops)?; - match self.ops.download(package, &hash)? { + match self.ops.download(package, hash)? { MaybeLock::Ready(file) => self.get_pkg(package, &file).map(MaybePackage::Ready), MaybeLock::Download { url, descriptor } => { Ok(MaybePackage::Download { url, descriptor }) @@ -614,7 +614,7 @@ impl<'cfg> Source for RegistrySource<'cfg> { fn finish_download(&mut self, package: PackageId, data: Vec) -> CargoResult { let hash = self.index.hash(package, &mut *self.ops)?; - let file = self.ops.finish_download(package, &hash, &data)?; + let file = self.ops.finish_download(package, hash, &data)?; self.get_pkg(package, &file) } diff --git a/src/cargo/util/dependency_queue.rs b/src/cargo/util/dependency_queue.rs index 94654950785..d0bc3da9df7 100644 --- a/src/cargo/util/dependency_queue.rs +++ b/src/cargo/util/dependency_queue.rs @@ -107,14 +107,14 @@ impl DependencyQueue { .get(key) .into_iter() .flat_map(|it| it.values()) - .flat_map(|set| set) + .flatten() { set.extend(depth(dep, map, results).iter().cloned()) } let slot = results.get_mut(key).unwrap(); *slot = set; - return &*slot; + &*slot } } diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index ff3eedaec6e..922ff7959f0 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -954,7 +954,7 @@ impl TomlManifest { .or_else(|| me.build_dependencies2.as_ref()); process_dependencies(&mut cx, build_deps, Some(Kind::Build))?; - for (name, platform) in me.target.iter().flat_map(|t| t) { + for (name, platform) in me.target.iter().flatten() { cx.platform = Some(name.parse()?); process_dependencies(&mut cx, platform.dependencies.as_ref(), None)?; let build_deps = platform @@ -1210,7 +1210,7 @@ impl TomlManifest { bail!("cannot specify both [replace] and [patch]"); } let mut replace = Vec::new(); - for (spec, replacement) in self.replace.iter().flat_map(|x| x) { + for (spec, replacement) in self.replace.iter().flatten() { let mut spec = PackageIdSpec::parse(spec).chain_err(|| { format!( "replacements must specify a valid semver \ @@ -1252,7 +1252,7 @@ impl TomlManifest { fn patch(&self, cx: &mut Context<'_, '_>) -> CargoResult>> { let mut patch = HashMap::new(); - for (url, deps) in self.patch.iter().flat_map(|x| x) { + for (url, deps) in self.patch.iter().flatten() { let url = match &url[..] { CRATES_IO_REGISTRY => CRATES_IO_INDEX.parse().unwrap(), _ => cx @@ -1469,7 +1469,7 @@ impl DetailedTomlDependency { Some(id) => Dependency::parse(pkg_name, version, new_source_id, id, cx.config)?, None => Dependency::parse_no_deprecated(pkg_name, version, new_source_id)?, }; - dep.set_features(self.features.iter().flat_map(|x| x)) + dep.set_features(self.features.iter().flatten()) .set_default_features( self.default_features .or(self.default_features2) diff --git a/tests/testsuite/standard_lib.rs b/tests/testsuite/standard_lib.rs index 5e6ae6126c1..6df837bd0ea 100644 --- a/tests/testsuite/standard_lib.rs +++ b/tests/testsuite/standard_lib.rs @@ -104,10 +104,10 @@ fn setup() -> Option { .build(); p.cargo("build").run(); - return Some(Setup { + Some(Setup { rustc_wrapper: p.bin("foo"), real_sysroot: paths::sysroot(), - }); + }) } fn enable_build_std(e: &mut Execs, setup: &Setup, arg: Option<&str>) {