Skip to content

Commit

Permalink
Make set_hook take a Box<Fn>
Browse files Browse the repository at this point in the history
Otherwise there's no good way of re-registering a hook you got out of
take_hook.
  • Loading branch information
sfackler committed Mar 16, 2016
1 parent 159eae8 commit 157e1bc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/libstd/panic.rs
Expand Up @@ -29,7 +29,7 @@ pub use panicking::{take_hook, set_hook, PanicInfo, Location};
#[rustc_deprecated(since = "1.9.0", reason = "renamed to set_hook")]
#[unstable(feature = "panic_handler", reason = "awaiting feedback", issue = "30449")]
pub fn set_handler<F>(handler: F) where F: Fn(&PanicInfo) + 'static + Sync + Send {
set_hook(handler)
set_hook(Box::new(handler))
}

///
Expand Down
3 changes: 1 addition & 2 deletions src/libstd/panicking.rs
Expand Up @@ -58,12 +58,11 @@ static FIRST_PANIC: AtomicBool = AtomicBool::new(true);
///
/// Panics if called from a panicking thread.
#[unstable(feature = "panic_handler", reason = "awaiting feedback", issue = "30449")]
pub fn set_hook<F>(hook: F) where F: Fn(&PanicInfo) + 'static + Sync + Send {
pub fn set_hook(hook: Box<Fn(&PanicInfo) + 'static + Sync + Send>) {
if thread::panicking() {
panic!("cannot modify the panic hook from a panicking thread");
}

let hook = Box::new(hook);
unsafe {
let lock = HOOK_LOCK.write();
let old_hook = HOOK;
Expand Down

0 comments on commit 157e1bc

Please sign in to comment.