@@ -25,9 +25,7 @@ use crate::core::Feature;
25
25
use crate :: core:: compiler:: { CompileKind , CompileTarget , Unit } ;
26
26
use crate :: core:: dependency:: Artifact ;
27
27
use crate :: core:: resolver:: features:: FeaturesFor ;
28
- use crate :: core:: {
29
- PackageId , PackageIdSpec , PackageIdSpecQuery , Resolve , Shell , Target , Workspace ,
30
- } ;
28
+ use crate :: core:: { PackageId , PackageIdSpec , PackageIdSpecQuery , Shell , Target , Workspace } ;
31
29
use crate :: util:: interning:: InternedString ;
32
30
use crate :: util:: toml:: validate_profile;
33
31
use crate :: util:: { CargoResult , GlobalContext , closest_msg, context} ;
@@ -352,11 +350,11 @@ impl Profiles {
352
350
}
353
351
354
352
/// Used to check for overrides for non-existing packages.
355
- pub fn validate_packages (
353
+ pub fn validate_packages < I : Iterator < Item = PackageId > > (
356
354
& self ,
357
355
profiles : Option < & TomlProfiles > ,
358
356
shell : & mut Shell ,
359
- resolve : & Resolve ,
357
+ packages : impl Fn ( ) -> I ,
360
358
) -> CargoResult < ( ) > {
361
359
for ( name, profile) in & self . by_name {
362
360
// If the user did not specify an override, skip this. This is here
@@ -372,13 +370,13 @@ impl Profiles {
372
370
{
373
371
continue ;
374
372
}
375
- let found = validate_packages_unique ( resolve , name, & profile. toml ) ?;
373
+ let found = validate_packages_unique ( & packages , name, & profile. toml ) ?;
376
374
// We intentionally do not validate unmatched packages for config
377
375
// profiles, in case they are defined in a central location. This
378
376
// iterates over the manifest profiles only.
379
377
if let Some ( profiles) = profiles {
380
378
if let Some ( toml_profile) = profiles. get ( name) {
381
- validate_packages_unmatched ( shell, resolve , name, toml_profile, & found) ?;
379
+ validate_packages_unmatched ( shell, & packages , name, toml_profile, & found) ?;
382
380
}
383
381
}
384
382
}
@@ -1335,8 +1333,8 @@ fn get_config_profile(ws: &Workspace<'_>, name: &str) -> CargoResult<Option<Toml
1335
1333
///
1336
1334
/// For example `[profile.dev.package.bar]` and `[profile.dev.package."bar:0.5.0"]`
1337
1335
/// would both match `bar:0.5.0` which would be ambiguous.
1338
- fn validate_packages_unique (
1339
- resolve : & Resolve ,
1336
+ fn validate_packages_unique < I : Iterator < Item = PackageId > > (
1337
+ packages : impl Fn ( ) -> I ,
1340
1338
name : & str ,
1341
1339
toml : & Option < TomlProfile > ,
1342
1340
) -> CargoResult < HashSet < PackageIdSpec > > {
@@ -1348,7 +1346,7 @@ fn validate_packages_unique(
1348
1346
} ;
1349
1347
// Verify that a package doesn't match multiple spec overrides.
1350
1348
let mut found = HashSet :: new ( ) ;
1351
- for pkg_id in resolve . iter ( ) {
1349
+ for pkg_id in packages ( ) {
1352
1350
let matches: Vec < & PackageIdSpec > = overrides
1353
1351
. keys ( )
1354
1352
. filter_map ( |key| match * key {
@@ -1389,9 +1387,9 @@ fn validate_packages_unique(
1389
1387
/// Check for any profile override specs that do not match any known packages.
1390
1388
///
1391
1389
/// This helps check for typos and mistakes.
1392
- fn validate_packages_unmatched (
1390
+ fn validate_packages_unmatched < I : Iterator < Item = PackageId > > (
1393
1391
shell : & mut Shell ,
1394
- resolve : & Resolve ,
1392
+ packages : impl Fn ( ) -> I ,
1395
1393
name : & str ,
1396
1394
toml : & TomlProfile ,
1397
1395
found : & HashSet < PackageIdSpec > ,
@@ -1411,8 +1409,7 @@ fn validate_packages_unmatched(
1411
1409
} ) ;
1412
1410
for spec in missing_specs {
1413
1411
// See if there is an exact name match.
1414
- let name_matches: Vec < String > = resolve
1415
- . iter ( )
1412
+ let name_matches: Vec < String > = packages ( )
1416
1413
. filter_map ( |pkg_id| {
1417
1414
if pkg_id. name ( ) == spec. name ( ) {
1418
1415
Some ( pkg_id. to_string ( ) )
@@ -1422,12 +1419,8 @@ fn validate_packages_unmatched(
1422
1419
} )
1423
1420
. collect ( ) ;
1424
1421
if name_matches. is_empty ( ) {
1425
- let suggestion = closest_msg (
1426
- & spec. name ( ) ,
1427
- resolve. iter ( ) ,
1428
- |p| p. name ( ) . as_str ( ) ,
1429
- "package" ,
1430
- ) ;
1422
+ let suggestion =
1423
+ closest_msg ( & spec. name ( ) , packages ( ) , |p| p. name ( ) . as_str ( ) , "package" ) ;
1431
1424
shell. warn ( format ! (
1432
1425
"profile package spec `{}` in profile `{}` did not match any packages{}" ,
1433
1426
spec, name, suggestion
0 commit comments