Skip to content

Commit 0b2059e

Browse files
committed
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.
2 parents e35b99a + e58c544 commit 0b2059e

File tree

13 files changed

+27
-35
lines changed

13 files changed

+27
-35
lines changed

src/bin/cargo/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,8 @@ fn aliased_command(config: &Config, command: &str) -> CargoResult<Option<Vec<Str
7676
Err(_) => config.get::<Option<Vec<String>>>(&alias_name)?,
7777
};
7878

79-
let result = user_alias.or_else(|| match builtin_aliases_execs(command) {
80-
Some(command_str) => Some(vec![command_str.1.to_string()]),
81-
None => None,
79+
let result = user_alias.or_else(|| {
80+
builtin_aliases_execs(command).map(|command_str| vec![command_str.1.to_string()])
8281
});
8382
Ok(result)
8483
}

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -699,10 +699,10 @@ impl RustcTargetData {
699699

700700
Ok(RustcTargetData {
701701
rustc,
702-
target_config,
703-
target_info,
704702
host_config,
705703
host_info,
704+
target_config,
705+
target_info,
706706
})
707707
}
708708

@@ -766,7 +766,7 @@ pub struct RustDocFingerprint {
766766

767767
impl RustDocFingerprint {
768768
/// Read the `RustDocFingerprint` info from the fingerprint file.
769-
fn read<'a, 'cfg>(cx: &Context<'a, 'cfg>) -> CargoResult<Self> {
769+
fn read(cx: &Context<'_, '_>) -> CargoResult<Self> {
770770
let rustdoc_data = paths::read(&cx.files().host_root().join(".rustdoc_fingerprint.json"))?;
771771
serde_json::from_str(&rustdoc_data).map_err(|e| anyhow::anyhow!("{:?}", e))
772772
}
@@ -779,7 +779,7 @@ impl RustDocFingerprint {
779779
)
780780
}
781781

782-
fn remove_doc_dirs(doc_dirs: &Vec<&Path>) -> CargoResult<()> {
782+
fn remove_doc_dirs(doc_dirs: &[&Path]) -> CargoResult<()> {
783783
doc_dirs
784784
.iter()
785785
.filter(|path| path.exists())
@@ -795,7 +795,7 @@ impl RustDocFingerprint {
795795
/// the rustdoc fingerprint info in order to guarantee that we won't end up with mixed
796796
/// versions of the `js/html/css` files that `rustdoc` autogenerates which do not have
797797
/// any versioning.
798-
pub fn check_rustdoc_fingerprint<'a, 'cfg>(cx: &Context<'a, 'cfg>) -> CargoResult<()> {
798+
pub fn check_rustdoc_fingerprint(cx: &Context<'_, '_>) -> CargoResult<()> {
799799
let actual_rustdoc_target_data = RustDocFingerprint {
800800
rustc_vv: cx.bcx.rustc().verbose_version.clone(),
801801
};

src/cargo/core/compiler/compilation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ impl<'cfg> Compilation<'cfg> {
341341
if self.config.cli_unstable().configurable_env {
342342
// Apply any environment variables from the config
343343
for (key, value) in self.config.env_config()?.iter() {
344-
if value.is_force() || cmd.get_env(&key).is_none() {
345-
cmd.env(&key, value.resolve(&self.config));
344+
if value.is_force() || cmd.get_env(key).is_none() {
345+
cmd.env(key, value.resolve(self.config));
346346
}
347347
}
348348
}

src/cargo/core/package.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,11 @@ impl<'cfg> PackageSet<'cfg> {
434434
})
435435
}
436436

437-
pub fn package_ids<'a>(&'a self) -> impl Iterator<Item = PackageId> + 'a {
437+
pub fn package_ids(&self) -> impl Iterator<Item = PackageId> + '_ {
438438
self.packages.keys().cloned()
439439
}
440440

441-
pub fn packages<'a>(&'a self) -> impl Iterator<Item = &'a Package> + 'a {
441+
pub fn packages(&self) -> impl Iterator<Item = &Package> {
442442
self.packages.values().filter_map(|p| p.borrow())
443443
}
444444

src/cargo/core/resolver/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ unable to verify that `{0}` is the same as when the lockfile was generated
236236
self.graph.sort()
237237
}
238238

239-
pub fn iter<'a>(&'a self) -> impl Iterator<Item = PackageId> + 'a {
239+
pub fn iter(&self) -> impl Iterator<Item = PackageId> + '_ {
240240
self.graph.iter().cloned()
241241
}
242242

src/cargo/core/resolver/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl DepsFrame {
173173
.unwrap_or(0)
174174
}
175175

176-
pub fn flatten<'a>(&'a self) -> impl Iterator<Item = (PackageId, Dependency)> + 'a {
176+
pub fn flatten(&self) -> impl Iterator<Item = (PackageId, Dependency)> + '_ {
177177
self.remaining_siblings
178178
.clone()
179179
.map(move |(d, _, _)| (self.parent.package_id(), d))
@@ -247,7 +247,7 @@ impl RemainingDeps {
247247
}
248248
None
249249
}
250-
pub fn iter<'a>(&'a mut self) -> impl Iterator<Item = (PackageId, Dependency)> + 'a {
250+
pub fn iter(&mut self) -> impl Iterator<Item = (PackageId, Dependency)> + '_ {
251251
self.data.iter().flat_map(|(other, _)| other.flatten())
252252
}
253253
}

src/cargo/ops/cargo_new.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -831,10 +831,7 @@ fn discover_author(path: &Path) -> (Option<String>, Option<String>) {
831831
.or_else(|| git_config.and_then(|g| g.get_string("user.name").ok()))
832832
.or_else(|| get_environment_variable(&name_variables[3..]));
833833

834-
let name = match name {
835-
Some(namestr) => Some(namestr.trim().to_string()),
836-
None => None,
837-
};
834+
let name = name.map(|namestr| namestr.trim().to_string());
838835

839836
let email_variables = [
840837
"CARGO_EMAIL",

src/cargo/ops/cargo_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn run_unit_tests(
9292
"{} ({})",
9393
test_path
9494
.strip_prefix(unit.pkg.root())
95-
.unwrap_or(&test_path)
95+
.unwrap_or(test_path)
9696
.display(),
9797
path.strip_prefix(cwd).unwrap_or(path).display()
9898
)

src/cargo/sources/registry/index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ impl IndexSummary {
837837
}
838838
}
839839

840-
fn split<'a>(haystack: &'a [u8], needle: u8) -> impl Iterator<Item = &'a [u8]> + 'a {
840+
fn split(haystack: &[u8], needle: u8) -> impl Iterator<Item = &[u8]> {
841841
struct Split<'a> {
842842
haystack: &'a [u8],
843843
needle: u8,

src/cargo/util/config/mod.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,9 @@ impl Config {
315315

316316
/// Gets the default Cargo registry.
317317
pub fn default_registry(&self) -> CargoResult<Option<String>> {
318-
Ok(match self.get_string("registry.default")? {
319-
Some(registry) => Some(registry.val),
320-
None => None,
321-
})
318+
Ok(self
319+
.get_string("registry.default")?
320+
.map(|registry| registry.val))
322321
}
323322

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

811-
let cli_target_dir = match target_dir.as_ref() {
812-
Some(dir) => Some(Filesystem::new(dir.clone())),
813-
None => None,
814-
};
810+
let cli_target_dir = target_dir.as_ref().map(|dir| Filesystem::new(dir.clone()));
815811

816812
self.shell().set_verbosity(verbosity);
817813
self.shell().set_color_choice(color)?;

0 commit comments

Comments
 (0)