@@ -13,6 +13,7 @@ use crate::panic::BacktraceStyle;
1313use core:: panic:: { BoxMeUp , Location , PanicInfo } ;
1414
1515use crate :: any:: Any ;
16+ use crate :: error:: Error ;
1617use crate :: fmt;
1718use crate :: intrinsics;
1819use crate :: mem:: { self , ManuallyDrop } ;
@@ -258,7 +259,9 @@ fn default_hook(info: &PanicInfo<'_>) {
258259
259260 let write = |err : & mut dyn crate :: io:: Write | {
260261 let _ = writeln ! ( err, "thread '{name}' panicked at '{msg}', {location}" ) ;
261-
262+ if info. source ( ) . is_some ( ) {
263+ writeln ! ( err, "fun is not allowed" ) ;
264+ }
262265 static FIRST_PANIC : AtomicBool = AtomicBool :: new ( true ) ;
263266
264267 match backtrace {
@@ -574,15 +577,17 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
574577 }
575578
576579 let loc = info. location ( ) . unwrap ( ) ; // The current implementation always returns Some
580+ let source = info. source ( ) ;
577581 let msg = info. message ( ) . unwrap ( ) ; // The current implementation always returns Some
578582 crate :: sys_common:: backtrace:: __rust_end_short_backtrace ( move || {
579583 if let Some ( msg) = msg. as_str ( ) {
580- rust_panic_with_hook ( & mut StrPanicPayload ( msg) , info. message ( ) , loc, info. can_unwind ( ) ) ;
584+ rust_panic_with_hook ( & mut StrPanicPayload ( msg) , info. message ( ) , loc, source , info. can_unwind ( ) ) ;
581585 } else {
582586 rust_panic_with_hook (
583587 & mut PanicPayload :: new ( msg) ,
584588 info. message ( ) ,
585589 loc,
590+ source,
586591 info. can_unwind ( ) ,
587592 ) ;
588593 }
@@ -608,7 +613,7 @@ pub const fn begin_panic<M: Any + Send>(msg: M) -> ! {
608613
609614 let loc = Location :: caller ( ) ;
610615 return crate :: sys_common:: backtrace:: __rust_end_short_backtrace ( move || {
611- rust_panic_with_hook ( & mut PanicPayload :: new ( msg) , None , loc, true )
616+ rust_panic_with_hook ( & mut PanicPayload :: new ( msg) , None , loc, None , true )
612617 } ) ;
613618
614619 struct PanicPayload < A > {
@@ -653,6 +658,7 @@ fn rust_panic_with_hook(
653658 payload : & mut dyn BoxMeUp ,
654659 message : Option < & fmt:: Arguments < ' _ > > ,
655660 location : & Location < ' _ > ,
661+ source : Option < & ( dyn Error + ' static ) > ,
656662 can_unwind : bool ,
657663) -> ! {
658664 let ( must_abort, panics) = panic_count:: increase ( ) ;
@@ -670,13 +676,13 @@ fn rust_panic_with_hook(
670676 } else {
671677 // Unfortunately, this does not print a backtrace, because creating
672678 // a `Backtrace` will allocate, which we must to avoid here.
673- let panicinfo = PanicInfo :: internal_constructor ( message, location, can_unwind) ;
679+ let panicinfo = PanicInfo :: internal_constructor ( message, location, source , can_unwind) ;
674680 rtprintpanic ! ( "{panicinfo}\n panicked after panic::always_abort(), aborting.\n " ) ;
675681 }
676682 crate :: sys:: abort_internal ( ) ;
677683 }
678684
679- let mut info = PanicInfo :: internal_constructor ( message, location, can_unwind) ;
685+ let mut info = PanicInfo :: internal_constructor ( message, location, source , can_unwind) ;
680686 let hook = HOOK . read ( ) . unwrap_or_else ( PoisonError :: into_inner) ;
681687 match * hook {
682688 // Some platforms (like wasm) know that printing to stderr won't ever actually
0 commit comments