Skip to content

Commit f05ef87

Browse files
committed
Remove unneeded mut and loop
1 parent de31a34 commit f05ef87

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

src/cargo/core/resolver/resolve.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,9 @@ impl Resolve {
119119

120120
pub fn register_used_patches(&mut self, patches: &[Summary]) {
121121
for summary in patches {
122-
if self.iter().any(|id| id == summary.package_id()) {
123-
continue;
124-
}
125-
self.unused_patches.push(summary.package_id());
122+
if !self.graph.contains(&summary.package_id()) {
123+
self.unused_patches.push(summary.package_id())
124+
};
126125
}
127126
}
128127

src/cargo/ops/resolve.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,14 @@ pub fn resolve_with_previous<'cfg>(
216216
//
217217
// TODO: this seems like a hokey reason to single out the registry as being
218218
// different.
219-
let mut to_avoid_sources: HashSet<SourceId> = HashSet::new();
220-
if let Some(to_avoid) = to_avoid {
221-
to_avoid_sources.extend(
222-
to_avoid
223-
.iter()
219+
let to_avoid_sources: HashSet<SourceId> = to_avoid
220+
.map(|set| {
221+
set.iter()
224222
.map(|p| p.source_id())
225-
.filter(|s| !s.is_registry()),
226-
);
227-
}
223+
.filter(|s| !s.is_registry())
224+
.collect()
225+
})
226+
.unwrap_or_default();
228227

229228
let pre_patch_keep = |p: &PackageId| {
230229
!to_avoid_sources.contains(&p.source_id())
@@ -286,18 +285,23 @@ pub fn resolve_with_previous<'cfg>(
286285
// In the case where a previous instance of resolve is available, we
287286
// want to lock as many packages as possible to the previous version
288287
// without disturbing the graph structure.
289-
let mut try_to_use = HashSet::new();
290288
if let Some(r) = previous {
291289
trace!("previous: {:?}", r);
292290
register_previous_locks(ws, registry, r, &keep);
293-
294-
// Everything in the previous lock file we want to keep is prioritized
295-
// in dependency selection if it comes up, aka we want to have
296-
// conservative updates.
297-
try_to_use.extend(r.iter().filter(keep).inspect(|id| {
298-
debug!("attempting to prefer {}", id);
299-
}));
300291
}
292+
// Everything in the previous lock file we want to keep is prioritized
293+
// in dependency selection if it comes up, aka we want to have
294+
// conservative updates.
295+
let try_to_use = previous
296+
.map(|r| {
297+
r.iter()
298+
.filter(keep)
299+
.inspect(|id| {
300+
debug!("attempting to prefer {}", id);
301+
})
302+
.collect()
303+
})
304+
.unwrap_or_default();
301305

302306
if register_patches {
303307
registry.lock_patches();

0 commit comments

Comments
 (0)