mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Some minor code cleanup.
This commit is contained in:
parent
e35b99a3f3
commit
e58c544f37
@ -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)
|
||||
}
|
||||
|
@ -699,10 +699,10 @@ impl RustcTargetData {
|
||||
|
||||
Ok(RustcTargetData {
|
||||
rustc,
|
||||
target_config,
|
||||
target_info,
|
||||
host_config,
|
||||
host_info,
|
||||
target_config,
|
||||
target_info,
|
||||
})
|
||||
}
|
||||
|
||||
@ -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))
|
||||
}
|
||||
@ -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())
|
||||
@ -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(),
|
||||
};
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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())
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
@ -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))
|
||||
@ -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())
|
||||
}
|
||||
}
|
||||
|
@ -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",
|
||||
|
@ -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()
|
||||
)
|
||||
|
@ -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,
|
||||
|
@ -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.
|
||||
@ -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)?;
|
||||
|
@ -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,
|
||||
};
|
||||
|
||||
{
|
||||
|
@ -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{}",
|
||||
@ -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");
|
||||
@ -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");
|
||||
@ -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");
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user