forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#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 rust-lang#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 rust-lang#110771
- Loading branch information
Showing
9 changed files
with
148 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//@normalize-stderr-test: "\| +\^+" -> "| ^" | ||
//@normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> "$1" | ||
//@normalize-stderr-test: "\n at [^\n]+" -> "$1" | ||
|
||
// Checks that nested panics work correctly. | ||
|
||
use std::panic::catch_unwind; | ||
|
||
fn double() { | ||
struct Double; | ||
|
||
impl Drop for Double { | ||
fn drop(&mut self) { | ||
let _ = catch_unwind(|| panic!("twice")); | ||
} | ||
} | ||
|
||
let _d = Double; | ||
|
||
panic!("once"); | ||
} | ||
|
||
fn main() { | ||
assert!(catch_unwind(|| double()).is_err()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
thread 'main' panicked at 'once', $DIR/nested_panic_caught.rs:LL:CC | ||
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace | ||
thread 'main' panicked at 'twice', $DIR/nested_panic_caught.rs:LL:CC | ||
stack backtrace: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// run-pass | ||
|
||
// Checks that nested panics work correctly. | ||
|
||
use std::panic::catch_unwind; | ||
|
||
fn double() { | ||
struct Double; | ||
|
||
impl Drop for Double { | ||
fn drop(&mut self) { | ||
let _ = catch_unwind(|| panic!("twice")); | ||
} | ||
} | ||
|
||
let _d = Double; | ||
|
||
panic!("once"); | ||
} | ||
|
||
fn main() { | ||
assert!(catch_unwind(|| double()).is_err()); | ||
} |