Skip to content

Commit e781a6f

Browse files
authored
Rollup merge of rust-lang#108105 - majaha:patch-1, r=cuviper
Explain the default panic hook better This changes the documentation of `std::panic::set_hook` and `take_hook` to explain how the default panic hook works. In particular the fact that `take_hook` registers the default hook, rather than no hook at all, was missing from the docs. I also reworded a few things for clarity.
2 parents 4dea3a2 + ec9a4ce commit e781a6f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

library/std/src/panicking.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,16 @@ impl Default for Hook {
9595

9696
static HOOK: RwLock<Hook> = RwLock::new(Hook::Default);
9797

98-
/// Registers a custom panic hook, replacing any that was previously registered.
98+
/// Registers a custom panic hook, replacing the previously registered hook.
9999
///
100100
/// The panic hook is invoked when a thread panics, but before the panic runtime
101101
/// is invoked. As such, the hook will run with both the aborting and unwinding
102-
/// runtimes. The default hook prints a message to standard error and generates
103-
/// a backtrace if requested, but this behavior can be customized with the
104-
/// `set_hook` and [`take_hook`] functions.
102+
/// runtimes.
103+
///
104+
/// The default hook, which is registered at startup, prints a message to standard error and
105+
/// generates a backtrace if requested. This behavior can be customized using the `set_hook` function.
106+
/// The current hook can be retrieved while reinstating the default hook with the [`take_hook`]
107+
/// function.
105108
///
106109
/// [`take_hook`]: ./fn.take_hook.html
107110
///
@@ -143,13 +146,14 @@ pub fn set_hook(hook: Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send>) {
143146
drop(old);
144147
}
145148

146-
/// Unregisters the current panic hook, returning it.
149+
/// Unregisters the current panic hook and returns it, registering the default hook
150+
/// in its place.
147151
///
148152
/// *See also the function [`set_hook`].*
149153
///
150154
/// [`set_hook`]: ./fn.set_hook.html
151155
///
152-
/// If no custom hook is registered, the default hook will be returned.
156+
/// If the default hook is registered it will be returned, but remain registered.
153157
///
154158
/// # Panics
155159
///

0 commit comments

Comments
 (0)