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,
}
#[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!(),
}
}
}

View file

@ -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);
}
}

View file

@ -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();

View file

@ -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(),

View file

@ -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()

View file

@ -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;

View file

@ -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));
}
}

View file

@ -112,7 +112,7 @@ fn walk(path: &Path, callback: &mut dyn FnMut(&Path) -> CargoResult<bool>) -> 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 {

View file

@ -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));
}
}
}

View file

@ -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,
)))
}
}

View file

@ -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;

View file

@ -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)]