@@ -111,8 +111,8 @@ impl Profiles {
111
111
let mut profile = maker. get_profile ( Some ( pkg_id) , is_member, unit_for) ;
112
112
// `panic` should not be set for tests/benches, or any of their
113
113
// dependencies.
114
- if !unit_for. is_panic_ok ( ) || mode. is_any_test ( ) {
115
- profile. panic = None ;
114
+ if !unit_for. is_panic_abort_ok ( ) || mode. is_any_test ( ) {
115
+ profile. panic = PanicStrategy :: Unwind ;
116
116
}
117
117
118
118
// Incremental can be globally overridden.
@@ -390,8 +390,13 @@ fn merge_profile(profile: &mut Profile, toml: &TomlProfile) {
390
390
if let Some ( rpath) = toml. rpath {
391
391
profile. rpath = rpath;
392
392
}
393
- if let Some ( ref panic) = toml. panic {
394
- profile. panic = Some ( InternedString :: new ( panic) ) ;
393
+ if let Some ( panic) = & toml. panic {
394
+ profile. panic = match panic. as_str ( ) {
395
+ "unwind" => PanicStrategy :: Unwind ,
396
+ "abort" => PanicStrategy :: Abort ,
397
+ // This should be validated in TomlProfile::validate
398
+ _ => panic ! ( "Unexpected panic setting `{}`" , panic) ,
399
+ } ;
395
400
}
396
401
if let Some ( overflow_checks) = toml. overflow_checks {
397
402
profile. overflow_checks = overflow_checks;
@@ -415,7 +420,7 @@ pub struct Profile {
415
420
pub overflow_checks : bool ,
416
421
pub rpath : bool ,
417
422
pub incremental : bool ,
418
- pub panic : Option < InternedString > ,
423
+ pub panic : PanicStrategy ,
419
424
}
420
425
421
426
impl Default for Profile {
@@ -430,7 +435,7 @@ impl Default for Profile {
430
435
overflow_checks : false ,
431
436
rpath : false ,
432
437
incremental : false ,
433
- panic : None ,
438
+ panic : PanicStrategy :: Unwind ,
434
439
}
435
440
}
436
441
}
@@ -530,26 +535,26 @@ impl Profile {
530
535
fn comparable (
531
536
& self ,
532
537
) -> (
533
- & InternedString ,
534
- & Lto ,
535
- & Option < u32 > ,
536
- & Option < u32 > ,
537
- & bool ,
538
- & bool ,
539
- & bool ,
540
- & bool ,
541
- & Option < InternedString > ,
538
+ InternedString ,
539
+ Lto ,
540
+ Option < u32 > ,
541
+ Option < u32 > ,
542
+ bool ,
543
+ bool ,
544
+ bool ,
545
+ bool ,
546
+ PanicStrategy ,
542
547
) {
543
548
(
544
- & self . opt_level ,
545
- & self . lto ,
546
- & self . codegen_units ,
547
- & self . debuginfo ,
548
- & self . debug_assertions ,
549
- & self . overflow_checks ,
550
- & self . rpath ,
551
- & self . incremental ,
552
- & self . panic ,
549
+ self . opt_level ,
550
+ self . lto ,
551
+ self . codegen_units ,
552
+ self . debuginfo ,
553
+ self . debug_assertions ,
554
+ self . overflow_checks ,
555
+ self . rpath ,
556
+ self . incremental ,
557
+ self . panic ,
553
558
)
554
559
}
555
560
}
@@ -564,18 +569,35 @@ pub enum Lto {
564
569
Named ( InternedString ) ,
565
570
}
566
571
572
+ /// The `panic` setting.
573
+ #[ derive( Clone , Copy , PartialEq , Eq , Debug , Hash , PartialOrd , Ord ) ]
574
+ pub enum PanicStrategy {
575
+ Unwind ,
576
+ Abort ,
577
+ }
578
+
579
+ impl fmt:: Display for PanicStrategy {
580
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
581
+ match * self {
582
+ PanicStrategy :: Unwind => "unwind" ,
583
+ PanicStrategy :: Abort => "abort" ,
584
+ }
585
+ . fmt ( f)
586
+ }
587
+ }
588
+
567
589
/// Flags used in creating `Unit`s to indicate the purpose for the target, and
568
590
/// to ensure the target's dependencies have the correct settings.
569
591
#[ derive( Copy , Clone , Debug , Eq , PartialEq , Hash ) ]
570
592
pub struct UnitFor {
571
593
/// A target for `build.rs` or any of its dependencies. This enables
572
594
/// `build-override` profiles for these targets.
573
595
custom_build : bool ,
574
- /// This is true if it is *allowed* to set the `panic` flag. Currently
596
+ /// This is true if it is *allowed* to set the `panic=abort ` flag. Currently
575
597
/// this is false for test/bench targets and all their dependencies, and
576
598
/// "for_host" units such as proc macro and custom build scripts and their
577
599
/// dependencies.
578
- panic_ok : bool ,
600
+ panic_abort_ok : bool ,
579
601
}
580
602
581
603
impl UnitFor {
@@ -584,42 +606,42 @@ impl UnitFor {
584
606
pub fn new_normal ( ) -> UnitFor {
585
607
UnitFor {
586
608
custom_build : false ,
587
- panic_ok : true ,
609
+ panic_abort_ok : true ,
588
610
}
589
611
}
590
612
591
613
/// A unit for a custom build script or its dependencies.
592
614
pub fn new_build ( ) -> UnitFor {
593
615
UnitFor {
594
616
custom_build : true ,
595
- panic_ok : false ,
617
+ panic_abort_ok : false ,
596
618
}
597
619
}
598
620
599
621
/// A unit for a proc macro or compiler plugin or their dependencies.
600
622
pub fn new_compiler ( ) -> UnitFor {
601
623
UnitFor {
602
624
custom_build : false ,
603
- panic_ok : false ,
625
+ panic_abort_ok : false ,
604
626
}
605
627
}
606
628
607
629
/// A unit for a test/bench target or their dependencies.
608
630
pub fn new_test ( ) -> UnitFor {
609
631
UnitFor {
610
632
custom_build : false ,
611
- panic_ok : false ,
633
+ panic_abort_ok : false ,
612
634
}
613
635
}
614
636
615
637
/// Creates a variant based on `for_host` setting.
616
638
///
617
- /// When `for_host` is true, this clears `panic_ok ` in a sticky fashion so
618
- /// that all its dependencies also have `panic_ok =false`.
639
+ /// When `for_host` is true, this clears `panic_abort_ok ` in a sticky fashion so
640
+ /// that all its dependencies also have `panic_abort_ok =false`.
619
641
pub fn with_for_host ( self , for_host : bool ) -> UnitFor {
620
642
UnitFor {
621
643
custom_build : self . custom_build ,
622
- panic_ok : self . panic_ok && !for_host,
644
+ panic_abort_ok : self . panic_abort_ok && !for_host,
623
645
}
624
646
}
625
647
@@ -630,24 +652,24 @@ impl UnitFor {
630
652
}
631
653
632
654
/// Returns `true` if this unit is allowed to set the `panic` compiler flag.
633
- pub fn is_panic_ok ( self ) -> bool {
634
- self . panic_ok
655
+ pub fn is_panic_abort_ok ( self ) -> bool {
656
+ self . panic_abort_ok
635
657
}
636
658
637
659
/// All possible values, used by `clean`.
638
660
pub fn all_values ( ) -> & ' static [ UnitFor ] {
639
661
static ALL : [ UnitFor ; 3 ] = [
640
662
UnitFor {
641
663
custom_build : false ,
642
- panic_ok : true ,
664
+ panic_abort_ok : true ,
643
665
} ,
644
666
UnitFor {
645
667
custom_build : true ,
646
- panic_ok : false ,
668
+ panic_abort_ok : false ,
647
669
} ,
648
670
UnitFor {
649
671
custom_build : false ,
650
- panic_ok : false ,
672
+ panic_abort_ok : false ,
651
673
} ,
652
674
] ;
653
675
& ALL
0 commit comments