diff --git a/src/unwind.rs b/src/unwind.rs index 070aa28fe..abb7b921a 100644 --- a/src/unwind.rs +++ b/src/unwind.rs @@ -1,12 +1,16 @@ use std::io::{self, Write}; -use std::panic::{self, UnwindSafe}; +use std::panic::{self, AssertUnwindSafe}; use std::process; pub fn catch_unwind(label: &'static str, foreign_call: F) -> R where - F: FnOnce() -> R + UnwindSafe, + F: FnOnce() -> R, { - match panic::catch_unwind(foreign_call) { + // Regarding the AssertUnwindSafe: we immediately abort on panic so it + // doesn't matter whether the types involved are unwind-safe. The UnwindSafe + // bound on catch_unwind is about ensuring nothing is in a broken state if + // your program plans to continue after the panic. + match panic::catch_unwind(AssertUnwindSafe(foreign_call)) { Ok(ret) => ret, Err(_) => abort(label), }