@@ -246,7 +246,9 @@ fn default_hook(info: &PanicInfo<'_>) {
246246pub fn panic_hook_with_disk_dump ( info : & PanicInfo < ' _ > , path : Option < & crate :: path:: Path > ) {
247247 // If this is a double panic, make sure that we print a backtrace
248248 // 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 {
250252 BacktraceStyle :: full ( )
251253 } else {
252254 crate :: panic:: get_backtrace_style ( )
@@ -294,7 +296,7 @@ pub fn panic_hook_with_disk_dump(info: &PanicInfo<'_>, path: Option<&crate::path
294296 }
295297 }
296298 }
297- // If backtraces aren't supported, do nothing.
299+ // If backtraces aren't supported or are forced-off , do nothing.
298300 None => { }
299301 }
300302 } ;
@@ -615,14 +617,23 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
615617 let loc = info. location ( ) . unwrap ( ) ; // The current implementation always returns Some
616618 let msg = info. message ( ) . unwrap ( ) ; // The current implementation always returns Some
617619 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`?
618622 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+ ) ;
620630 } else {
621631 rust_panic_with_hook (
622632 & mut PanicPayload :: new ( msg) ,
623633 info. message ( ) ,
624634 loc,
625635 info. can_unwind ( ) ,
636+ info. force_no_backtrace ( ) ,
626637 ) ;
627638 }
628639 } )
@@ -647,7 +658,13 @@ pub const fn begin_panic<M: Any + Send>(msg: M) -> ! {
647658
648659 let loc = Location :: caller ( ) ;
649660 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+ )
651668 } ) ;
652669
653670 struct PanicPayload < A > {
@@ -693,6 +710,7 @@ fn rust_panic_with_hook(
693710 message : Option < & fmt:: Arguments < ' _ > > ,
694711 location : & Location < ' _ > ,
695712 can_unwind : bool ,
713+ force_no_backtrace : bool ,
696714) -> ! {
697715 let must_abort = panic_count:: increase ( true ) ;
698716
@@ -707,14 +725,20 @@ fn rust_panic_with_hook(
707725 panic_count:: MustAbort :: AlwaysAbort => {
708726 // Unfortunately, this does not print a backtrace, because creating
709727 // 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+ ) ;
711734 rtprintpanic ! ( "{panicinfo}\n panicked after panic::always_abort(), aborting.\n " ) ;
712735 }
713736 }
714737 crate :: sys:: abort_internal ( ) ;
715738 }
716739
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) ;
718742 let hook = HOOK . read ( ) . unwrap_or_else ( PoisonError :: into_inner) ;
719743 match * hook {
720744 // Some platforms (like wasm) know that printing to stderr won't ever actually
0 commit comments