@@ -22,9 +22,8 @@ use crate::core::compiler::{CompileKind, CompileTarget};
2222use crate :: core:: dependency:: { Artifact , ArtifactTarget , DepKind } ;
2323use crate :: core:: manifest:: { ManifestMetadata , TargetSourcePath , Warnings } ;
2424use crate :: core:: resolver:: ResolveBehavior ;
25- use crate :: core:: {
26- find_workspace_root, resolve_relative_path, Dependency , Manifest , PackageId , Summary , Target ,
27- } ;
25+ use crate :: core:: { find_workspace_root, resolve_relative_path, CliUnstable } ;
26+ use crate :: core:: { Dependency , Manifest , PackageId , Summary , Target } ;
2827use crate :: core:: { Edition , EitherManifest , Feature , Features , VirtualManifest , Workspace } ;
2928use crate :: core:: { GitReference , PackageIdSpec , SourceId , WorkspaceConfig , WorkspaceRootConfig } ;
3029use crate :: sources:: { CRATES_IO_INDEX , CRATES_IO_REGISTRY } ;
@@ -455,9 +454,18 @@ impl TomlProfiles {
455454 self . 0 . get ( name)
456455 }
457456
458- pub fn validate ( & self , features : & Features , warnings : & mut Vec < String > ) -> CargoResult < ( ) > {
457+ /// Checks syntax validity and unstable feature gate for each profile.
458+ ///
459+ /// It's a bit unfortunate both `-Z` flags and `cargo-features` are required,
460+ /// because profiles can now be set in either `Cargo.toml` or `config.toml`.
461+ pub fn validate (
462+ & self ,
463+ cli_unstable : & CliUnstable ,
464+ features : & Features ,
465+ warnings : & mut Vec < String > ,
466+ ) -> CargoResult < ( ) > {
459467 for ( name, profile) in & self . 0 {
460- profile. validate ( name, features, warnings) ?;
468+ profile. validate ( name, cli_unstable , features, warnings) ?;
461469 }
462470 Ok ( ( ) )
463471 }
@@ -592,21 +600,27 @@ impl fmt::Display for ProfilePackageSpec {
592600}
593601
594602impl TomlProfile {
603+ /// Checks stytax validity and unstable feature gate for a given profile.
595604 pub fn validate (
596605 & self ,
597606 name : & str ,
607+ cli_unstable : & CliUnstable ,
598608 features : & Features ,
599609 warnings : & mut Vec < String > ,
600610 ) -> CargoResult < ( ) > {
601- self . validate_profile ( name, features) ?;
611+ self . validate_profile ( name, cli_unstable , features) ?;
602612 if let Some ( ref profile) = self . build_override {
603613 profile. validate_override ( "build-override" ) ?;
604- profile. validate_profile ( & format ! ( "{name}.build-override" ) , features) ?;
614+ profile. validate_profile ( & format ! ( "{name}.build-override" ) , cli_unstable , features) ?;
605615 }
606616 if let Some ( ref packages) = self . package {
607617 for ( override_name, profile) in packages {
608618 profile. validate_override ( "package" ) ?;
609- profile. validate_profile ( & format ! ( "{name}.package.{override_name}" ) , features) ?;
619+ profile. validate_profile (
620+ & format ! ( "{name}.package.{override_name}" ) ,
621+ cli_unstable,
622+ features,
623+ ) ?;
610624 }
611625 }
612626
@@ -751,9 +765,21 @@ impl TomlProfile {
751765 /// Validates a profile.
752766 ///
753767 /// This is a shallow check, which is reused for the profile itself and any overrides.
754- fn validate_profile ( & self , name : & str , features : & Features ) -> CargoResult < ( ) > {
768+ fn validate_profile (
769+ & self ,
770+ name : & str ,
771+ cli_unstable : & CliUnstable ,
772+ features : & Features ,
773+ ) -> CargoResult < ( ) > {
755774 if let Some ( codegen_backend) = & self . codegen_backend {
756- features. require ( Feature :: codegen_backend ( ) ) ?;
775+ match (
776+ features. require ( Feature :: codegen_backend ( ) ) ,
777+ cli_unstable. codegen_backend ,
778+ ) {
779+ ( Err ( e) , false ) => return Err ( e) ,
780+ _ => { }
781+ }
782+
757783 if codegen_backend. contains ( |c : char | !c. is_ascii_alphanumeric ( ) && c != '_' ) {
758784 bail ! (
759785 "`profile.{}.codegen-backend` setting of `{}` is not a valid backend name." ,
@@ -763,7 +789,13 @@ impl TomlProfile {
763789 }
764790 }
765791 if self . rustflags . is_some ( ) {
766- features. require ( Feature :: profile_rustflags ( ) ) ?;
792+ match (
793+ features. require ( Feature :: profile_rustflags ( ) ) ,
794+ cli_unstable. profile_rustflags ,
795+ ) {
796+ ( Err ( e) , false ) => return Err ( e) ,
797+ _ => { }
798+ }
767799 }
768800 Ok ( ( ) )
769801 }
@@ -2065,7 +2097,8 @@ impl TomlManifest {
20652097
20662098 let profiles = me. profile . clone ( ) ;
20672099 if let Some ( profiles) = & profiles {
2068- profiles. validate ( & features, & mut warnings) ?;
2100+ let cli_unstable = config. cli_unstable ( ) ;
2101+ profiles. validate ( cli_unstable, & features, & mut warnings) ?;
20692102 }
20702103
20712104 let publish = package
@@ -2254,7 +2287,7 @@ impl TomlManifest {
22542287 } ;
22552288 let profiles = me. profile . clone ( ) ;
22562289 if let Some ( profiles) = & profiles {
2257- profiles. validate ( & features, & mut warnings) ?;
2290+ profiles. validate ( config . cli_unstable ( ) , & features, & mut warnings) ?;
22582291 }
22592292 let resolve_behavior = me
22602293 . workspace
0 commit comments