@@ -33,7 +33,10 @@ use crate::intrinsics::const_eval_select;
3333use crate :: panic:: { Location , PanicInfo } ;
3434
3535#[ cfg( feature = "panic_immediate_abort" ) ]
36- const _: ( ) = assert ! ( cfg!( panic = "abort" ) , "panic_immediate_abort requires -C panic=abort" ) ;
36+ compile_error ! (
37+ "panic_immediate_abort is now a real panic strategy! \
38+ Enable it with the compiler flags `-Zunstable-options -Cpanic=immediate-abort`"
39+ ) ;
3740
3841// First we define the two main entry points that all panics go through.
3942// In the end both are just convenience wrappers around `panic_impl`.
@@ -44,16 +47,16 @@ const _: () = assert!(cfg!(panic = "abort"), "panic_immediate_abort requires -C
4447/// site as much as possible (so that `panic!()` has as low an impact
4548/// on (e.g.) the inlining of other functions as possible), by moving
4649/// the actual formatting into this shared place.
47- // If panic_immediate_abort , inline the abort call,
50+ // If panic=immediate-abort , inline the abort call,
4851// otherwise avoid inlining because of it is cold path.
49- #[ cfg_attr( not( feature = "panic_immediate_abort " ) , inline( never) , cold) ]
50- #[ cfg_attr( feature = "panic_immediate_abort " , inline) ]
52+ #[ cfg_attr( not( panic = "immediate-abort " ) , inline( never) , cold) ]
53+ #[ cfg_attr( panic = "immediate-abort " , inline) ]
5154#[ track_caller]
5255#[ lang = "panic_fmt" ] // needed for const-evaluated panics
5356#[ rustc_do_not_const_check] // hooked by const-eval
5457#[ rustc_const_stable_indirect] // must follow stable const rules since it is exposed to stable
5558pub const fn panic_fmt ( fmt : fmt:: Arguments < ' _ > ) -> ! {
56- if cfg ! ( feature = "panic_immediate_abort " ) {
59+ if cfg ! ( panic = "immediate-abort " ) {
5760 super :: intrinsics:: abort ( )
5861 }
5962
@@ -78,8 +81,8 @@ pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
7881/// Like `panic_fmt`, but for non-unwinding panics.
7982///
8083/// Has to be a separate function so that it can carry the `rustc_nounwind` attribute.
81- #[ cfg_attr( not( feature = "panic_immediate_abort " ) , inline( never) , cold) ]
82- #[ cfg_attr( feature = "panic_immediate_abort " , inline) ]
84+ #[ cfg_attr( not( panic = "immediate-abort " ) , inline( never) , cold) ]
85+ #[ cfg_attr( panic = "immediate-abort " , inline) ]
8386#[ track_caller]
8487// This attribute has the key side-effect that if the panic handler ignores `can_unwind`
8588// and unwinds anyway, we will hit the "unwinding out of nounwind function" guard,
@@ -94,7 +97,7 @@ pub const fn panic_nounwind_fmt(fmt: fmt::Arguments<'_>, force_no_backtrace: boo
9497 // We don't unwind anyway at compile-time so we can call the regular `panic_fmt`.
9598 panic_fmt( fmt)
9699 } else #[ track_caller] {
97- if cfg!( feature = "panic_immediate_abort " ) {
100+ if cfg!( panic = "immediate-abort " ) {
98101 super :: intrinsics:: abort( )
99102 }
100103
@@ -123,10 +126,10 @@ pub const fn panic_nounwind_fmt(fmt: fmt::Arguments<'_>, force_no_backtrace: boo
123126// above.
124127
125128/// The underlying implementation of core's `panic!` macro when no formatting is used.
126- // Never inline unless panic_immediate_abort to avoid code
129+ // Never inline unless panic=immediate-abort to avoid code
127130// bloat at the call sites as much as possible.
128- #[ cfg_attr( not( feature = "panic_immediate_abort " ) , inline( never) , cold) ]
129- #[ cfg_attr( feature = "panic_immediate_abort " , inline) ]
131+ #[ cfg_attr( not( panic = "immediate-abort " ) , inline( never) , cold) ]
132+ #[ cfg_attr( panic = "immediate-abort " , inline) ]
130133#[ track_caller]
131134#[ rustc_const_stable_indirect] // must follow stable const rules since it is exposed to stable
132135#[ lang = "panic" ] // used by lints and miri for panics
@@ -158,10 +161,10 @@ macro_rules! panic_const {
158161 $(
159162 /// This is a panic called with a message that's a result of a MIR-produced Assert.
160163 //
161- // never inline unless panic_immediate_abort to avoid code
164+ // never inline unless panic=immediate-abort to avoid code
162165 // bloat at the call sites as much as possible
163- #[ cfg_attr( not( feature = "panic_immediate_abort " ) , inline( never) , cold) ]
164- #[ cfg_attr( feature = "panic_immediate_abort " , inline) ]
166+ #[ cfg_attr( not( panic = "immediate-abort " ) , inline( never) , cold) ]
167+ #[ cfg_attr( panic = "immediate-abort " , inline) ]
165168 #[ track_caller]
166169 #[ rustc_const_stable_indirect] // must follow stable const rules since it is exposed to stable
167170 #[ lang = stringify!( $lang) ]
@@ -216,8 +219,8 @@ pub mod panic_const {
216219
217220/// Like `panic`, but without unwinding and track_caller to reduce the impact on codesize on the caller.
218221/// If you want `#[track_caller]` for nicer errors, call `panic_nounwind_fmt` directly.
219- #[ cfg_attr( not( feature = "panic_immediate_abort " ) , inline( never) , cold) ]
220- #[ cfg_attr( feature = "panic_immediate_abort " , inline) ]
222+ #[ cfg_attr( not( panic = "immediate-abort " ) , inline( never) , cold) ]
223+ #[ cfg_attr( panic = "immediate-abort " , inline) ]
221224#[ lang = "panic_nounwind" ] // needed by codegen for non-unwinding panics
222225#[ rustc_nounwind]
223226#[ rustc_const_stable_indirect] // must follow stable const rules since it is exposed to stable
@@ -226,8 +229,8 @@ pub const fn panic_nounwind(expr: &'static str) -> ! {
226229}
227230
228231/// Like `panic_nounwind`, but also inhibits showing a backtrace.
229- #[ cfg_attr( not( feature = "panic_immediate_abort " ) , inline( never) , cold) ]
230- #[ cfg_attr( feature = "panic_immediate_abort " , inline) ]
232+ #[ cfg_attr( not( panic = "immediate-abort " ) , inline( never) , cold) ]
233+ #[ cfg_attr( panic = "immediate-abort " , inline) ]
231234#[ rustc_nounwind]
232235pub fn panic_nounwind_nobacktrace ( expr : & ' static str ) -> ! {
233236 panic_nounwind_fmt ( fmt:: Arguments :: new_const ( & [ expr] ) , /* force_no_backtrace */ true ) ;
@@ -259,25 +262,25 @@ pub const fn panic_display<T: fmt::Display>(x: &T) -> ! {
259262 panic_fmt ( format_args ! ( "{}" , * x) ) ;
260263}
261264
262- #[ cfg_attr( not( feature = "panic_immediate_abort " ) , inline( never) , cold, optimize( size) ) ]
263- #[ cfg_attr( feature = "panic_immediate_abort " , inline) ]
265+ #[ cfg_attr( not( panic = "immediate-abort " ) , inline( never) , cold, optimize( size) ) ]
266+ #[ cfg_attr( panic = "immediate-abort " , inline) ]
264267#[ track_caller]
265268#[ lang = "panic_bounds_check" ] // needed by codegen for panic on OOB array/slice access
266269fn panic_bounds_check ( index : usize , len : usize ) -> ! {
267- if cfg ! ( feature = "panic_immediate_abort " ) {
270+ if cfg ! ( panic = "immediate-abort " ) {
268271 super :: intrinsics:: abort ( )
269272 }
270273
271274 panic ! ( "index out of bounds: the len is {len} but the index is {index}" )
272275}
273276
274- #[ cfg_attr( not( feature = "panic_immediate_abort " ) , inline( never) , cold, optimize( size) ) ]
275- #[ cfg_attr( feature = "panic_immediate_abort " , inline) ]
277+ #[ cfg_attr( not( panic = "immediate-abort " ) , inline( never) , cold, optimize( size) ) ]
278+ #[ cfg_attr( panic = "immediate-abort " , inline) ]
276279#[ track_caller]
277280#[ lang = "panic_misaligned_pointer_dereference" ] // needed by codegen for panic on misaligned pointer deref
278281#[ rustc_nounwind] // `CheckAlignment` MIR pass requires this function to never unwind
279282fn panic_misaligned_pointer_dereference ( required : usize , found : usize ) -> ! {
280- if cfg ! ( feature = "panic_immediate_abort " ) {
283+ if cfg ! ( panic = "immediate-abort " ) {
281284 super :: intrinsics:: abort ( )
282285 }
283286
@@ -289,13 +292,13 @@ fn panic_misaligned_pointer_dereference(required: usize, found: usize) -> ! {
289292 )
290293}
291294
292- #[ cfg_attr( not( feature = "panic_immediate_abort " ) , inline( never) , cold, optimize( size) ) ]
293- #[ cfg_attr( feature = "panic_immediate_abort " , inline) ]
295+ #[ cfg_attr( not( panic = "immediate-abort " ) , inline( never) , cold, optimize( size) ) ]
296+ #[ cfg_attr( panic = "immediate-abort " , inline) ]
294297#[ track_caller]
295298#[ lang = "panic_null_pointer_dereference" ] // needed by codegen for panic on null pointer deref
296299#[ rustc_nounwind] // `CheckNull` MIR pass requires this function to never unwind
297300fn panic_null_pointer_dereference ( ) -> ! {
298- if cfg ! ( feature = "panic_immediate_abort " ) {
301+ if cfg ! ( panic = "immediate-abort " ) {
299302 super :: intrinsics:: abort ( )
300303 }
301304
@@ -305,13 +308,13 @@ fn panic_null_pointer_dereference() -> ! {
305308 )
306309}
307310
308- #[ cfg_attr( not( feature = "panic_immediate_abort " ) , inline( never) , cold, optimize( size) ) ]
309- #[ cfg_attr( feature = "panic_immediate_abort " , inline) ]
311+ #[ cfg_attr( not( panic = "immediate-abort " ) , inline( never) , cold, optimize( size) ) ]
312+ #[ cfg_attr( panic = "immediate-abort " , inline) ]
310313#[ track_caller]
311314#[ lang = "panic_invalid_enum_construction" ] // needed by codegen for panic on invalid enum construction.
312315#[ rustc_nounwind] // `CheckEnums` MIR pass requires this function to never unwind
313316fn panic_invalid_enum_construction ( source : u128 ) -> ! {
314- if cfg ! ( feature = "panic_immediate_abort " ) {
317+ if cfg ! ( panic = "immediate-abort " ) {
315318 super :: intrinsics:: abort ( )
316319 }
317320
@@ -328,8 +331,8 @@ fn panic_invalid_enum_construction(source: u128) -> ! {
328331///
329332/// This function is called directly by the codegen backend, and must not have
330333/// any extra arguments (including those synthesized by track_caller).
331- #[ cfg_attr( not( feature = "panic_immediate_abort " ) , inline( never) , cold, optimize( size) ) ]
332- #[ cfg_attr( feature = "panic_immediate_abort " , inline) ]
334+ #[ cfg_attr( not( panic = "immediate-abort " ) , inline( never) , cold, optimize( size) ) ]
335+ #[ cfg_attr( panic = "immediate-abort " , inline) ]
333336#[ lang = "panic_cannot_unwind" ] // needed by codegen for panic in nounwind function
334337#[ rustc_nounwind]
335338fn panic_cannot_unwind ( ) -> ! {
@@ -344,8 +347,8 @@ fn panic_cannot_unwind() -> ! {
344347///
345348/// This function is called directly by the codegen backend, and must not have
346349/// any extra arguments (including those synthesized by track_caller).
347- #[ cfg_attr( not( feature = "panic_immediate_abort " ) , inline( never) , cold, optimize( size) ) ]
348- #[ cfg_attr( feature = "panic_immediate_abort " , inline) ]
350+ #[ cfg_attr( not( panic = "immediate-abort " ) , inline( never) , cold, optimize( size) ) ]
351+ #[ cfg_attr( panic = "immediate-abort " , inline) ]
349352#[ lang = "panic_in_cleanup" ] // needed by codegen for panic in nounwind function
350353#[ rustc_nounwind]
351354fn panic_in_cleanup ( ) -> ! {
@@ -377,8 +380,8 @@ pub enum AssertKind {
377380}
378381
379382/// Internal function for `assert_eq!` and `assert_ne!` macros
380- #[ cfg_attr( not( feature = "panic_immediate_abort " ) , inline( never) , cold, optimize( size) ) ]
381- #[ cfg_attr( feature = "panic_immediate_abort " , inline) ]
383+ #[ cfg_attr( not( panic = "immediate-abort " ) , inline( never) , cold, optimize( size) ) ]
384+ #[ cfg_attr( panic = "immediate-abort " , inline) ]
382385#[ track_caller]
383386#[ doc( hidden) ]
384387pub fn assert_failed < T , U > (
@@ -395,8 +398,8 @@ where
395398}
396399
397400/// Internal function for `assert_match!`
398- #[ cfg_attr( not( feature = "panic_immediate_abort " ) , inline( never) , cold, optimize( size) ) ]
399- #[ cfg_attr( feature = "panic_immediate_abort " , inline) ]
401+ #[ cfg_attr( not( panic = "immediate-abort " ) , inline( never) , cold, optimize( size) ) ]
402+ #[ cfg_attr( panic = "immediate-abort " , inline) ]
400403#[ track_caller]
401404#[ doc( hidden) ]
402405pub fn assert_matches_failed < T : fmt:: Debug + ?Sized > (
@@ -415,8 +418,8 @@ pub fn assert_matches_failed<T: fmt::Debug + ?Sized>(
415418}
416419
417420/// Non-generic version of the above functions, to avoid code bloat.
418- #[ cfg_attr( not( feature = "panic_immediate_abort " ) , inline( never) , cold, optimize( size) ) ]
419- #[ cfg_attr( feature = "panic_immediate_abort " , inline) ]
421+ #[ cfg_attr( not( panic = "immediate-abort " ) , inline( never) , cold, optimize( size) ) ]
422+ #[ cfg_attr( panic = "immediate-abort " , inline) ]
420423#[ track_caller]
421424fn assert_failed_inner (
422425 kind : AssertKind ,
0 commit comments