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

File tree

17 files changed

+50
-52
lines changed

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

0 commit comments

Comments
 (0)