Skip to content

Commit 335ad2b

Browse files
committed
Auto merge of #9323 - matthiaskrgr:clippy_v19, r=ehuss
fix clippy warnings fixes these clippy warnings: map_collect_result_unit needless_borrow needless_return into_iter_on_ref manual_flatten match_like_matches_macro bool_comparison
2 parents 10ef854 + 1b7fa21 commit 335ad2b

17 files changed

+50
-52
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,8 +788,7 @@ impl RustDocFingerprint {
788788
doc_dirs
789789
.iter()
790790
.filter(|path| path.exists())
791-
.map(|path| paths::remove_dir_all(&path))
792-
.collect::<CargoResult<()>>()
791+
.try_for_each(|path| paths::remove_dir_all(&path))
793792
}
794793

795794
/// This function checks whether the latest version of `Rustc` used to compile this

src/cargo/core/resolver/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl Context {
170170
// package again, which should only affect performance, but that
171171
// should be rare. Cycles should still be detected since those
172172
// will have `DepFeatures` edges.
173-
RequestedFeatures::CliFeatures(_) => return Ok(false),
173+
RequestedFeatures::CliFeatures(_) => Ok(false),
174174
RequestedFeatures::DepFeatures {
175175
features,
176176
uses_default_features,

src/cargo/core/resolver/dep_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ fn build_requirements<'a, 'b: 'a>(
333333
}
334334
} else {
335335
for fv in features.iter() {
336-
if let Err(e) = reqs.require_value(&fv) {
336+
if let Err(e) = reqs.require_value(fv) {
337337
return Err(e.into_activate_error(parent, s));
338338
}
339339
}

src/cargo/core/resolver/features.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl ResolvedFeatures {
367367
// The new resolver should never add features.
368368
assert_eq!(new_features.difference(&old_features).next(), None);
369369
let removed_features: BTreeSet<_> =
370-
old_features.difference(&new_features).cloned().collect();
370+
old_features.difference(new_features).cloned().collect();
371371
if removed_features.is_empty() {
372372
None
373373
} else {
@@ -386,7 +386,7 @@ impl ResolvedFeatures {
386386
};
387387
// The new resolver should never add dependencies.
388388
assert_eq!(new_deps.difference(&old_deps).next(), None);
389-
let removed_deps: BTreeSet<_> = old_deps.difference(&new_deps).cloned().collect();
389+
let removed_deps: BTreeSet<_> = old_deps.difference(new_deps).cloned().collect();
390390
if removed_deps.is_empty() {
391391
None
392392
} else {

src/cargo/core/resolver/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ fn activate(
624624
}
625625
}
626626

627-
let activated = cx.flag_activated(&candidate, &opts, parent)?;
627+
let activated = cx.flag_activated(&candidate, opts, parent)?;
628628

629629
let candidate = match registry.replacement_summary(candidate_pid) {
630630
Some(replace) => {
@@ -633,7 +633,7 @@ fn activate(
633633
// does. TBH it basically cause panics in the test suite if
634634
// `parent` is passed through here and `[replace]` is otherwise
635635
// on life support so it's not critical to fix bugs anyway per se.
636-
if cx.flag_activated(replace, &opts, None)? && activated {
636+
if cx.flag_activated(replace, opts, None)? && activated {
637637
return Ok(None);
638638
}
639639
trace!(
@@ -654,7 +654,7 @@ fn activate(
654654

655655
let now = Instant::now();
656656
let (used_features, deps) =
657-
&*registry.build_deps(cx, parent.map(|p| p.0.package_id()), &candidate, &opts)?;
657+
&*registry.build_deps(cx, parent.map(|p| p.0.package_id()), &candidate, opts)?;
658658

659659
// Record what list of features is active for this package.
660660
if !used_features.is_empty() {

src/cargo/core/workspace.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ impl<'cfg> Workspace<'cfg> {
404404
/* platform */ None,
405405
// NOTE: Since we use ConfigRelativePath, this root isn't used as
406406
// any relative paths are resolved before they'd be joined with root.
407-
&Path::new("unused-relative-path"),
407+
Path::new("unused-relative-path"),
408408
self.unstable_features(),
409409
/* kind */ None,
410410
)
@@ -436,7 +436,7 @@ impl<'cfg> Workspace<'cfg> {
436436
return Ok(from_manifest.clone());
437437
}
438438
if from_manifest.is_empty() {
439-
return Ok(from_config.clone());
439+
return Ok(from_config);
440440
}
441441

442442
// We could just chain from_manifest and from_config,

src/cargo/ops/cargo_compile.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -791,12 +791,13 @@ impl CompileFilter {
791791
}
792792

793793
pub fn is_all_targets(&self) -> bool {
794-
match *self {
794+
matches!(
795+
*self,
795796
CompileFilter::Only {
796-
all_targets: true, ..
797-
} => true,
798-
_ => false,
799-
}
797+
all_targets: true,
798+
..
799+
}
800+
)
800801
}
801802

802803
pub(crate) fn contains_glob_patterns(&self) -> bool {

src/cargo/ops/cargo_config.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ fn print_toml(config: &Config, opts: &GetOptions<'_>, key: &ConfigKey, cv: &CV)
123123
format!(" # {}", def)
124124
};
125125
match cv {
126-
CV::Boolean(val, def) => drop_println!(config, "{} = {}{}", key, val, origin(&def)),
127-
CV::Integer(val, def) => drop_println!(config, "{} = {}{}", key, val, origin(&def)),
126+
CV::Boolean(val, def) => drop_println!(config, "{} = {}{}", key, val, origin(def)),
127+
CV::Integer(val, def) => drop_println!(config, "{} = {}{}", key, val, origin(def)),
128128
CV::String(val, def) => drop_println!(
129129
config,
130130
"{} = {}{}",
131131
key,
132132
toml::to_string(&val).unwrap(),
133-
origin(&def)
133+
origin(def)
134134
),
135135
CV::List(vals, _def) => {
136136
if opts.show_origin {
@@ -145,13 +145,13 @@ fn print_toml(config: &Config, opts: &GetOptions<'_>, key: &ConfigKey, cv: &CV)
145145
}
146146
}
147147
CV::Table(table, _def) => {
148-
let mut key_vals: Vec<_> = table.into_iter().collect();
149-
key_vals.sort_by(|a, b| a.0.cmp(&b.0));
148+
let mut key_vals: Vec<_> = table.iter().collect();
149+
key_vals.sort_by(|a, b| a.0.cmp(b.0));
150150
for (table_key, val) in key_vals {
151151
let mut subkey = key.clone();
152152
// push or push_sensitive shouldn't matter here, since this is
153153
// not dealing with environment variables.
154-
subkey.push(&table_key);
154+
subkey.push(table_key);
155155
print_toml(config, opts, &subkey, val);
156156
}
157157
}
@@ -205,7 +205,7 @@ fn print_json(config: &Config, key: &ConfigKey, cv: &CV, include_key: bool) {
205205
CV::Integer(val, _def) => json!(val),
206206
CV::String(val, _def) => json!(val),
207207
CV::List(vals, _def) => {
208-
let jvals: Vec<_> = vals.into_iter().map(|(val, _def)| json!(val)).collect();
208+
let jvals: Vec<_> = vals.iter().map(|(val, _def)| json!(val)).collect();
209209
json!(jvals)
210210
}
211211
CV::Table(map, _def) => {

src/cargo/ops/cargo_install.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -703,21 +703,19 @@ fn remove_orphaned_bins(
703703
let all_self_names = exe_names(pkg, &filter);
704704
let mut to_remove: HashMap<PackageId, BTreeSet<String>> = HashMap::new();
705705
// For each package that we stomped on.
706-
for other_pkg in duplicates.values() {
706+
for other_pkg in duplicates.values().flatten() {
707707
// Only for packages with the same name.
708-
if let Some(other_pkg) = other_pkg {
709-
if other_pkg.name() == pkg.name() {
710-
// Check what the old package had installed.
711-
if let Some(installed) = tracker.installed_bins(*other_pkg) {
712-
// If the old install has any names that no longer exist,
713-
// add them to the list to remove.
714-
for installed_name in installed {
715-
if !all_self_names.contains(installed_name.as_str()) {
716-
to_remove
717-
.entry(*other_pkg)
718-
.or_default()
719-
.insert(installed_name.clone());
720-
}
708+
if other_pkg.name() == pkg.name() {
709+
// Check what the old package had installed.
710+
if let Some(installed) = tracker.installed_bins(*other_pkg) {
711+
// If the old install has any names that no longer exist,
712+
// add them to the list to remove.
713+
for installed_name in installed {
714+
if !all_self_names.contains(installed_name.as_str()) {
715+
to_remove
716+
.entry(*other_pkg)
717+
.or_default()
718+
.insert(installed_name.clone());
721719
}
722720
}
723721
}

src/cargo/ops/common_for_install_and_uninstall.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ impl InstallInfo {
492492
fn is_up_to_date(&self, opts: &CompileOptions, target: &str, exes: &BTreeSet<String>) -> bool {
493493
self.features == feature_set(&opts.cli_features.features)
494494
&& self.all_features == opts.cli_features.all_features
495-
&& self.no_default_features == !opts.cli_features.uses_default_features
495+
&& self.no_default_features != opts.cli_features.uses_default_features
496496
&& self.profile.as_str() == opts.build_config.requested_profile.as_str()
497497
&& (self.target.is_none() || self.target.as_deref() == Some(target))
498498
&& &self.bins == exes

src/cargo/util/config/key.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ impl fmt::Display for ConfigKey {
103103
}
104104

105105
fn escape_key_part<'a>(part: &'a str) -> Cow<'a, str> {
106-
let ok = part.chars().all(|c| match c {
107-
'a'..='z' | 'A'..='Z' | '0'..='9' | '-' | '_' => true,
108-
_ => false,
106+
let ok = part.chars().all(|c| {
107+
matches!(c,
108+
'a'..='z' | 'A'..='Z' | '0'..='9' | '-' | '_')
109109
});
110110
if ok {
111111
Cow::Borrowed(part)

tests/testsuite/build_script.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3985,7 +3985,7 @@ fn build_script_scan_eacces() {
39853985
.file("secrets/stuff", "")
39863986
.build();
39873987
let path = p.root().join("secrets");
3988-
fs::set_permissions(&path, fs::Permissions::from_mode(0)).unwrap();
3988+
fs::set_permissions(&path, fs::Permissions::from_mode(0o0)).unwrap();
39893989
// The last "Caused by" is a string from libc such as the following:
39903990
// Permission denied (os error 13)
39913991
p.cargo("build")

tests/testsuite/features2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ fn itarget_proc_macro() {
201201
Package::new("hostdep", "1.0.0").publish();
202202
Package::new("pm", "1.0.0")
203203
.proc_macro(true)
204-
.target_dep("hostdep", "1.0", &rustc_host())
204+
.target_dep("hostdep", "1.0", rustc_host())
205205
.file("src/lib.rs", "extern crate hostdep;")
206206
.publish();
207207
let p = project()
@@ -1203,7 +1203,7 @@ fn build_dep_activated() {
12031203
Package::new("targetdep", "1.0.0").publish();
12041204
Package::new("hostdep", "1.0.0")
12051205
// Check that "for_host" is sticky.
1206-
.target_dep("somedep", "1.0", &rustc_host())
1206+
.target_dep("somedep", "1.0", rustc_host())
12071207
.feature("feat1", &[])
12081208
.file(
12091209
"src/lib.rs",

tests/testsuite/future_incompat_report.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ fn test_multi_crate() {
164164
let stderr = std::str::from_utf8(&output.stderr).unwrap();
165165

166166
// Find '--id <ID>' in the output
167-
let mut iter = stderr.split(" ");
167+
let mut iter = stderr.split(' ');
168168
iter.find(|w| *w == "--id").unwrap();
169169
let id = iter
170170
.next()

tests/testsuite/metadata.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,7 +2358,7 @@ fn filter_platform() {
23582358
}
23592359
"#
23602360
.replace("$ALT_TRIPLE", alt_target)
2361-
.replace("$HOST_TRIPLE", &host_target)
2361+
.replace("$HOST_TRIPLE", host_target)
23622362
.replace("$FOO_DEPS", &foo_deps.to_string());
23632363

23642364
// We're going to be checking that we don't download excessively,
@@ -2483,7 +2483,7 @@ fn filter_platform() {
24832483
}
24842484
"#
24852485
.replace("$ALT_TRIPLE", alt_target)
2486-
.replace("$HOST_TRIPLE", &host_target)
2486+
.replace("$HOST_TRIPLE", host_target)
24872487
.replace("$ALT_DEP", alt_dep)
24882488
.replace("$CFG_DEP", cfg_dep)
24892489
.replace("$HOST_DEP", host_dep)
@@ -2648,7 +2648,7 @@ fn filter_platform() {
26482648
"metadata": null
26492649
}
26502650
"#
2651-
.replace("$HOST_TRIPLE", &host_target)
2651+
.replace("$HOST_TRIPLE", host_target)
26522652
.replace("$HOST_DEP", host_dep)
26532653
.replace("$NORMAL_DEP", normal_dep)
26542654
.replace("$FOO", &foo),
@@ -2749,7 +2749,7 @@ fn filter_platform() {
27492749
"metadata": null
27502750
}
27512751
"#
2752-
.replace("$HOST_TRIPLE", &host_target)
2752+
.replace("$HOST_TRIPLE", host_target)
27532753
.replace("$CFG_DEP", cfg_dep)
27542754
.replace("$HOST_DEP", host_dep)
27552755
.replace("$NORMAL_DEP", normal_dep)

tests/testsuite/multitarget.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn simple_build() {
3636
.run();
3737

3838
assert!(p.target_bin(t1, "foo").is_file());
39-
assert!(p.target_bin(&t2, "foo").is_file());
39+
assert!(p.target_bin(t2, "foo").is_file());
4040
}
4141

4242
#[cargo_test]
@@ -140,5 +140,5 @@ fn same_value_twice() {
140140
.masquerade_as_nightly_cargo()
141141
.run();
142142

143-
assert!(p.target_bin(&t, "foo").is_file());
143+
assert!(p.target_bin(t, "foo").is_file());
144144
}

tests/testsuite/tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ fn filters_target() {
367367
Package::new("build_target_dep", "1.0.0").publish();
368368
Package::new("build_host_dep", "1.0.0")
369369
.target_dep("targetdep", "1.0", alternate())
370-
.target_dep("hostdep", "1.0", &rustc_host())
370+
.target_dep("hostdep", "1.0", rustc_host())
371371
.publish();
372372
Package::new("pm_target", "1.0.0")
373373
.proc_macro(true)

0 commit comments

Comments
 (0)