@@ -255,37 +255,35 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
255
255
( dep. name ( ) . as_str ( ) , dep. source_id ( ) )
256
256
}
257
257
258
- // Removes all package IDs in `b` from `a`. Note that this is somewhat
259
- // more complicated because the equality for source IDs does not take
260
- // precise versions into account (e.g., git shas), but we want to take
261
- // that into account here.
262
258
fn vec_subtract ( a : & [ PackageId ] , b : & [ PackageId ] ) -> Vec < PackageId > {
263
- a. iter ( )
264
- . filter ( |a| {
265
- // If this package ID is not found in `b`, then it's definitely
266
- // in the subtracted set.
267
- let Ok ( i) = b. binary_search ( a) else {
268
- return true ;
269
- } ;
259
+ a. iter ( ) . filter ( |a| !contains_id ( b, a) ) . cloned ( ) . collect ( )
260
+ }
270
261
271
- // If we've found `a` in `b`, then we iterate over all instances
272
- // (we know `b` is sorted) and see if they all have different
273
- // precise versions. If so, then `a` isn't actually in `b` so
274
- // we'll let it through.
275
- //
276
- // Note that we only check this for non-registry sources,
277
- // however, as registries contain enough version information in
278
- // the package ID to disambiguate.
279
- if a. source_id ( ) . is_registry ( ) {
280
- return false ;
281
- }
282
- b[ i..]
283
- . iter ( )
284
- . take_while ( |b| a == b)
285
- . all ( |b| !a. source_id ( ) . has_same_precise_as ( b. source_id ( ) ) )
286
- } )
287
- . cloned ( )
288
- . collect ( )
262
+ // Check if a PackageId is present `b` from `a`.
263
+ //
264
+ // Note that this is somewhat more complicated because the equality for source IDs does not
265
+ // take precise versions into account (e.g., git shas), but we want to take that into
266
+ // account here.
267
+ fn contains_id ( haystack : & [ PackageId ] , needle : & PackageId ) -> bool {
268
+ let Ok ( i) = haystack. binary_search ( needle) else {
269
+ return false ;
270
+ } ;
271
+
272
+ // If we've found `a` in `b`, then we iterate over all instances
273
+ // (we know `b` is sorted) and see if they all have different
274
+ // precise versions. If so, then `a` isn't actually in `b` so
275
+ // we'll let it through.
276
+ //
277
+ // Note that we only check this for non-registry sources,
278
+ // however, as registries contain enough version information in
279
+ // the package ID to disambiguate.
280
+ if needle. source_id ( ) . is_registry ( ) {
281
+ return true ;
282
+ }
283
+ haystack[ i..]
284
+ . iter ( )
285
+ . take_while ( |b| & needle == b)
286
+ . any ( |b| needle. source_id ( ) . has_same_precise_as ( b. source_id ( ) ) )
289
287
}
290
288
291
289
// Map `(package name, package source)` to `(removed versions, added versions)`.
0 commit comments