diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index 6ff7b19f293d3..ca32e458478da 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -246,7 +246,10 @@ fn default_hook(info: &PanicInfo<'_>) { pub fn panic_hook_with_disk_dump(info: &PanicInfo<'_>, path: Option<&crate::path::Path>) { // If this is a double panic, make sure that we print a backtrace // for this panic. Otherwise only print it if logging is enabled. - let backtrace = if panic_count::get_count() >= 2 { + // We do not keep printing for further panics, so that e.g. a "panic inside a drop on an unwind + // path", which leads to a triple-panic (the third panic being "cannot unwind here"), doesn't + // print *two* backtraces. + let backtrace = if panic_count::get_count() == 2 { BacktraceStyle::full() } else { crate::panic::get_backtrace_style() diff --git a/src/tools/miri/tests/fail/panic/double_panic.stderr b/src/tools/miri/tests/fail/panic/double_panic.stderr index 9efba031250be..20b751d57a250 100644 --- a/src/tools/miri/tests/fail/panic/double_panic.stderr +++ b/src/tools/miri/tests/fail/panic/double_panic.stderr @@ -6,7 +6,6 @@ second stack backtrace: thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC: panic in a destructor during cleanup -stack backtrace: thread caused non-unwinding panic. aborting. error: abnormal termination: the program aborted execution --> RUSTLIB/std/src/sys/PLATFORM/mod.rs:LL:CC diff --git a/tests/ui/backtrace.rs b/tests/ui/backtrace.rs index 95783945529a5..4c832ca157381 100644 --- a/tests/ui/backtrace.rs +++ b/tests/ui/backtrace.rs @@ -106,6 +106,8 @@ fn runtest(me: &str) { contains_verbose_expected(s, "double"), "bad output3: {}", s ); + // Make sure it's only one stack trace. + assert_eq!(s.split("stack backtrace").count(), 2); // Make sure a stack trace isn't printed too many times // diff --git a/tests/ui/panics/panic-in-cleanup.run.stderr b/tests/ui/panics/panic-in-cleanup.run.stderr index 923bac69c50ef..b655b388c6c68 100644 --- a/tests/ui/panics/panic-in-cleanup.run.stderr +++ b/tests/ui/panics/panic-in-cleanup.run.stderr @@ -6,5 +6,4 @@ BOOM stack backtrace: thread 'main' panicked at library/core/src/panicking.rs:126:5: panic in a destructor during cleanup -stack backtrace: thread caused non-unwinding panic. aborting.