diff --git a/src/bin/cargo/cli.rs b/src/bin/cargo/cli.rs index a1b8eb8ce7b..af02bbbfae7 100644 --- a/src/bin/cargo/cli.rs +++ b/src/bin/cargo/cli.rs @@ -47,7 +47,7 @@ Run with 'cargo -Z [FLAG] [SUBCOMMAND]'" return Ok(()); } - if let Some(ref code) = args.value_of("explain") { + if let Some(code) = args.value_of("explain") { let mut procss = config.rustc(None)?.process(); procss.arg("--explain").arg(code).exec()?; return Ok(()); diff --git a/src/bin/cargo/main.rs b/src/bin/cargo/main.rs index d0a18293f6e..39bc48f6887 100644 --- a/src/bin/cargo/main.rs +++ b/src/bin/cargo/main.rs @@ -1,6 +1,8 @@ #![warn(rust_2018_idioms)] // while we're getting used to 2018 #![allow(clippy::too_many_arguments)] // large project #![allow(clippy::redundant_closure)] // there's a false positive +#![warn(clippy::needless_borrow)] +#![warn(clippy::redundant_clone)] use std::collections::BTreeSet; use std::env; diff --git a/src/cargo/core/compiler/build_plan.rs b/src/cargo/core/compiler/build_plan.rs index d6c79d004be..efdfe1153ec 100644 --- a/src/cargo/core/compiler/build_plan.rs +++ b/src/cargo/core/compiler/build_plan.rs @@ -113,7 +113,7 @@ impl BuildPlan { let id = self.plan.invocations.len(); self.invocation_map.insert(unit.buildkey(), id); let deps = cx - .dep_targets(&unit) + .dep_targets(unit) .iter() .map(|dep| self.invocation_map[&dep.buildkey()]) .collect(); diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index afe2c9e4859..11014bae39a 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -120,7 +120,7 @@ impl<'cfg> Compilation<'cfg> { rustc_process: rustc, host: bcx.host_triple().to_string(), target: bcx.target_triple().to_string(), - target_runner: target_runner(&bcx)?, + target_runner: target_runner(bcx)?, }) } diff --git a/src/cargo/core/compiler/context/compilation_files.rs b/src/cargo/core/compiler/context/compilation_files.rs index 2808c286975..fd30a92a4e2 100644 --- a/src/cargo/core/compiler/context/compilation_files.rs +++ b/src/cargo/core/compiler/context/compilation_files.rs @@ -491,7 +491,7 @@ fn compute_metadata<'a, 'cfg>( // settings like debuginfo and whatnot. unit.profile.hash(&mut hasher); unit.mode.hash(&mut hasher); - if let Some(ref args) = bcx.extra_args_for(unit) { + if let Some(args) = bcx.extra_args_for(unit) { args.hash(&mut hasher); } diff --git a/src/cargo/core/compiler/context/mod.rs b/src/cargo/core/compiler/context/mod.rs index 650e7d2f552..511f3ec987a 100644 --- a/src/cargo/core/compiler/context/mod.rs +++ b/src/cargo/core/compiler/context/mod.rs @@ -474,11 +474,11 @@ impl<'a, 'cfg> Context<'a, 'cfg> { for unit in keys { for output in self.outputs(unit)?.iter() { if let Some(other_unit) = output_collisions.insert(output.path.clone(), unit) { - report_collision(unit, &other_unit, &output.path)?; + report_collision(unit, other_unit, &output.path)?; } if let Some(hardlink) = output.hardlink.as_ref() { if let Some(other_unit) = output_collisions.insert(hardlink.clone(), unit) { - report_collision(unit, &other_unit, hardlink)?; + report_collision(unit, other_unit, hardlink)?; } } if let Some(ref export_path) = output.export_path { @@ -488,7 +488,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { {}\ The exported filenames should be unique.\n\ {}", - describe_collision(unit, &other_unit, &export_path), + describe_collision(unit, other_unit, export_path), suggestion ))?; } diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index 3015ed89444..7516812842c 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -162,7 +162,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes .env( "TARGET", &match unit.kind { - Kind::Host => &bcx.host_triple(), + Kind::Host => bcx.host_triple(), Kind::Target => bcx.target_triple(), }, ) diff --git a/src/cargo/core/compiler/fingerprint.rs b/src/cargo/core/compiler/fingerprint.rs index a49ee867f9c..a01723c4498 100644 --- a/src/cargo/core/compiler/fingerprint.rs +++ b/src/cargo/core/compiler/fingerprint.rs @@ -682,7 +682,7 @@ fn calculate<'a, 'cfg>( local.extend(local_fingerprint_run_custom_build_deps(cx, unit)); local } else { - let fingerprint = pkg_fingerprint(&cx.bcx, unit.pkg)?; + let fingerprint = pkg_fingerprint(cx.bcx, unit.pkg)?; vec![LocalFingerprint::Precalculated(fingerprint)] }; @@ -701,7 +701,7 @@ fn calculate<'a, 'cfg>( profile: profile_hash, // Note that .0 is hashed here, not .1 which is the cwd. That doesn't // actually affect the output artifact so there's no need to hash it. - path: util::hash_u64(&super::path_args(&cx.bcx, unit).0), + path: util::hash_u64(&super::path_args(cx.bcx, unit).0), features: format!("{:?}", bcx.resolve.features_sorted(unit.pkg.package_id())), deps, local, @@ -855,7 +855,7 @@ fn build_script_local_fingerprints<'a, 'cfg>( let output = deps.build_script_output.clone(); if deps.rerun_if_changed.is_empty() && deps.rerun_if_env_changed.is_empty() { debug!("old local fingerprints deps"); - let s = pkg_fingerprint(&cx.bcx, unit.pkg)?; + let s = pkg_fingerprint(cx.bcx, unit.pkg)?; return Ok((vec![LocalFingerprint::Precalculated(s)], Some(output))); } diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index cb7136c1f7a..534c707d6c1 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -640,7 +640,7 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult add_error_format(bcx, &mut rustdoc); - if let Some(ref args) = bcx.extra_args_for(unit) { + if let Some(args) = bcx.extra_args_for(unit) { rustdoc.args(args); } @@ -831,7 +831,7 @@ fn build_base_args<'a, 'cfg>( cmd.arg("-C").arg(format!("debuginfo={}", debuginfo)); } - if let Some(ref args) = bcx.extra_args_for(unit) { + if let Some(args) = bcx.extra_args_for(unit) { cmd.args(args); } diff --git a/src/cargo/core/package.rs b/src/cargo/core/package.rs index a4850b11f9b..36f612d3305 100644 --- a/src/cargo/core/package.rs +++ b/src/cargo/core/package.rs @@ -105,7 +105,7 @@ impl ser::Serialize for Package { SerializedPackage { name: &*package_id.name(), - version: &package_id.version(), + version: package_id.version(), id: package_id, license, license_file, @@ -740,7 +740,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> { self.set.multi.messages(|msg| { let token = msg.token().expect("failed to read token"); let handle = &pending[&token].1; - if let Some(result) = msg.result_for(&handle) { + if let Some(result) = msg.result_for(handle) { results.push((token, result)); } else { debug!("message without a result (?)"); diff --git a/src/cargo/core/source/source_id.rs b/src/cargo/core/source/source_id.rs index dd5f5ff9af5..38231069b10 100644 --- a/src/cargo/core/source/source_id.rs +++ b/src/cargo/core/source/source_id.rs @@ -368,7 +368,7 @@ impl PartialOrd for SourceId { impl Ord for SourceId { fn cmp(&self, other: &SourceId) -> Ordering { - self.inner.cmp(&other.inner) + self.inner.cmp(other.inner) } } diff --git a/src/cargo/core/summary.rs b/src/cargo/core/summary.rs index 65a1a6bfc56..69f290435b1 100644 --- a/src/cargo/core/summary.rs +++ b/src/cargo/core/summary.rs @@ -58,7 +58,7 @@ impl Summary { ) } } - let feature_map = build_feature_map(&features, &dependencies, namespaced_features)?; + let feature_map = build_feature_map(features, &dependencies, namespaced_features)?; Ok(Summary { inner: Rc::new(Inner { package_id: pkg_id, @@ -170,7 +170,7 @@ where // iteration over the list if the dependency is found in the list. let mut dependency_found = if namespaced { match dep_map.get(feature.borrow()) { - Some(ref dep_data) => { + Some(dep_data) => { if !dep_data.iter().any(|d| d.is_optional()) { failure::bail!( "Feature `{}` includes the dependency of the same name, but this is \ diff --git a/src/cargo/lib.rs b/src/cargo/lib.rs index db193897bf9..e15a914cc8b 100644 --- a/src/cargo/lib.rs +++ b/src/cargo/lib.rs @@ -14,6 +14,8 @@ #![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)] use std::fmt; diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 7c567ec8bf5..3813366dcc9 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -372,12 +372,12 @@ pub fn compile_ws<'a>( &resolve_with_overrides, &packages, config, - &build_config, + build_config, profiles, extra_compiler_args, )?; let cx = Context::new(config, &bcx)?; - cx.compile(&units, export_dir.clone(), &exec)? + cx.compile(&units, export_dir.clone(), exec)? }; Ok(ret) diff --git a/src/cargo/ops/cargo_output_metadata.rs b/src/cargo/ops/cargo_output_metadata.rs index 0359f179eaa..957664cfda5 100644 --- a/src/cargo/ops/cargo_output_metadata.rs +++ b/src/cargo/ops/cargo_output_metadata.rs @@ -42,7 +42,7 @@ fn metadata_no_deps(ws: &Workspace<'_>, _opt: &OutputMetadataOptions) -> CargoRe packages: ws.members().cloned().collect(), workspace_members: ws.members().map(|pkg| pkg.package_id()).collect(), resolve: None, - target_directory: ws.target_dir().clone().into_path_unlocked(), + target_directory: ws.target_dir().into_path_unlocked(), version: VERSION, workspace_root: ws.root().to_path_buf(), }) @@ -70,7 +70,7 @@ fn metadata_full(ws: &Workspace<'_>, opt: &OutputMetadataOptions) -> CargoResult resolve: (packages, resolve), root: ws.current_opt().map(|pkg| pkg.package_id()), }), - target_directory: ws.target_dir().clone().into_path_unlocked(), + target_directory: ws.target_dir().into_path_unlocked(), version: VERSION, workspace_root: ws.root().to_path_buf(), }) diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index f0b6618d1e8..0908056da63 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -59,7 +59,7 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult