@@ -22,9 +22,8 @@ use crate::core::compiler::{CompileKind, CompileTarget};
22
22
use crate :: core:: dependency:: { Artifact , ArtifactTarget , DepKind } ;
23
23
use crate :: core:: manifest:: { ManifestMetadata , TargetSourcePath , Warnings } ;
24
24
use 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 } ;
28
27
use crate :: core:: { Edition , EitherManifest , Feature , Features , VirtualManifest , Workspace } ;
29
28
use crate :: core:: { GitReference , PackageIdSpec , SourceId , WorkspaceConfig , WorkspaceRootConfig } ;
30
29
use crate :: sources:: { CRATES_IO_INDEX , CRATES_IO_REGISTRY } ;
@@ -455,9 +454,18 @@ impl TomlProfiles {
455
454
self . 0 . get ( name)
456
455
}
457
456
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 < ( ) > {
459
467
for ( name, profile) in & self . 0 {
460
- profile. validate ( name, features, warnings) ?;
468
+ profile. validate ( name, cli_unstable , features, warnings) ?;
461
469
}
462
470
Ok ( ( ) )
463
471
}
@@ -592,21 +600,27 @@ impl fmt::Display for ProfilePackageSpec {
592
600
}
593
601
594
602
impl TomlProfile {
603
+ /// Checks stytax validity and unstable feature gate for a given profile.
595
604
pub fn validate (
596
605
& self ,
597
606
name : & str ,
607
+ cli_unstable : & CliUnstable ,
598
608
features : & Features ,
599
609
warnings : & mut Vec < String > ,
600
610
) -> CargoResult < ( ) > {
601
- self . validate_profile ( name, features) ?;
611
+ self . validate_profile ( name, cli_unstable , features) ?;
602
612
if let Some ( ref profile) = self . build_override {
603
613
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) ?;
605
615
}
606
616
if let Some ( ref packages) = self . package {
607
617
for ( override_name, profile) in packages {
608
618
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
+ ) ?;
610
624
}
611
625
}
612
626
@@ -751,9 +765,21 @@ impl TomlProfile {
751
765
/// Validates a profile.
752
766
///
753
767
/// 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 < ( ) > {
755
774
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
+
757
783
if codegen_backend. contains ( |c : char | !c. is_ascii_alphanumeric ( ) && c != '_' ) {
758
784
bail ! (
759
785
"`profile.{}.codegen-backend` setting of `{}` is not a valid backend name." ,
@@ -763,7 +789,13 @@ impl TomlProfile {
763
789
}
764
790
}
765
791
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
+ }
767
799
}
768
800
Ok ( ( ) )
769
801
}
@@ -2065,7 +2097,8 @@ impl TomlManifest {
2065
2097
2066
2098
let profiles = me. profile . clone ( ) ;
2067
2099
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) ?;
2069
2102
}
2070
2103
2071
2104
let publish = package
@@ -2254,7 +2287,7 @@ impl TomlManifest {
2254
2287
} ;
2255
2288
let profiles = me. profile . clone ( ) ;
2256
2289
if let Some ( profiles) = & profiles {
2257
- profiles. validate ( & features, & mut warnings) ?;
2290
+ profiles. validate ( config . cli_unstable ( ) , & features, & mut warnings) ?;
2258
2291
}
2259
2292
let resolve_behavior = me
2260
2293
. workspace
0 commit comments