Auto merge of #9214 - ehuss:clippy-cleanup, r=Eh2406

Some minor code cleanup.

Some cleanup as recommended by clippy.  I think most of these are a little cleaner, though sometimes it is hard call.
This commit is contained in:
bors 2021-03-01 04:25:06 +00:00
commit 0b2059e981
13 changed files with 27 additions and 35 deletions

View File

@ -76,9 +76,8 @@ fn aliased_command(config: &Config, command: &str) -> CargoResult<Option<Vec<Str
Err(_) => config.get::<Option<Vec<String>>>(&alias_name)?, Err(_) => config.get::<Option<Vec<String>>>(&alias_name)?,
}; };
let result = user_alias.or_else(|| match builtin_aliases_execs(command) { let result = user_alias.or_else(|| {
Some(command_str) => Some(vec![command_str.1.to_string()]), builtin_aliases_execs(command).map(|command_str| vec![command_str.1.to_string()])
None => None,
}); });
Ok(result) Ok(result)
} }

View File

@ -699,10 +699,10 @@ impl RustcTargetData {
Ok(RustcTargetData { Ok(RustcTargetData {
rustc, rustc,
target_config,
target_info,
host_config, host_config,
host_info, host_info,
target_config,
target_info,
}) })
} }
@ -766,7 +766,7 @@ pub struct RustDocFingerprint {
impl RustDocFingerprint { impl RustDocFingerprint {
/// Read the `RustDocFingerprint` info from the fingerprint file. /// Read the `RustDocFingerprint` info from the fingerprint file.
fn read<'a, 'cfg>(cx: &Context<'a, 'cfg>) -> CargoResult<Self> { fn read(cx: &Context<'_, '_>) -> CargoResult<Self> {
let rustdoc_data = paths::read(&cx.files().host_root().join(".rustdoc_fingerprint.json"))?; let rustdoc_data = paths::read(&cx.files().host_root().join(".rustdoc_fingerprint.json"))?;
serde_json::from_str(&rustdoc_data).map_err(|e| anyhow::anyhow!("{:?}", e)) serde_json::from_str(&rustdoc_data).map_err(|e| anyhow::anyhow!("{:?}", e))
} }
@ -779,7 +779,7 @@ impl RustDocFingerprint {
) )
} }
fn remove_doc_dirs(doc_dirs: &Vec<&Path>) -> CargoResult<()> { fn remove_doc_dirs(doc_dirs: &[&Path]) -> CargoResult<()> {
doc_dirs doc_dirs
.iter() .iter()
.filter(|path| path.exists()) .filter(|path| path.exists())
@ -795,7 +795,7 @@ impl RustDocFingerprint {
/// the rustdoc fingerprint info in order to guarantee that we won't end up with mixed /// the rustdoc fingerprint info in order to guarantee that we won't end up with mixed
/// versions of the `js/html/css` files that `rustdoc` autogenerates which do not have /// versions of the `js/html/css` files that `rustdoc` autogenerates which do not have
/// any versioning. /// any versioning.
pub fn check_rustdoc_fingerprint<'a, 'cfg>(cx: &Context<'a, 'cfg>) -> CargoResult<()> { pub fn check_rustdoc_fingerprint(cx: &Context<'_, '_>) -> CargoResult<()> {
let actual_rustdoc_target_data = RustDocFingerprint { let actual_rustdoc_target_data = RustDocFingerprint {
rustc_vv: cx.bcx.rustc().verbose_version.clone(), rustc_vv: cx.bcx.rustc().verbose_version.clone(),
}; };

View File

@ -341,8 +341,8 @@ impl<'cfg> Compilation<'cfg> {
if self.config.cli_unstable().configurable_env { if self.config.cli_unstable().configurable_env {
// Apply any environment variables from the config // Apply any environment variables from the config
for (key, value) in self.config.env_config()?.iter() { for (key, value) in self.config.env_config()?.iter() {
if value.is_force() || cmd.get_env(&key).is_none() { if value.is_force() || cmd.get_env(key).is_none() {
cmd.env(&key, value.resolve(&self.config)); cmd.env(key, value.resolve(self.config));
} }
} }
} }

View File

@ -434,11 +434,11 @@ impl<'cfg> PackageSet<'cfg> {
}) })
} }
pub fn package_ids<'a>(&'a self) -> impl Iterator<Item = PackageId> + 'a { pub fn package_ids(&self) -> impl Iterator<Item = PackageId> + '_ {
self.packages.keys().cloned() self.packages.keys().cloned()
} }
pub fn packages<'a>(&'a self) -> impl Iterator<Item = &'a Package> + 'a { pub fn packages(&self) -> impl Iterator<Item = &Package> {
self.packages.values().filter_map(|p| p.borrow()) self.packages.values().filter_map(|p| p.borrow())
} }

View File

@ -236,7 +236,7 @@ unable to verify that `{0}` is the same as when the lockfile was generated
self.graph.sort() self.graph.sort()
} }
pub fn iter<'a>(&'a self) -> impl Iterator<Item = PackageId> + 'a { pub fn iter(&self) -> impl Iterator<Item = PackageId> + '_ {
self.graph.iter().cloned() self.graph.iter().cloned()
} }

View File

@ -173,7 +173,7 @@ impl DepsFrame {
.unwrap_or(0) .unwrap_or(0)
} }
pub fn flatten<'a>(&'a self) -> impl Iterator<Item = (PackageId, Dependency)> + 'a { pub fn flatten(&self) -> impl Iterator<Item = (PackageId, Dependency)> + '_ {
self.remaining_siblings self.remaining_siblings
.clone() .clone()
.map(move |(d, _, _)| (self.parent.package_id(), d)) .map(move |(d, _, _)| (self.parent.package_id(), d))
@ -247,7 +247,7 @@ impl RemainingDeps {
} }
None None
} }
pub fn iter<'a>(&'a mut self) -> impl Iterator<Item = (PackageId, Dependency)> + 'a { pub fn iter(&mut self) -> impl Iterator<Item = (PackageId, Dependency)> + '_ {
self.data.iter().flat_map(|(other, _)| other.flatten()) self.data.iter().flat_map(|(other, _)| other.flatten())
} }
} }

View File

@ -831,10 +831,7 @@ fn discover_author(path: &Path) -> (Option<String>, Option<String>) {
.or_else(|| git_config.and_then(|g| g.get_string("user.name").ok())) .or_else(|| git_config.and_then(|g| g.get_string("user.name").ok()))
.or_else(|| get_environment_variable(&name_variables[3..])); .or_else(|| get_environment_variable(&name_variables[3..]));
let name = match name { let name = name.map(|namestr| namestr.trim().to_string());
Some(namestr) => Some(namestr.trim().to_string()),
None => None,
};
let email_variables = [ let email_variables = [
"CARGO_EMAIL", "CARGO_EMAIL",

View File

@ -92,7 +92,7 @@ fn run_unit_tests(
"{} ({})", "{} ({})",
test_path test_path
.strip_prefix(unit.pkg.root()) .strip_prefix(unit.pkg.root())
.unwrap_or(&test_path) .unwrap_or(test_path)
.display(), .display(),
path.strip_prefix(cwd).unwrap_or(path).display() path.strip_prefix(cwd).unwrap_or(path).display()
) )

View File

@ -837,7 +837,7 @@ impl IndexSummary {
} }
} }
fn split<'a>(haystack: &'a [u8], needle: u8) -> impl Iterator<Item = &'a [u8]> + 'a { fn split(haystack: &[u8], needle: u8) -> impl Iterator<Item = &[u8]> {
struct Split<'a> { struct Split<'a> {
haystack: &'a [u8], haystack: &'a [u8],
needle: u8, needle: u8,

View File

@ -315,10 +315,9 @@ impl Config {
/// Gets the default Cargo registry. /// Gets the default Cargo registry.
pub fn default_registry(&self) -> CargoResult<Option<String>> { pub fn default_registry(&self) -> CargoResult<Option<String>> {
Ok(match self.get_string("registry.default")? { Ok(self
Some(registry) => Some(registry.val), .get_string("registry.default")?
None => None, .map(|registry| registry.val))
})
} }
/// Gets a reference to the shell, e.g., for writing error messages. /// Gets a reference to the shell, e.g., for writing error messages.
@ -808,10 +807,7 @@ impl Config {
(false, _, false) => Verbosity::Normal, (false, _, false) => Verbosity::Normal,
}; };
let cli_target_dir = match target_dir.as_ref() { let cli_target_dir = target_dir.as_ref().map(|dir| Filesystem::new(dir.clone()));
Some(dir) => Some(Filesystem::new(dir.clone())),
None => None,
};
self.shell().set_verbosity(verbosity); self.shell().set_verbosity(verbosity);
self.shell().set_color_choice(color)?; self.shell().set_color_choice(color)?;

View File

@ -276,9 +276,9 @@ impl ProcessBuilder {
})() })()
.chain_err(|| process_error(&format!("could not execute process {}", self), None, None))?; .chain_err(|| process_error(&format!("could not execute process {}", self), None, None))?;
let output = Output { let output = Output {
status,
stdout, stdout,
stderr, stderr,
status,
}; };
{ {

View File

@ -393,7 +393,7 @@ fn new_features() {
.. ..
}) = err.downcast_ref::<ProcessError>() }) = err.downcast_ref::<ProcessError>()
{ {
let stderr = std::str::from_utf8(&stderr).unwrap(); let stderr = std::str::from_utf8(stderr).unwrap();
if !stderr.contains(contents) { if !stderr.contains(contents) {
tc_result.push(format!( tc_result.push(format!(
"{} expected to see error contents:\n{}\nbut saw:\n{}", "{} expected to see error contents:\n{}\nbut saw:\n{}",
@ -428,7 +428,7 @@ fn new_features() {
} }
let which = "locked bar 1.0.0"; let which = "locked bar 1.0.0";
lock_bar_to(&version, 100); lock_bar_to(version, 100);
match run_cargo() { match run_cargo() {
Ok(behavior) => { Ok(behavior) => {
check_lock!(tc_result, "bar", which, behavior.bar, "1.0.0"); check_lock!(tc_result, "bar", which, behavior.bar, "1.0.0");
@ -441,7 +441,7 @@ fn new_features() {
} }
let which = "locked bar 1.0.1"; let which = "locked bar 1.0.1";
lock_bar_to(&version, 101); lock_bar_to(version, 101);
match run_cargo() { match run_cargo() {
Ok(behavior) => { Ok(behavior) => {
check_lock!(tc_result, "bar", which, behavior.bar, "1.0.1"); check_lock!(tc_result, "bar", which, behavior.bar, "1.0.1");
@ -463,7 +463,7 @@ fn new_features() {
} }
let which = "locked bar 1.0.2"; let which = "locked bar 1.0.2";
lock_bar_to(&version, 102); lock_bar_to(version, 102);
match run_cargo() { match run_cargo() {
Ok(behavior) => { Ok(behavior) => {
check_lock!(tc_result, "bar", which, behavior.bar, "1.0.2"); check_lock!(tc_result, "bar", which, behavior.bar, "1.0.2");

View File

@ -584,7 +584,7 @@ fn preserve_top_comment() {
let mut lines = lockfile.lines().collect::<Vec<_>>(); let mut lines = lockfile.lines().collect::<Vec<_>>();
lines.insert(2, "# some other comment"); lines.insert(2, "# some other comment");
let mut lockfile = lines.join("\n"); let mut lockfile = lines.join("\n");
lockfile.push_str("\n"); // .lines/.join loses the last newline lockfile.push('\n'); // .lines/.join loses the last newline
println!("saving Cargo.lock contents:\n{}", lockfile); println!("saving Cargo.lock contents:\n{}", lockfile);
p.change_file("Cargo.lock", &lockfile); p.change_file("Cargo.lock", &lockfile);