@@ -437,9 +437,31 @@ pub fn panicking() -> bool {
437
437
!panic_count:: count_is_zero ( )
438
438
}
439
439
440
+ /// The entry point for panicking with a formatted message.
441
+ ///
442
+ /// This is designed to reduce the amount of code required at the call
443
+ /// site as much as possible (so that `panic!()` has as low an impact
444
+ /// on (e.g.) the inlining of other functions as possible), by moving
445
+ /// the actual formatting into this shared place.
446
+ #[ unstable( feature = "libstd_sys_internals" , reason = "used by the panic! macro" , issue = "none" ) ]
447
+ #[ cold]
448
+ // If panic_immediate_abort, inline the abort call,
449
+ // otherwise avoid inlining because of it is cold path.
450
+ #[ cfg_attr( not( feature = "panic_immediate_abort" ) , track_caller) ]
451
+ #[ cfg_attr( not( feature = "panic_immediate_abort" ) , inline( never) ) ]
452
+ #[ cfg_attr( feature = "panic_immediate_abort" , inline) ]
453
+ #[ cfg_attr( not( test) , lang = "begin_panic_fmt" ) ]
454
+ pub fn begin_panic_fmt ( msg : & fmt:: Arguments < ' _ > ) -> ! {
455
+ if cfg ! ( feature = "panic_immediate_abort" ) {
456
+ intrinsics:: abort ( )
457
+ }
458
+
459
+ let info = PanicInfo :: internal_constructor ( Some ( msg) , Location :: caller ( ) ) ;
460
+ begin_panic_handler ( & info)
461
+ }
462
+
440
463
/// Entry point of panics from the libcore crate (`panic_impl` lang item).
441
- #[ cfg( not( test) ) ]
442
- #[ panic_handler]
464
+ #[ cfg_attr( not( test) , panic_handler) ]
443
465
pub fn begin_panic_handler ( info : & PanicInfo < ' _ > ) -> ! {
444
466
struct PanicPayload < ' a > {
445
467
inner : & ' a fmt:: Arguments < ' a > ,
0 commit comments