Skip to content

Commit

Permalink
Remove incorrect debug assertions from catch_unwind
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
tmiasko committed Jan 31, 2020
1 parent b1cb3c0 commit 80c3bec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/libstd/panicking.rs
Expand Up @@ -286,11 +286,9 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
);

return if r == 0 {
debug_assert!(update_panic_count(0) == 0);
Ok(ManuallyDrop::into_inner(data.r))
} else {
update_panic_count(-1);
debug_assert!(update_panic_count(0) == 0);
Err(mem::transmute(raw::TraitObject {
data: any_data as *mut _,
vtable: any_vtable as *mut _,
Expand Down
26 changes: 26 additions & 0 deletions src/test/ui/issues/issue-68696-catch-during-unwind.rs
@@ -0,0 +1,26 @@
// Checks that catch_unwind can be used if unwinding is already in progress.
// Used to fail when standard library had been compiled with debug assertions,
// due to incorrect assumption that a current thread is not panicking when
// entering the catch_unwind.
//
// run-pass
// ignore-wasm no panic support
// ignore-emscripten no panic support

use std::panic::catch_unwind;

#[derive(Default)]
struct Guard;

impl Drop for Guard {
fn drop(&mut self) {
let _ = catch_unwind(|| {});
}
}

fn main() {
let _ = catch_unwind(|| {
let _guard = Guard::default();
panic!();
});
}

0 comments on commit 80c3bec

Please sign in to comment.