You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of #110975 - Amanieu:panic_count, r=joshtriplett
Rework handling of recursive panics
This PR makes 2 changes to how recursive panics works (a panic while handling a panic).
1. The panic count is no longer used to determine whether to force an immediate abort. This allows code like the following to work without aborting the process immediately:
```rust
struct Double;
impl Drop for Double {
fn drop(&mut self) {
// 2 panics are active at once, but this is fine since it is caught.
std::panic::catch_unwind(|| panic!("twice"));
}
}
let _d = Double;
panic!("once");
```
Rustc already generates appropriate code so that any exceptions escaping out of a `Drop` called in the unwind path will immediately abort the process.
2. Any panics while the panic hook is executing will force an immediate abort. This is necessary to avoid potential deadlocks like #110771 where a panic happens while holding the backtrace lock. We don't even try to print the panic message in this case since the panic may have been caused by `Display` impls.
Fixes#110771
Copy file name to clipboardExpand all lines: src/tools/miri/tests/fail/panic/double_panic.stderr
+8-21
Original file line number
Diff line number
Diff line change
@@ -2,30 +2,17 @@ thread 'main' panicked at 'first', $DIR/double_panic.rs:LL:CC
2
2
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
3
3
thread 'main' panicked at 'second', $DIR/double_panic.rs:LL:CC
4
4
stack backtrace:
5
-
thread panicked while panicking. aborting.
6
-
error: abnormal termination: the program aborted execution
7
-
--> RUSTLIB/std/src/sys/PLATFORM/mod.rs:LL:CC
8
-
|
9
-
LL | ABORT();
10
-
| ^ the program aborted execution
11
-
|
12
-
= note: inside `std::sys::PLATFORM::abort_internal` at RUSTLIB/std/src/sys/PLATFORM/mod.rs:LL:CC
13
-
= note: inside `std::panicking::rust_panic_with_hook` at RUSTLIB/std/src/panicking.rs:LL:CC
14
-
= note: inside closure at RUSTLIB/std/src/panicking.rs:LL:CC
15
-
= note: inside `std::sys_common::backtrace::__rust_end_short_backtrace::<[closure@std::panicking::begin_panic_handler::{closure#0}], !>` at RUSTLIB/std/src/sys_common/backtrace.rs:LL:CC
16
-
= note: inside `std::panicking::begin_panic_handler` at RUSTLIB/std/src/panicking.rs:LL:CC
17
-
note: inside `<Foo as std::ops::Drop>::drop`
5
+
error: abnormal termination: panic in a function that cannot unwind
18
6
--> $DIR/double_panic.rs:LL:CC
19
7
|
20
-
LL | panic!("second");
21
-
| ^
22
-
= note: inside `std::ptr::drop_in_place::<Foo> - shim(Some(Foo))` at RUSTLIB/core/src/ptr/mod.rs:LL:CC
23
-
note: inside `main`
24
-
--> $DIR/double_panic.rs:LL:CC
8
+
LL | / fn main() {
9
+
LL | |
10
+
LL | | let _foo = Foo;
11
+
LL | | panic!("first");
12
+
LL | | }
13
+
| |_^ panic in a function that cannot unwind
25
14
|
26
-
LL | }
27
-
| ^
28
-
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
15
+
= note: inside `main` at $DIR/double_panic.rs:LL:CC
29
16
30
17
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
0 commit comments