@@ -448,10 +448,7 @@ impl ser::Serialize for ProfilePackageSpec {
448
448
where
449
449
S : ser:: Serializer ,
450
450
{
451
- match * self {
452
- ProfilePackageSpec :: Spec ( ref spec) => spec. serialize ( s) ,
453
- ProfilePackageSpec :: All => "*" . serialize ( s) ,
454
- }
451
+ self . to_string ( ) . serialize ( s)
455
452
}
456
453
}
457
454
@@ -471,21 +468,33 @@ impl<'de> de::Deserialize<'de> for ProfilePackageSpec {
471
468
}
472
469
}
473
470
471
+ impl fmt:: Display for ProfilePackageSpec {
472
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
473
+ match self {
474
+ ProfilePackageSpec :: Spec ( spec) => spec. fmt ( f) ,
475
+ ProfilePackageSpec :: All => f. write_str ( "*" ) ,
476
+ }
477
+ }
478
+ }
479
+
474
480
impl TomlProfile {
475
481
pub fn validate (
476
482
& self ,
477
483
name : & str ,
478
484
features : & Features ,
479
485
warnings : & mut Vec < String > ,
480
486
) -> CargoResult < ( ) > {
487
+ self . validate_profile ( name, features) ?;
481
488
if let Some ( ref profile) = self . build_override {
482
489
features. require ( Feature :: profile_overrides ( ) ) ?;
483
- profile. validate_override ( "build-override" , features) ?;
490
+ profile. validate_override ( "build-override" ) ?;
491
+ profile. validate_profile ( & format ! ( "{name}.build-override" ) , features) ?;
484
492
}
485
493
if let Some ( ref packages) = self . package {
486
494
features. require ( Feature :: profile_overrides ( ) ) ?;
487
- for profile in packages. values ( ) {
488
- profile. validate_override ( "package" , features) ?;
495
+ for ( override_name, profile) in packages {
496
+ profile. validate_override ( "package" ) ?;
497
+ profile. validate_profile ( & format ! ( "{name}.package.{override_name}" ) , features) ?;
489
498
}
490
499
}
491
500
@@ -548,21 +557,6 @@ impl TomlProfile {
548
557
}
549
558
}
550
559
551
- if self . rustflags . is_some ( ) {
552
- features. require ( Feature :: profile_rustflags ( ) ) ?;
553
- }
554
-
555
- if let Some ( codegen_backend) = & self . codegen_backend {
556
- features. require ( Feature :: codegen_backend ( ) ) ?;
557
- if codegen_backend. contains ( |c : char | !c. is_ascii_alphanumeric ( ) && c != '_' ) {
558
- bail ! (
559
- "`profile.{}.codegen-backend` setting of `{}` is not a valid backend name." ,
560
- name,
561
- codegen_backend,
562
- ) ;
563
- }
564
- }
565
-
566
560
Ok ( ( ) )
567
561
}
568
562
@@ -645,7 +639,28 @@ impl TomlProfile {
645
639
Ok ( ( ) )
646
640
}
647
641
648
- fn validate_override ( & self , which : & str , features : & Features ) -> CargoResult < ( ) > {
642
+ /// Validates a profile.
643
+ ///
644
+ /// This is a shallow check, which is reused for the profile itself and any overrides.
645
+ fn validate_profile ( & self , name : & str , features : & Features ) -> CargoResult < ( ) > {
646
+ if let Some ( codegen_backend) = & self . codegen_backend {
647
+ features. require ( Feature :: codegen_backend ( ) ) ?;
648
+ if codegen_backend. contains ( |c : char | !c. is_ascii_alphanumeric ( ) && c != '_' ) {
649
+ bail ! (
650
+ "`profile.{}.codegen-backend` setting of `{}` is not a valid backend name." ,
651
+ name,
652
+ codegen_backend,
653
+ ) ;
654
+ }
655
+ }
656
+ if self . rustflags . is_some ( ) {
657
+ features. require ( Feature :: profile_rustflags ( ) ) ?;
658
+ }
659
+ Ok ( ( ) )
660
+ }
661
+
662
+ /// Validation that is specific to an override.
663
+ fn validate_override ( & self , which : & str ) -> CargoResult < ( ) > {
649
664
if self . package . is_some ( ) {
650
665
bail ! ( "package-specific profiles cannot be nested" ) ;
651
666
}
@@ -661,9 +676,6 @@ impl TomlProfile {
661
676
if self . rpath . is_some ( ) {
662
677
bail ! ( "`rpath` may not be specified in a `{}` profile" , which)
663
678
}
664
- if self . codegen_backend . is_some ( ) {
665
- features. require ( Feature :: codegen_backend ( ) ) ?;
666
- }
667
679
Ok ( ( ) )
668
680
}
669
681
0 commit comments