@@ -47,6 +47,7 @@ pub macro panic_2015 {
47
47
#[ allow_internal_unstable( core_panic, const_format_args) ]
48
48
#[ rustc_diagnostic_item = "core_panic_2021_macro" ]
49
49
#[ rustc_macro_transparency = "semitransparent" ]
50
+ #[ cfg( any( bootstrap, feature = "panic_immediate_abort" ) ) ]
50
51
pub macro panic_2021 {
51
52
( ) => (
52
53
$crate:: panicking:: panic ( "explicit panic" )
@@ -62,6 +63,50 @@ pub macro panic_2021 {
62
63
} ) ,
63
64
}
64
65
66
+ #[ doc ( hidden) ]
67
+ #[ unstable( feature = "edition_panic" , issue = "none" , reason = "use panic!() instead" ) ]
68
+ #[ allow_internal_unstable(
69
+ core_panic,
70
+ core_intrinsics,
71
+ const_dispatch,
72
+ const_eval_select,
73
+ const_format_args,
74
+ rustc_attrs
75
+ ) ]
76
+ #[ rustc_diagnostic_item = "core_panic_2021_macro" ]
77
+ #[ rustc_macro_transparency = "semitransparent" ]
78
+ #[ cfg( not( any( bootstrap, feature = "panic_immediate_abort" ) ) ) ]
79
+ pub macro panic_2021 {
80
+ ( ) => ( {
81
+ // Create a function so that the argument for `track_caller`
82
+ // can be moved inside if possible.
83
+ #[ cold]
84
+ #[ track_caller]
85
+ #[ inline( never) ]
86
+ const fn panic_cold_explicit ( ) -> ! {
87
+ $crate:: panicking:: panic_explicit ( )
88
+ }
89
+ panic_cold_explicit ( ) ;
90
+ } ) ,
91
+ // Special-case the single-argument case for const_panic.
92
+ ( "{}" , $arg: expr $( , ) ?) => ( {
93
+ #[ cold]
94
+ #[ track_caller]
95
+ #[ inline( never) ]
96
+ #[ rustc_const_panic_str] // enforce a &&str argument in const-check and hook this by const-eval
97
+ #[ rustc_do_not_const_check] // hooked by const-eval
98
+ const fn panic_cold_display < T : $crate:: fmt:: Display > ( arg : & T ) -> ! {
99
+ $crate:: panicking:: panic_display ( arg)
100
+ }
101
+ panic_cold_display ( & $arg) ;
102
+ } ) ,
103
+ ( $( $t: tt) +) => ( {
104
+ // Semicolon to prevent temporaries inside the formatting machinery from
105
+ // being considered alive in the caller after the panic_fmt call.
106
+ $crate:: panicking:: panic_fmt ( $crate:: const_format_args!( $( $t) +) ) ;
107
+ } ) ,
108
+ }
109
+
65
110
#[ doc ( hidden) ]
66
111
#[ unstable( feature = "edition_panic" , issue = "none" , reason = "use unreachable!() instead" ) ]
67
112
#[ allow_internal_unstable( core_panic) ]
0 commit comments