Skip to content

Remove incorrect debug assertions from catch_unwind #68698

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

Merged
merged 1 commit into from
Feb 1, 2020
Merged
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
2 changes: 0 additions & 2 deletions src/libstd/panicking.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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!();
});
}