@@ -51,7 +51,22 @@ const _: () = assert!(cfg!(panic = "abort"), "panic_immediate_abort requires -C
5151#[ rustc_do_not_const_check] // hooked by const-eval
5252#[ rustc_const_unstable( feature = "core_panic" , issue = "none" ) ]
5353pub const fn panic_fmt ( fmt : fmt:: Arguments < ' _ > ) -> ! {
54- panic_source ( fmt, None )
54+ //panic_source(fmt, None)
55+ if cfg ! ( feature = "panic_immediate_abort" ) {
56+ super :: intrinsics:: abort ( )
57+ }
58+
59+ // NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call
60+ // that gets resolved to the `#[panic_handler]` function.
61+ extern "Rust" {
62+ #[ lang = "panic_impl" ]
63+ fn panic_impl ( pi : & PanicInfo < ' _ > ) -> !;
64+ }
65+
66+ let pi = PanicInfo :: internal_constructor ( Some ( & fmt) , Location :: caller ( ) , None , true ) ;
67+
68+ // SAFETY: `panic_impl` is defined in safe Rust code and thus is safe to call.
69+ unsafe { panic_impl ( & pi) }
5570}
5671
5772#[ cold]
@@ -62,7 +77,7 @@ pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
6277#[ track_caller]
6378#[ rustc_do_not_const_check] // hooked by const-eval
6479#[ rustc_const_unstable( feature = "core_panic" , issue = "none" ) ]
65- pub const fn panic_source ( fmt : fmt:: Arguments < ' _ > , source : Option < & ( dyn Error + ' static ) > ) -> ! {
80+ pub const fn panic_source ( fmt : fmt:: Arguments < ' _ > , source : & ( dyn Error + ' static ) ) -> ! {
6681 if cfg ! ( feature = "panic_immediate_abort" ) {
6782 super :: intrinsics:: abort ( )
6883 }
@@ -74,7 +89,7 @@ pub const fn panic_source(fmt: fmt::Arguments<'_>, source: Option<&(dyn Error +
7489 fn panic_impl ( pi : & PanicInfo < ' _ > ) -> !;
7590 }
7691
77- let pi = PanicInfo :: internal_constructor ( Some ( & fmt) , Location :: caller ( ) , source, true ) ;
92+ let pi = PanicInfo :: internal_constructor ( Some ( & fmt) , Location :: caller ( ) , Some ( source) , true ) ;
7893
7994 // SAFETY: `panic_impl` is defined in safe Rust code and thus is safe to call.
8095 unsafe { panic_impl ( & pi) }
0 commit comments