@@ -246,7 +246,9 @@ fn default_hook(info: &PanicInfo<'_>) {
246
246
pub fn panic_hook_with_disk_dump ( info : & PanicInfo < ' _ > , path : Option < & crate :: path:: Path > ) {
247
247
// If this is a double panic, make sure that we print a backtrace
248
248
// for this panic. Otherwise only print it if logging is enabled.
249
- let backtrace = if panic_count:: get_count ( ) >= 2 {
249
+ let backtrace = if info. force_no_backtrace ( ) {
250
+ None
251
+ } else if panic_count:: get_count ( ) >= 2 {
250
252
BacktraceStyle :: full ( )
251
253
} else {
252
254
crate :: panic:: get_backtrace_style ( )
@@ -294,7 +296,7 @@ pub fn panic_hook_with_disk_dump(info: &PanicInfo<'_>, path: Option<&crate::path
294
296
}
295
297
}
296
298
}
297
- // If backtraces aren't supported, do nothing.
299
+ // If backtraces aren't supported or are forced-off , do nothing.
298
300
None => { }
299
301
}
300
302
} ;
@@ -615,14 +617,23 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
615
617
let loc = info. location ( ) . unwrap ( ) ; // The current implementation always returns Some
616
618
let msg = info. message ( ) . unwrap ( ) ; // The current implementation always returns Some
617
619
crate :: sys_common:: backtrace:: __rust_end_short_backtrace ( move || {
620
+ // FIXME: can we just pass `info` along rather than taking it apart here, only to have
621
+ // `rust_panic_with_hook` construct a new `PanicInfo`?
618
622
if let Some ( msg) = msg. as_str ( ) {
619
- rust_panic_with_hook ( & mut StrPanicPayload ( msg) , info. message ( ) , loc, info. can_unwind ( ) ) ;
623
+ rust_panic_with_hook (
624
+ & mut StrPanicPayload ( msg) ,
625
+ info. message ( ) ,
626
+ loc,
627
+ info. can_unwind ( ) ,
628
+ info. force_no_backtrace ( ) ,
629
+ ) ;
620
630
} else {
621
631
rust_panic_with_hook (
622
632
& mut PanicPayload :: new ( msg) ,
623
633
info. message ( ) ,
624
634
loc,
625
635
info. can_unwind ( ) ,
636
+ info. force_no_backtrace ( ) ,
626
637
) ;
627
638
}
628
639
} )
@@ -647,7 +658,13 @@ pub const fn begin_panic<M: Any + Send>(msg: M) -> ! {
647
658
648
659
let loc = Location :: caller ( ) ;
649
660
return crate :: sys_common:: backtrace:: __rust_end_short_backtrace ( move || {
650
- rust_panic_with_hook ( & mut PanicPayload :: new ( msg) , None , loc, true )
661
+ rust_panic_with_hook (
662
+ & mut PanicPayload :: new ( msg) ,
663
+ None ,
664
+ loc,
665
+ /* can_unwind */ true ,
666
+ /* force_no_backtrace */ false ,
667
+ )
651
668
} ) ;
652
669
653
670
struct PanicPayload < A > {
@@ -693,6 +710,7 @@ fn rust_panic_with_hook(
693
710
message : Option < & fmt:: Arguments < ' _ > > ,
694
711
location : & Location < ' _ > ,
695
712
can_unwind : bool ,
713
+ force_no_backtrace : bool ,
696
714
) -> ! {
697
715
let must_abort = panic_count:: increase ( true ) ;
698
716
@@ -707,14 +725,20 @@ fn rust_panic_with_hook(
707
725
panic_count:: MustAbort :: AlwaysAbort => {
708
726
// Unfortunately, this does not print a backtrace, because creating
709
727
// a `Backtrace` will allocate, which we must to avoid here.
710
- let panicinfo = PanicInfo :: internal_constructor ( message, location, can_unwind) ;
728
+ let panicinfo = PanicInfo :: internal_constructor (
729
+ message,
730
+ location,
731
+ can_unwind,
732
+ force_no_backtrace,
733
+ ) ;
711
734
rtprintpanic ! ( "{panicinfo}\n panicked after panic::always_abort(), aborting.\n " ) ;
712
735
}
713
736
}
714
737
crate :: sys:: abort_internal ( ) ;
715
738
}
716
739
717
- let mut info = PanicInfo :: internal_constructor ( message, location, can_unwind) ;
740
+ let mut info =
741
+ PanicInfo :: internal_constructor ( message, location, can_unwind, force_no_backtrace) ;
718
742
let hook = HOOK . read ( ) . unwrap_or_else ( PoisonError :: into_inner) ;
719
743
match * hook {
720
744
// Some platforms (like wasm) know that printing to stderr won't ever actually
0 commit comments