@@ -295,12 +295,53 @@ fn default_hook(info: &PanicInfo<'_>) {
295295
296296#[ cfg( not( test) ) ]
297297#[ 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" ) ) ]
298339#[ unstable( feature = "update_panic_count" , issue = "none" ) ]
299340pub mod panic_count {
300341 use crate :: cell:: Cell ;
301342 use crate :: sync:: atomic:: { AtomicUsize , Ordering } ;
302343
303- pub const ALWAYS_ABORT_FLAG : usize = 1 << ( usize:: BITS - 1 ) ;
344+ const ALWAYS_ABORT_FLAG : usize = 1 << ( usize:: BITS - 1 ) ;
304345
305346 /// A reason for forcing an immediate abort on panic.
306347 #[ derive( Debug ) ]
@@ -421,6 +462,13 @@ pub mod panic_count {
421462pub use realstd:: rt:: panic_count;
422463
423464/// 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" ) ) ]
424472pub unsafe fn r#try < R , F : FnOnce ( ) -> R > ( f : F ) -> Result < R , Box < dyn Any + Send > > {
425473 union Data < F , R > {
426474 f : ManuallyDrop < F > ,
@@ -755,6 +803,7 @@ fn rust_panic_with_hook(
755803
756804/// This is the entry point for `resume_unwind`.
757805/// It just forwards the payload to the panic runtime.
806+ #[ cfg_attr( feature = "panic_immediate_abort" , inline) ]
758807pub fn rust_panic_without_hook ( payload : Box < dyn Any + Send > ) -> ! {
759808 panic_count:: increase ( false ) ;
760809
@@ -777,7 +826,16 @@ pub fn rust_panic_without_hook(payload: Box<dyn Any + Send>) -> ! {
777826/// yer breakpoints.
778827#[ inline( never) ]
779828#[ cfg_attr( not( test) , rustc_std_internal_symbol) ]
829+ #[ cfg( not( feature = "panic_immediate_abort" ) ) ]
780830fn rust_panic ( msg : & mut dyn PanicPayload ) -> ! {
781831 let code = unsafe { __rust_start_panic ( msg) } ;
782832 rtabort ! ( "failed to initiate panic, error {code}" )
783833}
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