Skip to content

for triple-panics, do not keep printing backtraces #115020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion library/std/src/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion src/tools/miri/tests/fail/panic/double_panic.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
1 change: 0 additions & 1 deletion tests/ui/panics/panic-in-cleanup.run.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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.