Skip to content

Commit 6c0b779

Browse files
committed
Auto merge of #68698 - tmiasko:catch-panic, r=Amanieu
Remove incorrect debug assertions from catch_unwind Previously the debug assertions in the implementation of catch_unwind used to verify consistency of the panic count by checking that the count is zero just before leaving the function. This incorrectly assumed that no panic was in progress when entering `catch_unwind`. Fixes #68696.
2 parents cdd41ea + 80c3bec commit 6c0b779

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/libstd/panicking.rs

-2
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,9 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
286286
);
287287

288288
return if r == 0 {
289-
debug_assert!(update_panic_count(0) == 0);
290289
Ok(ManuallyDrop::into_inner(data.r))
291290
} else {
292291
update_panic_count(-1);
293-
debug_assert!(update_panic_count(0) == 0);
294292
Err(mem::transmute(raw::TraitObject {
295293
data: any_data as *mut _,
296294
vtable: any_vtable as *mut _,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Checks that catch_unwind can be used if unwinding is already in progress.
2+
// Used to fail when standard library had been compiled with debug assertions,
3+
// due to incorrect assumption that a current thread is not panicking when
4+
// entering the catch_unwind.
5+
//
6+
// run-pass
7+
// ignore-wasm no panic support
8+
// ignore-emscripten no panic support
9+
10+
use std::panic::catch_unwind;
11+
12+
#[derive(Default)]
13+
struct Guard;
14+
15+
impl Drop for Guard {
16+
fn drop(&mut self) {
17+
let _ = catch_unwind(|| {});
18+
}
19+
}
20+
21+
fn main() {
22+
let _ = catch_unwind(|| {
23+
let _guard = Guard::default();
24+
panic!();
25+
});
26+
}

0 commit comments

Comments
 (0)