@@ -458,10 +458,7 @@ impl ser::Serialize for ProfilePackageSpec {
458
458
where
459
459
S : ser:: Serializer ,
460
460
{
461
- match * self {
462
- ProfilePackageSpec :: Spec ( ref spec) => spec. serialize ( s) ,
463
- ProfilePackageSpec :: All => "*" . serialize ( s) ,
464
- }
461
+ self . to_string ( ) . serialize ( s)
465
462
}
466
463
}
467
464
@@ -481,21 +478,33 @@ impl<'de> de::Deserialize<'de> for ProfilePackageSpec {
481
478
}
482
479
}
483
480
481
+ impl fmt:: Display for ProfilePackageSpec {
482
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
483
+ match self {
484
+ ProfilePackageSpec :: Spec ( spec) => spec. fmt ( f) ,
485
+ ProfilePackageSpec :: All => f. write_str ( "*" ) ,
486
+ }
487
+ }
488
+ }
489
+
484
490
impl TomlProfile {
485
491
pub fn validate (
486
492
& self ,
487
493
name : & str ,
488
494
features : & Features ,
489
495
warnings : & mut Vec < String > ,
490
496
) -> CargoResult < ( ) > {
497
+ self . validate_profile ( name, features) ?;
491
498
if let Some ( ref profile) = self . build_override {
492
499
features. require ( Feature :: profile_overrides ( ) ) ?;
493
- profile. validate_override ( "build-override" , features) ?;
500
+ profile. validate_override ( "build-override" ) ?;
501
+ profile. validate_profile ( & format ! ( "{name}.build-override" ) , features) ?;
494
502
}
495
503
if let Some ( ref packages) = self . package {
496
504
features. require ( Feature :: profile_overrides ( ) ) ?;
497
- for profile in packages. values ( ) {
498
- profile. validate_override ( "package" , features) ?;
505
+ for ( override_name, profile) in packages {
506
+ profile. validate_override ( "package" ) ?;
507
+ profile. validate_profile ( & format ! ( "{name}.package.{override_name}" ) , features) ?;
499
508
}
500
509
}
501
510
@@ -558,21 +567,6 @@ impl TomlProfile {
558
567
}
559
568
}
560
569
561
- if self . rustflags . is_some ( ) {
562
- features. require ( Feature :: profile_rustflags ( ) ) ?;
563
- }
564
-
565
- if let Some ( codegen_backend) = & self . codegen_backend {
566
- features. require ( Feature :: codegen_backend ( ) ) ?;
567
- if codegen_backend. contains ( |c : char | !c. is_ascii_alphanumeric ( ) && c != '_' ) {
568
- bail ! (
569
- "`profile.{}.codegen-backend` setting of `{}` is not a valid backend name." ,
570
- name,
571
- codegen_backend,
572
- ) ;
573
- }
574
- }
575
-
576
570
Ok ( ( ) )
577
571
}
578
572
@@ -655,7 +649,28 @@ impl TomlProfile {
655
649
Ok ( ( ) )
656
650
}
657
651
658
- fn validate_override ( & self , which : & str , features : & Features ) -> CargoResult < ( ) > {
652
+ /// Validates a profile.
653
+ ///
654
+ /// This is a shallow check, which is reused for the profile itself and any overrides.
655
+ fn validate_profile ( & self , name : & str , features : & Features ) -> CargoResult < ( ) > {
656
+ if let Some ( codegen_backend) = & self . codegen_backend {
657
+ features. require ( Feature :: codegen_backend ( ) ) ?;
658
+ if codegen_backend. contains ( |c : char | !c. is_ascii_alphanumeric ( ) && c != '_' ) {
659
+ bail ! (
660
+ "`profile.{}.codegen-backend` setting of `{}` is not a valid backend name." ,
661
+ name,
662
+ codegen_backend,
663
+ ) ;
664
+ }
665
+ }
666
+ if self . rustflags . is_some ( ) {
667
+ features. require ( Feature :: profile_rustflags ( ) ) ?;
668
+ }
669
+ Ok ( ( ) )
670
+ }
671
+
672
+ /// Validation that is specific to an override.
673
+ fn validate_override ( & self , which : & str ) -> CargoResult < ( ) > {
659
674
if self . package . is_some ( ) {
660
675
bail ! ( "package-specific profiles cannot be nested" ) ;
661
676
}
@@ -671,9 +686,6 @@ impl TomlProfile {
671
686
if self . rpath . is_some ( ) {
672
687
bail ! ( "`rpath` may not be specified in a `{}` profile" , which)
673
688
}
674
- if self . codegen_backend . is_some ( ) {
675
- features. require ( Feature :: codegen_backend ( ) ) ?;
676
- }
677
689
Ok ( ( ) )
678
690
}
679
691
0 commit comments