diff --git a/bindgen-cli/main.rs b/bindgen-cli/main.rs index a61f67ad51..fed454afca 100644 --- a/bindgen-cli/main.rs +++ b/bindgen-cli/main.rs @@ -6,7 +6,6 @@ extern crate env_logger; extern crate log; use std::env; -use std::panic; mod options; use crate::options::builder_from_flags; @@ -41,18 +40,18 @@ pub fn main() { Ok((builder, output, verbose)) => { #[cfg(feature = "logging")] clang_version_check(); - let builder_result = panic::catch_unwind(|| { - builder.generate().expect("Unable to generate bindings") - }); - if builder_result.is_err() { + std::panic::set_hook(Box::new(move |_info| { if verbose { - print_verbose_err(); + print_verbose_err() } - std::process::exit(1); - } + })); + + let bindings = + builder.generate().expect("Unable to generate bindings"); + + let _ = std::panic::take_hook(); - let bindings = builder_result.unwrap(); bindings.write(output).expect("Unable to write output"); } Err(error) => { diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index d0eb466734..fb84c8c331 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -5,7 +5,6 @@ pub use crate::ir::derive::CanDerive as ImplementsTrait; pub use crate::ir::enum_ty::{EnumVariantCustomBehavior, EnumVariantValue}; pub use crate::ir::int::IntKind; use std::fmt; -use std::panic::UnwindSafe; /// An enum to allow ignoring parsing of macros. #[derive(Copy, Clone, Debug, PartialEq, Eq)] @@ -25,7 +24,7 @@ impl Default for MacroParsingBehavior { /// A trait to allow configuring different kinds of types in different /// situations. -pub trait ParseCallbacks: fmt::Debug + UnwindSafe { +pub trait ParseCallbacks: fmt::Debug { /// This function will be run on every macro that is identified. fn will_parse_macro(&self, _name: &str) -> MacroParsingBehavior { MacroParsingBehavior::Default diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 880d52a9ee..22ce603c4d 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -2103,11 +2103,6 @@ struct BindgenOptions { merge_extern_blocks: bool, } -/// TODO(emilio): This is sort of a lie (see the error message that results from -/// removing this), but since we don't share references across panic boundaries -/// it's ok. -impl ::std::panic::UnwindSafe for BindgenOptions {} - impl BindgenOptions { fn build(&mut self) { let mut regex_sets = [