Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some minor code cleanup. #9214

Merged
merged 1 commit into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/bin/cargo/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ fn aliased_command(config: &Config, command: &str) -> CargoResult<Option<Vec<Str
Err(_) => config.get::<Option<Vec<String>>>(&alias_name)?,
};

let result = user_alias.or_else(|| match builtin_aliases_execs(command) {
Some(command_str) => Some(vec![command_str.1.to_string()]),
None => None,
let result = user_alias.or_else(|| {
builtin_aliases_execs(command).map(|command_str| vec![command_str.1.to_string()])
});
Ok(result)
}
Expand Down
10 changes: 5 additions & 5 deletions src/cargo/core/compiler/build_context/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,10 +699,10 @@ impl RustcTargetData {

Ok(RustcTargetData {
rustc,
target_config,
target_info,
host_config,
host_info,
target_config,
target_info,
})
}

Expand Down Expand Up @@ -766,7 +766,7 @@ pub struct RustDocFingerprint {

impl RustDocFingerprint {
/// 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"))?;
serde_json::from_str(&rustdoc_data).map_err(|e| anyhow::anyhow!("{:?}", e))
}
Expand All @@ -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
.iter()
.filter(|path| path.exists())
Expand All @@ -795,7 +795,7 @@ impl RustDocFingerprint {
/// 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
/// 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 {
rustc_vv: cx.bcx.rustc().verbose_version.clone(),
};
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ impl<'cfg> Compilation<'cfg> {
if self.config.cli_unstable().configurable_env {
// Apply any environment variables from the config
for (key, value) in self.config.env_config()?.iter() {
if value.is_force() || cmd.get_env(&key).is_none() {
cmd.env(&key, value.resolve(&self.config));
if value.is_force() || cmd.get_env(key).is_none() {
cmd.env(key, value.resolve(self.config));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/resolver/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ unable to verify that `{0}` is the same as when the lockfile was generated
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()
}

Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/resolver/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl DepsFrame {
.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
.clone()
.map(move |(d, _, _)| (self.parent.package_id(), d))
Expand Down Expand Up @@ -247,7 +247,7 @@ impl RemainingDeps {
}
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())
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|| get_environment_variable(&name_variables[3..]));

let name = match name {
Some(namestr) => Some(namestr.trim().to_string()),
None => None,
};
let name = name.map(|namestr| namestr.trim().to_string());

let email_variables = [
"CARGO_EMAIL",
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn run_unit_tests(
"{} ({})",
test_path
.strip_prefix(unit.pkg.root())
.unwrap_or(&test_path)
.unwrap_or(test_path)
.display(),
path.strip_prefix(cwd).unwrap_or(path).display()
)
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/sources/registry/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
haystack: &'a [u8],
needle: u8,
Expand Down
12 changes: 4 additions & 8 deletions src/cargo/util/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,9 @@ impl Config {

/// Gets the default Cargo registry.
pub fn default_registry(&self) -> CargoResult<Option<String>> {
Ok(match self.get_string("registry.default")? {
Some(registry) => Some(registry.val),
None => None,
})
Ok(self
.get_string("registry.default")?
.map(|registry| registry.val))
}

/// Gets a reference to the shell, e.g., for writing error messages.
Expand Down Expand Up @@ -808,10 +807,7 @@ impl Config {
(false, _, false) => Verbosity::Normal,
};

let cli_target_dir = match target_dir.as_ref() {
Some(dir) => Some(Filesystem::new(dir.clone())),
None => None,
};
let cli_target_dir = target_dir.as_ref().map(|dir| Filesystem::new(dir.clone()));

self.shell().set_verbosity(verbosity);
self.shell().set_color_choice(color)?;
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/process_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ impl ProcessBuilder {
})()
.chain_err(|| process_error(&format!("could not execute process {}", self), None, None))?;
let output = Output {
status,
stdout,
stderr,
status,
};

{
Expand Down
8 changes: 4 additions & 4 deletions tests/testsuite/old_cargos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ fn new_features() {
..
}) = err.downcast_ref::<ProcessError>()
{
let stderr = std::str::from_utf8(&stderr).unwrap();
let stderr = std::str::from_utf8(stderr).unwrap();
if !stderr.contains(contents) {
tc_result.push(format!(
"{} expected to see error contents:\n{}\nbut saw:\n{}",
Expand Down Expand Up @@ -428,7 +428,7 @@ fn new_features() {
}

let which = "locked bar 1.0.0";
lock_bar_to(&version, 100);
lock_bar_to(version, 100);
match run_cargo() {
Ok(behavior) => {
check_lock!(tc_result, "bar", which, behavior.bar, "1.0.0");
Expand All @@ -441,7 +441,7 @@ fn new_features() {
}

let which = "locked bar 1.0.1";
lock_bar_to(&version, 101);
lock_bar_to(version, 101);
match run_cargo() {
Ok(behavior) => {
check_lock!(tc_result, "bar", which, behavior.bar, "1.0.1");
Expand All @@ -463,7 +463,7 @@ fn new_features() {
}

let which = "locked bar 1.0.2";
lock_bar_to(&version, 102);
lock_bar_to(version, 102);
match run_cargo() {
Ok(behavior) => {
check_lock!(tc_result, "bar", which, behavior.bar, "1.0.2");
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ fn preserve_top_comment() {
let mut lines = lockfile.lines().collect::<Vec<_>>();
lines.insert(2, "# some other comment");
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);

p.change_file("Cargo.lock", &lockfile);
Expand Down