fix clippy warnings

This commit is contained in:
Matthias Krüger 2020-06-04 00:44:59 +02:00
parent 0227f048fc
commit 6eefe3c236
12 changed files with 20 additions and 25 deletions

View file

@ -6,6 +6,7 @@ pub struct ParseError {
orig: String, orig: String,
} }
#[non_exhaustive]
#[derive(Debug)] #[derive(Debug)]
pub enum ParseErrorKind { pub enum ParseErrorKind {
UnterminatedString, UnterminatedString,
@ -17,9 +18,6 @@ pub enum ParseErrorKind {
IncompleteExpr(&'static str), IncompleteExpr(&'static str),
UnterminatedExpression(String), UnterminatedExpression(String),
InvalidTarget(String), InvalidTarget(String),
#[doc(hidden)]
__Nonexhaustive,
} }
impl fmt::Display for ParseError { impl fmt::Display for ParseError {
@ -53,7 +51,6 @@ impl fmt::Display for ParseErrorKind {
write!(f, "unexpected content `{}` found after cfg expression", s) write!(f, "unexpected content `{}` found after cfg expression", s)
} }
InvalidTarget(s) => write!(f, "invalid target specifier: {}", s), InvalidTarget(s) => write!(f, "invalid target specifier: {}", s),
__Nonexhaustive => unreachable!(),
} }
} }
} }

View file

@ -894,7 +894,7 @@ impl Fingerprint {
if a.name != b.name { if a.name != b.name {
let e = format_err!("`{}` != `{}`", a.name, b.name) let e = format_err!("`{}` != `{}`", a.name, b.name)
.context("unit dependency name changed"); .context("unit dependency name changed");
return Err(e.into()); return Err(e);
} }
if a.fingerprint.hash() != b.fingerprint.hash() { if a.fingerprint.hash() != b.fingerprint.hash() {
@ -906,7 +906,7 @@ impl Fingerprint {
b.fingerprint.hash() b.fingerprint.hash()
) )
.context("unit dependency information changed"); .context("unit dependency information changed");
return Err(e.into()); return Err(e);
} }
} }

View file

@ -79,7 +79,7 @@ pub fn add_root_urls(
return Ok(()); return Ok(());
} }
let map = config.doc_extern_map()?; 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. // Skip doing unnecessary work.
return Ok(()); return Ok(());
} }
@ -90,13 +90,13 @@ pub fn add_root_urls(
.keys() .keys()
.filter_map(|name| { .filter_map(|name| {
if let Ok(index_url) = config.get_registry_index(name) { if let Ok(index_url) = config.get_registry_index(name) {
return Some((name, index_url)); Some((name, index_url))
} else { } else {
log::warn!( log::warn!(
"`doc.extern-map.{}` specifies a registry that is not defined", "`doc.extern-map.{}` specifies a registry that is not defined",
name name
); );
return None; None
} }
}) })
.collect(); .collect();

View file

@ -294,7 +294,7 @@ impl<'cfg> PackageRegistry<'cfg> {
.expect("loaded source not present"); .expect("loaded source not present");
let summaries = source.query_vec(dep)?; let summaries = source.query_vec(dep)?;
let (summary, should_unlock) = 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!( format!(
"patch for `{}` in `{}` failed to resolve", "patch for `{}` in `{}` failed to resolve",
orig_patch.package_name(), orig_patch.package_name(),

View file

@ -863,7 +863,7 @@ impl<'cfg> Workspace<'cfg> {
let err = anyhow::format_err!("{}", warning.message); let err = anyhow::format_err!("{}", warning.message);
let cx = let cx =
anyhow::format_err!("failed to parse manifest at `{}`", path.display()); anyhow::format_err!("failed to parse manifest at `{}`", path.display());
return Err(err.context(cx).into()); return Err(err.context(cx));
} else { } else {
let msg = if self.root_manifest.is_none() { let msg = if self.root_manifest.is_none() {
warning.message.to_string() warning.message.to_string()

View file

@ -28,7 +28,7 @@
#![allow(clippy::unneeded_field_pattern)] #![allow(clippy::unneeded_field_pattern)]
// false positives in target-specific code, for details see // false positives in target-specific code, for details see
// https://github.com/rust-lang/cargo/pull/7251#pullrequestreview-274914270 // 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::Verbosity::Verbose;
use crate::core::Shell; use crate::core::Shell;

View file

@ -570,8 +570,8 @@ where
// best-effort check to see if we can avoid hitting the network. // best-effort check to see if we can avoid hitting the network.
if let Ok(pkg) = select_dep_pkg(source, dep, config, false) { if let Ok(pkg) = select_dep_pkg(source, dep, config, false) {
let (_ws, rustc, target) = let (_ws, rustc, target) =
make_ws_rustc_target(&config, opts, &source.source_id(), pkg.clone())?; 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) { if let Ok(true) = is_installed(&pkg, config, opts, &rustc, &target, root, dst, force) {
return Ok(Some(pkg)); return Ok(Some(pkg));
} }
} }

View file

@ -112,7 +112,7 @@ fn walk(path: &Path, callback: &mut dyn FnMut(&Path) -> CargoResult<bool>) -> Ca
Err(e) => { Err(e) => {
let cx = format!("failed to read directory `{}`", path.display()); let cx = format!("failed to read directory `{}`", path.display());
let e = anyhow::Error::from(e); let e = anyhow::Error::from(e);
return Err(e.context(cx).into()); return Err(e.context(cx));
} }
}; };
for dir in dirs { for dir in dirs {

View file

@ -307,7 +307,7 @@ fn acquire(
if !error_contended(&e) { if !error_contended(&e) {
let e = anyhow::Error::from(e); let e = anyhow::Error::from(e);
let cx = format!("failed to lock file: {}", path.display()); let cx = format!("failed to lock file: {}", path.display());
return Err(e.context(cx).into()); return Err(e.context(cx));
} }
} }
} }

View file

@ -381,13 +381,11 @@ mod imp {
pub fn exec_replace(process_builder: &ProcessBuilder) -> CargoResult<()> { pub fn exec_replace(process_builder: &ProcessBuilder) -> CargoResult<()> {
let mut command = process_builder.build_command(); let mut command = process_builder.build_command();
let error = command.exec(); let error = command.exec();
Err(anyhow::Error::from(error) Err(anyhow::Error::from(error).context(process_error(
.context(process_error( &format!("could not execute process {}", process_builder),
&format!("could not execute process {}", process_builder), None,
None, None,
None, )))
))
.into())
} }
} }

View file

@ -163,7 +163,7 @@ and this will become a hard error in the future.",
} }
let first_error = anyhow::Error::from(first_error); 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; type TomlLibTarget = TomlTarget;

View file

@ -3,7 +3,7 @@
#![allow(clippy::blacklisted_name)] #![allow(clippy::blacklisted_name)]
#![allow(clippy::explicit_iter_loop)] #![allow(clippy::explicit_iter_loop)]
#![allow(clippy::redundant_closure)] #![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()` #![allow(clippy::inefficient_to_string)] // this causes suggestions that result in `(*s).to_string()`
#![warn(clippy::needless_borrow)] #![warn(clippy::needless_borrow)]
#![warn(clippy::redundant_clone)] #![warn(clippy::redundant_clone)]