From d17ef56220a497bca837cf5b4c94f9b824603b53 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 10 Mar 2019 19:32:13 -0700 Subject: [PATCH] Update panic_handler. - Address review comments. - Some minor formatting adjustments. --- src/attributes.md | 2 ++ src/runtime.md | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/attributes.md b/src/attributes.md index caaffacd3..8117ad847 100644 --- a/src/attributes.md +++ b/src/attributes.md @@ -206,6 +206,7 @@ which can be used to control type layout. symbol for this item to its identifier. - [`used`] - on statics, this forces the compiler to keep the variable in the output object file. +- [`panic_handler`] — sets the function to handle panics. ### Deprecation @@ -632,3 +633,4 @@ pub fn f() {} [Expression Attributes]: expressions.html#expression-attributes [`meta` macro fragment specifier]: macros-by-example.html [`used`]: abi.html#the-used-attribute +[`panic_handler`]: runtime.html#the-panic_handler-attribute diff --git a/src/runtime.md b/src/runtime.md index 616a760cb..09fd888bf 100644 --- a/src/runtime.md +++ b/src/runtime.md @@ -1,19 +1,14 @@ # The Rust runtime -This section documents features that define some aspects of the Rust runtime. A list of such -features is shown below: +This section documents features that define some aspects of the Rust runtime. -- `#[panic_handler]`, the panicking behavior +## The `panic_handler` attribute -## `#[panic_handler]` - -The `panic_handler` attribute can only be applied to a function with signature -`fn(&PanicInfo) -> !`. The function marked with this attribute defines the behavior of panics. The +The *`panic_handler` attribute* can only be applied to a function with signature +`fn(&PanicInfo) -> !`. The function marked with this [attribute] defines the behavior of panics. The [`PanicInfo`] struct contains information about the location of the panic. There must be a single `panic_handler` function in the dependency graph of a binary, dylib or cdylib crate. -[`PanicInfo`]: https://doc.rust-lang.org/nightly/core/panic/struct.PanicInfo.html - Below is shown a `panic_handler` function that logs the panic message and then halts the thread. @@ -51,7 +46,12 @@ fn panic(info: &PanicInfo) -> ! { ### Standard behavior -The standard library provides an implementation of `panic_handler` than defaults -to unwinding the stack but that can be [changed to abort the process][abort]. +The standard library provides an implementation of `panic_handler` that +defaults to unwinding the stack but that can be [changed to abort the +process][abort]. The standard library's panic behavior can be modified at +runtime with the [set_hook] function. -[abort]: ../book/2018-edition/ch09-01-unrecoverable-errors-with-panic.html +[`PanicInfo`]: ../core/panic/struct.PanicInfo.html +[abort]: ../book/ch09-01-unrecoverable-errors-with-panic.html +[attribute]: attributes.html +[set_hook]: ../std/panic/fn.set_hook.html