@@ -13,6 +13,7 @@ use crate::panic::BacktraceStyle;
13
13
use core:: panic:: { BoxMeUp , Location , PanicInfo } ;
14
14
15
15
use crate :: any:: Any ;
16
+ use crate :: error:: Error ;
16
17
use crate :: fmt;
17
18
use crate :: intrinsics;
18
19
use crate :: mem:: { self , ManuallyDrop } ;
@@ -258,7 +259,9 @@ fn default_hook(info: &PanicInfo<'_>) {
258
259
259
260
let write = |err : & mut dyn crate :: io:: Write | {
260
261
let _ = writeln ! ( err, "thread '{name}' panicked at '{msg}', {location}" ) ;
261
-
262
+ if info. source ( ) . is_some ( ) {
263
+ writeln ! ( err, "fun is not allowed" ) ;
264
+ }
262
265
static FIRST_PANIC : AtomicBool = AtomicBool :: new ( true ) ;
263
266
264
267
match backtrace {
@@ -574,15 +577,17 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
574
577
}
575
578
576
579
let loc = info. location ( ) . unwrap ( ) ; // The current implementation always returns Some
580
+ let source = info. source ( ) ;
577
581
let msg = info. message ( ) . unwrap ( ) ; // The current implementation always returns Some
578
582
crate :: sys_common:: backtrace:: __rust_end_short_backtrace ( move || {
579
583
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 ( ) ) ;
581
585
} else {
582
586
rust_panic_with_hook (
583
587
& mut PanicPayload :: new ( msg) ,
584
588
info. message ( ) ,
585
589
loc,
590
+ source,
586
591
info. can_unwind ( ) ,
587
592
) ;
588
593
}
@@ -608,7 +613,7 @@ pub const fn begin_panic<M: Any + Send>(msg: M) -> ! {
608
613
609
614
let loc = Location :: caller ( ) ;
610
615
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 )
612
617
} ) ;
613
618
614
619
struct PanicPayload < A > {
@@ -653,6 +658,7 @@ fn rust_panic_with_hook(
653
658
payload : & mut dyn BoxMeUp ,
654
659
message : Option < & fmt:: Arguments < ' _ > > ,
655
660
location : & Location < ' _ > ,
661
+ source : Option < & ( dyn Error + ' static ) > ,
656
662
can_unwind : bool ,
657
663
) -> ! {
658
664
let ( must_abort, panics) = panic_count:: increase ( ) ;
@@ -670,13 +676,13 @@ fn rust_panic_with_hook(
670
676
} else {
671
677
// Unfortunately, this does not print a backtrace, because creating
672
678
// 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) ;
674
680
rtprintpanic ! ( "{panicinfo}\n panicked after panic::always_abort(), aborting.\n " ) ;
675
681
}
676
682
crate :: sys:: abort_internal ( ) ;
677
683
}
678
684
679
- let mut info = PanicInfo :: internal_constructor ( message, location, can_unwind) ;
685
+ let mut info = PanicInfo :: internal_constructor ( message, location, source , can_unwind) ;
680
686
let hook = HOOK . read ( ) . unwrap_or_else ( PoisonError :: into_inner) ;
681
687
match * hook {
682
688
// Some platforms (like wasm) know that printing to stderr won't ever actually
0 commit comments