@@ -33,7 +33,10 @@ use crate::intrinsics::const_eval_select;
33
33
use crate :: panic:: { Location , PanicInfo } ;
34
34
35
35
#[ 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
+ ) ;
37
40
38
41
// First we define the two main entry points that all panics go through.
39
42
// 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
44
47
/// site as much as possible (so that `panic!()` has as low an impact
45
48
/// on (e.g.) the inlining of other functions as possible), by moving
46
49
/// 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,
48
51
// 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) ]
51
54
#[ track_caller]
52
55
#[ lang = "panic_fmt" ] // needed for const-evaluated panics
53
56
#[ rustc_do_not_const_check] // hooked by const-eval
54
57
#[ rustc_const_stable_indirect] // must follow stable const rules since it is exposed to stable
55
58
pub const fn panic_fmt ( fmt : fmt:: Arguments < ' _ > ) -> ! {
56
- if cfg ! ( feature = "panic_immediate_abort " ) {
59
+ if cfg ! ( panic = "immediate-abort " ) {
57
60
super :: intrinsics:: abort ( )
58
61
}
59
62
@@ -78,8 +81,8 @@ pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
78
81
/// Like `panic_fmt`, but for non-unwinding panics.
79
82
///
80
83
/// 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) ]
83
86
#[ track_caller]
84
87
// This attribute has the key side-effect that if the panic handler ignores `can_unwind`
85
88
// 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
94
97
// We don't unwind anyway at compile-time so we can call the regular `panic_fmt`.
95
98
panic_fmt( fmt)
96
99
} else #[ track_caller] {
97
- if cfg!( feature = "panic_immediate_abort " ) {
100
+ if cfg!( panic = "immediate-abort " ) {
98
101
super :: intrinsics:: abort( )
99
102
}
100
103
@@ -123,10 +126,10 @@ pub const fn panic_nounwind_fmt(fmt: fmt::Arguments<'_>, force_no_backtrace: boo
123
126
// above.
124
127
125
128
/// 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
127
130
// 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) ]
130
133
#[ track_caller]
131
134
#[ rustc_const_stable_indirect] // must follow stable const rules since it is exposed to stable
132
135
#[ lang = "panic" ] // used by lints and miri for panics
@@ -158,10 +161,10 @@ macro_rules! panic_const {
158
161
$(
159
162
/// This is a panic called with a message that's a result of a MIR-produced Assert.
160
163
//
161
- // never inline unless panic_immediate_abort to avoid code
164
+ // never inline unless panic=immediate-abort to avoid code
162
165
// 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) ]
165
168
#[ track_caller]
166
169
#[ rustc_const_stable_indirect] // must follow stable const rules since it is exposed to stable
167
170
#[ lang = stringify!( $lang) ]
@@ -216,8 +219,8 @@ pub mod panic_const {
216
219
217
220
/// Like `panic`, but without unwinding and track_caller to reduce the impact on codesize on the caller.
218
221
/// 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) ]
221
224
#[ lang = "panic_nounwind" ] // needed by codegen for non-unwinding panics
222
225
#[ rustc_nounwind]
223
226
#[ 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) -> ! {
226
229
}
227
230
228
231
/// 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) ]
231
234
#[ rustc_nounwind]
232
235
pub fn panic_nounwind_nobacktrace ( expr : & ' static str ) -> ! {
233
236
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) -> ! {
259
262
panic_fmt ( format_args ! ( "{}" , * x) ) ;
260
263
}
261
264
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) ]
264
267
#[ track_caller]
265
268
#[ lang = "panic_bounds_check" ] // needed by codegen for panic on OOB array/slice access
266
269
fn panic_bounds_check ( index : usize , len : usize ) -> ! {
267
- if cfg ! ( feature = "panic_immediate_abort " ) {
270
+ if cfg ! ( panic = "immediate-abort " ) {
268
271
super :: intrinsics:: abort ( )
269
272
}
270
273
271
274
panic ! ( "index out of bounds: the len is {len} but the index is {index}" )
272
275
}
273
276
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) ]
276
279
#[ track_caller]
277
280
#[ lang = "panic_misaligned_pointer_dereference" ] // needed by codegen for panic on misaligned pointer deref
278
281
#[ rustc_nounwind] // `CheckAlignment` MIR pass requires this function to never unwind
279
282
fn panic_misaligned_pointer_dereference ( required : usize , found : usize ) -> ! {
280
- if cfg ! ( feature = "panic_immediate_abort " ) {
283
+ if cfg ! ( panic = "immediate-abort " ) {
281
284
super :: intrinsics:: abort ( )
282
285
}
283
286
@@ -289,13 +292,13 @@ fn panic_misaligned_pointer_dereference(required: usize, found: usize) -> ! {
289
292
)
290
293
}
291
294
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) ]
294
297
#[ track_caller]
295
298
#[ lang = "panic_null_pointer_dereference" ] // needed by codegen for panic on null pointer deref
296
299
#[ rustc_nounwind] // `CheckNull` MIR pass requires this function to never unwind
297
300
fn panic_null_pointer_dereference ( ) -> ! {
298
- if cfg ! ( feature = "panic_immediate_abort " ) {
301
+ if cfg ! ( panic = "immediate-abort " ) {
299
302
super :: intrinsics:: abort ( )
300
303
}
301
304
@@ -305,13 +308,13 @@ fn panic_null_pointer_dereference() -> ! {
305
308
)
306
309
}
307
310
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) ]
310
313
#[ track_caller]
311
314
#[ lang = "panic_invalid_enum_construction" ] // needed by codegen for panic on invalid enum construction.
312
315
#[ rustc_nounwind] // `CheckEnums` MIR pass requires this function to never unwind
313
316
fn panic_invalid_enum_construction ( source : u128 ) -> ! {
314
- if cfg ! ( feature = "panic_immediate_abort " ) {
317
+ if cfg ! ( panic = "immediate-abort " ) {
315
318
super :: intrinsics:: abort ( )
316
319
}
317
320
@@ -328,8 +331,8 @@ fn panic_invalid_enum_construction(source: u128) -> ! {
328
331
///
329
332
/// This function is called directly by the codegen backend, and must not have
330
333
/// 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) ]
333
336
#[ lang = "panic_cannot_unwind" ] // needed by codegen for panic in nounwind function
334
337
#[ rustc_nounwind]
335
338
fn panic_cannot_unwind ( ) -> ! {
@@ -344,8 +347,8 @@ fn panic_cannot_unwind() -> ! {
344
347
///
345
348
/// This function is called directly by the codegen backend, and must not have
346
349
/// 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) ]
349
352
#[ lang = "panic_in_cleanup" ] // needed by codegen for panic in nounwind function
350
353
#[ rustc_nounwind]
351
354
fn panic_in_cleanup ( ) -> ! {
@@ -377,8 +380,8 @@ pub enum AssertKind {
377
380
}
378
381
379
382
/// 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) ]
382
385
#[ track_caller]
383
386
#[ doc( hidden) ]
384
387
pub fn assert_failed < T , U > (
@@ -395,8 +398,8 @@ where
395
398
}
396
399
397
400
/// 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) ]
400
403
#[ track_caller]
401
404
#[ doc( hidden) ]
402
405
pub fn assert_matches_failed < T : fmt:: Debug + ?Sized > (
@@ -415,8 +418,8 @@ pub fn assert_matches_failed<T: fmt::Debug + ?Sized>(
415
418
}
416
419
417
420
/// 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) ]
420
423
#[ track_caller]
421
424
fn assert_failed_inner (
422
425
kind : AssertKind ,
0 commit comments