From 6eefe3c2367e269643deee609fbbd558d987bf30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Thu, 4 Jun 2020 00:44:59 +0200 Subject: [PATCH] fix clippy warnings --- crates/cargo-platform/src/error.rs | 5 +---- src/cargo/core/compiler/fingerprint.rs | 4 ++-- src/cargo/core/compiler/rustdoc.rs | 6 +++--- src/cargo/core/registry.rs | 2 +- src/cargo/core/workspace.rs | 2 +- src/cargo/lib.rs | 2 +- src/cargo/ops/cargo_install.rs | 4 ++-- src/cargo/ops/cargo_read_manifest.rs | 2 +- src/cargo/util/flock.rs | 2 +- src/cargo/util/process_builder.rs | 12 +++++------- src/cargo/util/toml/mod.rs | 2 +- tests/testsuite/main.rs | 2 +- 12 files changed, 20 insertions(+), 25 deletions(-) diff --git a/crates/cargo-platform/src/error.rs b/crates/cargo-platform/src/error.rs index 19a15a1e1..bf4b35f27 100644 --- a/crates/cargo-platform/src/error.rs +++ b/crates/cargo-platform/src/error.rs @@ -6,6 +6,7 @@ pub struct ParseError { orig: String, } +#[non_exhaustive] #[derive(Debug)] pub enum ParseErrorKind { UnterminatedString, @@ -17,9 +18,6 @@ pub enum ParseErrorKind { IncompleteExpr(&'static str), UnterminatedExpression(String), InvalidTarget(String), - - #[doc(hidden)] - __Nonexhaustive, } impl fmt::Display for ParseError { @@ -53,7 +51,6 @@ impl fmt::Display for ParseErrorKind { write!(f, "unexpected content `{}` found after cfg expression", s) } InvalidTarget(s) => write!(f, "invalid target specifier: {}", s), - __Nonexhaustive => unreachable!(), } } } diff --git a/src/cargo/core/compiler/fingerprint.rs b/src/cargo/core/compiler/fingerprint.rs index 4e554202e..4adab7efb 100644 --- a/src/cargo/core/compiler/fingerprint.rs +++ b/src/cargo/core/compiler/fingerprint.rs @@ -894,7 +894,7 @@ impl Fingerprint { if a.name != b.name { let e = format_err!("`{}` != `{}`", a.name, b.name) .context("unit dependency name changed"); - return Err(e.into()); + return Err(e); } if a.fingerprint.hash() != b.fingerprint.hash() { @@ -906,7 +906,7 @@ impl Fingerprint { b.fingerprint.hash() ) .context("unit dependency information changed"); - return Err(e.into()); + return Err(e); } } diff --git a/src/cargo/core/compiler/rustdoc.rs b/src/cargo/core/compiler/rustdoc.rs index ad0524a2f..d32f2d691 100644 --- a/src/cargo/core/compiler/rustdoc.rs +++ b/src/cargo/core/compiler/rustdoc.rs @@ -79,7 +79,7 @@ pub fn add_root_urls( return Ok(()); } let map = config.doc_extern_map()?; - if map.registries.len() == 0 && map.std.is_none() { + if map.registries.is_empty() && map.std.is_none() { // Skip doing unnecessary work. return Ok(()); } @@ -90,13 +90,13 @@ pub fn add_root_urls( .keys() .filter_map(|name| { if let Ok(index_url) = config.get_registry_index(name) { - return Some((name, index_url)); + Some((name, index_url)) } else { log::warn!( "`doc.extern-map.{}` specifies a registry that is not defined", name ); - return None; + None } }) .collect(); diff --git a/src/cargo/core/registry.rs b/src/cargo/core/registry.rs index 2f63c2620..160ca770a 100644 --- a/src/cargo/core/registry.rs +++ b/src/cargo/core/registry.rs @@ -294,7 +294,7 @@ impl<'cfg> PackageRegistry<'cfg> { .expect("loaded source not present"); let summaries = source.query_vec(dep)?; let (summary, should_unlock) = - summary_for_patch(orig_patch, &locked, summaries, source).chain_err(|| { + summary_for_patch(orig_patch, locked, summaries, source).chain_err(|| { format!( "patch for `{}` in `{}` failed to resolve", orig_patch.package_name(), diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 5931a9a5c..aec08c79e 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -863,7 +863,7 @@ impl<'cfg> Workspace<'cfg> { let err = anyhow::format_err!("{}", warning.message); let cx = anyhow::format_err!("failed to parse manifest at `{}`", path.display()); - return Err(err.context(cx).into()); + return Err(err.context(cx)); } else { let msg = if self.root_manifest.is_none() { warning.message.to_string() diff --git a/src/cargo/lib.rs b/src/cargo/lib.rs index 19cbd49c1..29eb11088 100644 --- a/src/cargo/lib.rs +++ b/src/cargo/lib.rs @@ -28,7 +28,7 @@ #![allow(clippy::unneeded_field_pattern)] // false positives in target-specific code, for details see // https://github.com/rust-lang/cargo/pull/7251#pullrequestreview-274914270 -#![allow(clippy::identity_conversion)] +#![allow(clippy::useless_conversion)] use crate::core::shell::Verbosity::Verbose; use crate::core::Shell; diff --git a/src/cargo/ops/cargo_install.rs b/src/cargo/ops/cargo_install.rs index 9b1b08a72..1c7f5df99 100644 --- a/src/cargo/ops/cargo_install.rs +++ b/src/cargo/ops/cargo_install.rs @@ -570,8 +570,8 @@ where // best-effort check to see if we can avoid hitting the network. if let Ok(pkg) = select_dep_pkg(source, dep, config, false) { let (_ws, rustc, target) = - make_ws_rustc_target(&config, opts, &source.source_id(), pkg.clone())?; - if let Ok(true) = is_installed(&pkg, config, opts, &rustc, &target, root, &dst, force) { + make_ws_rustc_target(config, opts, &source.source_id(), pkg.clone())?; + if let Ok(true) = is_installed(&pkg, config, opts, &rustc, &target, root, dst, force) { return Ok(Some(pkg)); } } diff --git a/src/cargo/ops/cargo_read_manifest.rs b/src/cargo/ops/cargo_read_manifest.rs index df1083fc3..95975c8c1 100644 --- a/src/cargo/ops/cargo_read_manifest.rs +++ b/src/cargo/ops/cargo_read_manifest.rs @@ -112,7 +112,7 @@ fn walk(path: &Path, callback: &mut dyn FnMut(&Path) -> CargoResult) -> Ca Err(e) => { let cx = format!("failed to read directory `{}`", path.display()); let e = anyhow::Error::from(e); - return Err(e.context(cx).into()); + return Err(e.context(cx)); } }; for dir in dirs { diff --git a/src/cargo/util/flock.rs b/src/cargo/util/flock.rs index 2d732bb7a..985ef6e24 100644 --- a/src/cargo/util/flock.rs +++ b/src/cargo/util/flock.rs @@ -307,7 +307,7 @@ fn acquire( if !error_contended(&e) { let e = anyhow::Error::from(e); let cx = format!("failed to lock file: {}", path.display()); - return Err(e.context(cx).into()); + return Err(e.context(cx)); } } } diff --git a/src/cargo/util/process_builder.rs b/src/cargo/util/process_builder.rs index 953f8ae58..f23039814 100644 --- a/src/cargo/util/process_builder.rs +++ b/src/cargo/util/process_builder.rs @@ -381,13 +381,11 @@ mod imp { pub fn exec_replace(process_builder: &ProcessBuilder) -> CargoResult<()> { let mut command = process_builder.build_command(); let error = command.exec(); - Err(anyhow::Error::from(error) - .context(process_error( - &format!("could not execute process {}", process_builder), - None, - None, - )) - .into()) + Err(anyhow::Error::from(error).context(process_error( + &format!("could not execute process {}", process_builder), + None, + None, + ))) } } diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index b1688b857..d39d09356 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -163,7 +163,7 @@ and this will become a hard error in the future.", } let first_error = anyhow::Error::from(first_error); - Err(first_error.context("could not parse input as TOML").into()) + Err(first_error.context("could not parse input as TOML")) } type TomlLibTarget = TomlTarget; diff --git a/tests/testsuite/main.rs b/tests/testsuite/main.rs index 7aec3227b..56c00c7a3 100644 --- a/tests/testsuite/main.rs +++ b/tests/testsuite/main.rs @@ -3,7 +3,7 @@ #![allow(clippy::blacklisted_name)] #![allow(clippy::explicit_iter_loop)] #![allow(clippy::redundant_closure)] -#![allow(clippy::block_in_if_condition_stmt)] // clippy doesn't agree with rustfmt 😂 +#![allow(clippy::blocks_in_if_conditions)] // clippy doesn't agree with rustfmt 😂 #![allow(clippy::inefficient_to_string)] // this causes suggestions that result in `(*s).to_string()` #![warn(clippy::needless_borrow)] #![warn(clippy::redundant_clone)]