@@ -25,9 +25,7 @@ use crate::core::Feature;
2525use crate :: core:: compiler:: { CompileKind , CompileTarget , Unit } ;
2626use crate :: core:: dependency:: Artifact ;
2727use 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 } ;
3129use crate :: util:: interning:: InternedString ;
3230use crate :: util:: toml:: validate_profile;
3331use crate :: util:: { CargoResult , GlobalContext , closest_msg, context} ;
@@ -352,11 +350,11 @@ impl Profiles {
352350 }
353351
354352 /// Used to check for overrides for non-existing packages.
355- pub fn validate_packages (
353+ pub fn validate_packages < I : Iterator < Item = PackageId > > (
356354 & self ,
357355 profiles : Option < & TomlProfiles > ,
358356 shell : & mut Shell ,
359- resolve : & Resolve ,
357+ packages : impl Fn ( ) -> I ,
360358 ) -> CargoResult < ( ) > {
361359 for ( name, profile) in & self . by_name {
362360 // If the user did not specify an override, skip this. This is here
@@ -372,13 +370,13 @@ impl Profiles {
372370 {
373371 continue ;
374372 }
375- let found = validate_packages_unique ( resolve , name, & profile. toml ) ?;
373+ let found = validate_packages_unique ( & packages , name, & profile. toml ) ?;
376374 // We intentionally do not validate unmatched packages for config
377375 // profiles, in case they are defined in a central location. This
378376 // iterates over the manifest profiles only.
379377 if let Some ( profiles) = profiles {
380378 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) ?;
382380 }
383381 }
384382 }
@@ -1335,8 +1333,8 @@ fn get_config_profile(ws: &Workspace<'_>, name: &str) -> CargoResult<Option<Toml
13351333///
13361334/// For example `[profile.dev.package.bar]` and `[profile.dev.package."bar:0.5.0"]`
13371335/// 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 ,
13401338 name : & str ,
13411339 toml : & Option < TomlProfile > ,
13421340) -> CargoResult < HashSet < PackageIdSpec > > {
@@ -1348,7 +1346,7 @@ fn validate_packages_unique(
13481346 } ;
13491347 // Verify that a package doesn't match multiple spec overrides.
13501348 let mut found = HashSet :: new ( ) ;
1351- for pkg_id in resolve . iter ( ) {
1349+ for pkg_id in packages ( ) {
13521350 let matches: Vec < & PackageIdSpec > = overrides
13531351 . keys ( )
13541352 . filter_map ( |key| match * key {
@@ -1389,9 +1387,9 @@ fn validate_packages_unique(
13891387/// Check for any profile override specs that do not match any known packages.
13901388///
13911389/// This helps check for typos and mistakes.
1392- fn validate_packages_unmatched (
1390+ fn validate_packages_unmatched < I : Iterator < Item = PackageId > > (
13931391 shell : & mut Shell ,
1394- resolve : & Resolve ,
1392+ packages : impl Fn ( ) -> I ,
13951393 name : & str ,
13961394 toml : & TomlProfile ,
13971395 found : & HashSet < PackageIdSpec > ,
@@ -1411,8 +1409,7 @@ fn validate_packages_unmatched(
14111409 } ) ;
14121410 for spec in missing_specs {
14131411 // See if there is an exact name match.
1414- let name_matches: Vec < String > = resolve
1415- . iter ( )
1412+ let name_matches: Vec < String > = packages ( )
14161413 . filter_map ( |pkg_id| {
14171414 if pkg_id. name ( ) == spec. name ( ) {
14181415 Some ( pkg_id. to_string ( ) )
@@ -1422,12 +1419,8 @@ fn validate_packages_unmatched(
14221419 } )
14231420 . collect ( ) ;
14241421 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" ) ;
14311424 shell. warn ( format ! (
14321425 "profile package spec `{}` in profile `{}` did not match any packages{}" ,
14331426 spec, name, suggestion
0 commit comments