@@ -32,73 +32,72 @@ thread_local! {
3232}
3333
3434#[ derive( Copy , Clone ) ]
35- enum Handler {
35+ enum Hook {
3636 Default ,
3737 Custom ( * mut ( Fn ( & PanicInfo ) + ' static + Sync + Send ) ) ,
3838}
3939
40- static HANDLER_LOCK : StaticRwLock = StaticRwLock :: new ( ) ;
41- static mut HANDLER : Handler = Handler :: Default ;
40+ static HOOK_LOCK : StaticRwLock = StaticRwLock :: new ( ) ;
41+ static mut HOOK : Hook = Hook :: Default ;
4242static FIRST_PANIC : AtomicBool = AtomicBool :: new ( true ) ;
4343
44- /// Registers a custom panic handler, replacing any that was previously
45- /// registered.
44+ /// Registers a custom panic hook, replacing any that was previously registered.
4645///
47- /// The panic handler is invoked when a thread panics, but before it begins
48- /// unwinding the stack. The default handler prints a message to standard error
46+ /// The panic hook is invoked when a thread panics, but before it begins
47+ /// unwinding the stack. The default hook prints a message to standard error
4948/// and generates a backtrace if requested, but this behavior can be customized
50- /// with the `set_handler ` and `take_handler ` functions.
49+ /// with the `set_hook ` and `take_hook ` functions.
5150///
52- /// The handler is provided with a `PanicInfo` struct which contains information
51+ /// The hook is provided with a `PanicInfo` struct which contains information
5352/// about the origin of the panic, including the payload passed to `panic!` and
5453/// the source code location from which the panic originated.
5554///
56- /// The panic handler is a global resource.
55+ /// The panic hook is a global resource.
5756///
5857/// # Panics
5958///
6059/// Panics if called from a panicking thread.
6160#[ unstable( feature = "panic_handler" , reason = "awaiting feedback" , issue = "30449" ) ]
62- pub fn set_handler < F > ( handler : F ) where F : Fn ( & PanicInfo ) + ' static + Sync + Send {
61+ pub fn set_hook < F > ( hook : F ) where F : Fn ( & PanicInfo ) + ' static + Sync + Send {
6362 if thread:: panicking ( ) {
64- panic ! ( "cannot modify the panic handler from a panicking thread" ) ;
63+ panic ! ( "cannot modify the panic hook from a panicking thread" ) ;
6564 }
6665
67- let handler = Box :: new ( handler ) ;
66+ let hook = Box :: new ( hook ) ;
6867 unsafe {
69- let lock = HANDLER_LOCK . write ( ) ;
70- let old_handler = HANDLER ;
71- HANDLER = Handler :: Custom ( Box :: into_raw ( handler ) ) ;
68+ let lock = HOOK_LOCK . write ( ) ;
69+ let old_hook = HOOK ;
70+ HOOK = Hook :: Custom ( Box :: into_raw ( hook ) ) ;
7271 drop ( lock) ;
7372
74- if let Handler :: Custom ( ptr) = old_handler {
73+ if let Hook :: Custom ( ptr) = old_hook {
7574 Box :: from_raw ( ptr) ;
7675 }
7776 }
7877}
7978
80- /// Unregisters the current panic handler , returning it.
79+ /// Unregisters the current panic hook , returning it.
8180///
82- /// If no custom handler is registered, the default handler will be returned.
81+ /// If no custom hook is registered, the default hook will be returned.
8382///
8483/// # Panics
8584///
8685/// Panics if called from a panicking thread.
8786#[ unstable( feature = "panic_handler" , reason = "awaiting feedback" , issue = "30449" ) ]
88- pub fn take_handler ( ) -> Box < Fn ( & PanicInfo ) + ' static + Sync + Send > {
87+ pub fn take_hook ( ) -> Box < Fn ( & PanicInfo ) + ' static + Sync + Send > {
8988 if thread:: panicking ( ) {
90- panic ! ( "cannot modify the panic handler from a panicking thread" ) ;
89+ panic ! ( "cannot modify the panic hook from a panicking thread" ) ;
9190 }
9291
9392 unsafe {
94- let lock = HANDLER_LOCK . write ( ) ;
95- let handler = HANDLER ;
96- HANDLER = Handler :: Default ;
93+ let lock = HOOK_LOCK . write ( ) ;
94+ let hook = HOOK ;
95+ HOOK = Hook :: Default ;
9796 drop ( lock) ;
9897
99- match handler {
100- Handler :: Default => Box :: new ( default_handler ) ,
101- Handler :: Custom ( ptr) => { Box :: from_raw ( ptr) } // FIXME #30530
98+ match hook {
99+ Hook :: Default => Box :: new ( default_hook ) ,
100+ Hook :: Custom ( ptr) => { Box :: from_raw ( ptr) } // FIXME #30530
102101 }
103102 }
104103}
@@ -151,7 +150,7 @@ impl<'a> Location<'a> {
151150 }
152151}
153152
154- fn default_handler ( info : & PanicInfo ) {
153+ fn default_hook ( info : & PanicInfo ) {
155154 let panics = PANIC_COUNT . with ( |s| s. get ( ) ) ;
156155
157156 // If this is a double panic, make sure that we print a backtrace
@@ -224,10 +223,10 @@ pub fn on_panic(obj: &(Any+Send), file: &'static str, line: u32) {
224223 } ;
225224
226225 unsafe {
227- let _lock = HANDLER_LOCK . read ( ) ;
228- match HANDLER {
229- Handler :: Default => default_handler ( & info) ,
230- Handler :: Custom ( ptr) => ( * ptr) ( & info) ,
226+ let _lock = HOOK_LOCK . read ( ) ;
227+ match HOOK {
228+ Hook :: Default => default_hook ( & info) ,
229+ Hook :: Custom ( ptr) => ( * ptr) ( & info) ,
231230 }
232231 }
233232
0 commit comments