Skip to content

Commit

Permalink
Update panic_handler.
Browse files Browse the repository at this point in the history
- Address review comments.
- Some minor formatting adjustments.
  • Loading branch information
ehuss committed Mar 11, 2019
1 parent bd744e2 commit f659a93
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ which can be used to control type layout.
object file that this item's contents will be placed into.
- `no_mangle` - on any item, do not apply the standard name mangling. Set the
symbol for this item to its identifier.
- [`panic_handler`] — sets the function to handle panics.

### Deprecation

Expand Down Expand Up @@ -629,3 +630,4 @@ pub fn f() {}
[trait or lifetime bounds]: trait-bounds.html
[Expression Attributes]: expressions.html#expression-attributes
[`meta` macro fragment specifier]: macros-by-example.html
[`panic_handler`]: runtime.html#the-panic_handler-attribute
24 changes: 12 additions & 12 deletions src/runtime.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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

0 comments on commit f659a93

Please sign in to comment.