]> git.lizzy.rs Git - rust.git/commitdiff
Make set_hook take a Box<Fn>
authorSteven Fackler <sfackler@gmail.com>
Wed, 16 Mar 2016 03:19:03 +0000 (20:19 -0700)
committerSteven Fackler <sfackler@gmail.com>
Wed, 16 Mar 2016 03:51:48 +0000 (20:51 -0700)
Otherwise there's no good way of re-registering a hook you got out of
take_hook.

src/libstd/panic.rs
src/libstd/panicking.rs

index 56d638d9df3b4d0adab4f646461584b0c5bfff12..aff11d036f8f91e16006a8c624afb01db229bcfb 100644 (file)
@@ -29,7 +29,7 @@
 #[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))
 }
 
 ///
index 556dddf9387e230bbe60fe225edd7e92f55cbda0..fd6a15b0f69a3f8bebf751eae3cfeeb643e7fbed 100644 (file)
@@ -58,12 +58,11 @@ enum Hook {
 ///
 /// 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;