@@ -295,12 +295,53 @@ fn default_hook(info: &PanicInfo<'_>) {
295
295
296
296
#[ cfg( not( test) ) ]
297
297
#[ doc( hidden) ]
298
+ #[ cfg( feature = "panic_immediate_abort" ) ]
299
+ #[ unstable( feature = "update_panic_count" , issue = "none" ) ]
300
+ pub mod panic_count {
301
+ /// A reason for forcing an immediate abort on panic.
302
+ #[ derive( Debug ) ]
303
+ pub enum MustAbort {
304
+ AlwaysAbort ,
305
+ PanicInHook ,
306
+ }
307
+
308
+ #[ inline]
309
+ pub fn increase ( run_panic_hook : bool ) -> Option < MustAbort > {
310
+ None
311
+ }
312
+
313
+ #[ inline]
314
+ pub fn finished_panic_hook ( ) { }
315
+
316
+ #[ inline]
317
+ pub fn decrease ( ) { }
318
+
319
+ #[ inline]
320
+ pub fn set_always_abort ( ) { }
321
+
322
+ // Disregards ALWAYS_ABORT_FLAG
323
+ #[ inline]
324
+ #[ must_use]
325
+ pub fn get_count ( ) -> usize {
326
+ 0
327
+ }
328
+
329
+ #[ must_use]
330
+ #[ inline]
331
+ pub fn count_is_zero ( ) -> bool {
332
+ true
333
+ }
334
+ }
335
+
336
+ #[ cfg( not( test) ) ]
337
+ #[ doc( hidden) ]
338
+ #[ cfg( not( feature = "panic_immediate_abort" ) ) ]
298
339
#[ unstable( feature = "update_panic_count" , issue = "none" ) ]
299
340
pub mod panic_count {
300
341
use crate :: cell:: Cell ;
301
342
use crate :: sync:: atomic:: { AtomicUsize , Ordering } ;
302
343
303
- pub const ALWAYS_ABORT_FLAG : usize = 1 << ( usize:: BITS - 1 ) ;
344
+ const ALWAYS_ABORT_FLAG : usize = 1 << ( usize:: BITS - 1 ) ;
304
345
305
346
/// A reason for forcing an immediate abort on panic.
306
347
#[ derive( Debug ) ]
@@ -421,6 +462,13 @@ pub mod panic_count {
421
462
pub use realstd:: rt:: panic_count;
422
463
423
464
/// Invoke a closure, capturing the cause of an unwinding panic if one occurs.
465
+ #[ cfg( feature = "panic_immediate_abort" ) ]
466
+ pub unsafe fn r#try < R , F : FnOnce ( ) -> R > ( f : F ) -> Result < R , Box < dyn Any + Send > > {
467
+ Ok ( f ( ) )
468
+ }
469
+
470
+ /// Invoke a closure, capturing the cause of an unwinding panic if one occurs.
471
+ #[ cfg( not( feature = "panic_immediate_abort" ) ) ]
424
472
pub unsafe fn r#try < R , F : FnOnce ( ) -> R > ( f : F ) -> Result < R , Box < dyn Any + Send > > {
425
473
union Data < F , R > {
426
474
f : ManuallyDrop < F > ,
@@ -755,6 +803,7 @@ fn rust_panic_with_hook(
755
803
756
804
/// This is the entry point for `resume_unwind`.
757
805
/// It just forwards the payload to the panic runtime.
806
+ #[ cfg_attr( feature = "panic_immediate_abort" , inline) ]
758
807
pub fn rust_panic_without_hook ( payload : Box < dyn Any + Send > ) -> ! {
759
808
panic_count:: increase ( false ) ;
760
809
@@ -777,7 +826,16 @@ pub fn rust_panic_without_hook(payload: Box<dyn Any + Send>) -> ! {
777
826
/// yer breakpoints.
778
827
#[ inline( never) ]
779
828
#[ cfg_attr( not( test) , rustc_std_internal_symbol) ]
829
+ #[ cfg( not( feature = "panic_immediate_abort" ) ) ]
780
830
fn rust_panic ( msg : & mut dyn PanicPayload ) -> ! {
781
831
let code = unsafe { __rust_start_panic ( msg) } ;
782
832
rtabort ! ( "failed to initiate panic, error {code}" )
783
833
}
834
+
835
+ #[ cfg_attr( not( test) , rustc_std_internal_symbol) ]
836
+ #[ cfg( feature = "panic_immediate_abort" ) ]
837
+ fn rust_panic ( _: & mut dyn PanicPayload ) -> ! {
838
+ unsafe {
839
+ crate :: intrinsics:: abort ( ) ;
840
+ }
841
+ }
0 commit comments