Skip to content

Commit ddac383

Browse files
japaricehuss
authored andcommitted
panic_implementation -> panic_handler; beneath std -> the Rust runtime
1 parent dba3cbb commit ddac383

File tree

3 files changed

+45
-40
lines changed

3 files changed

+45
-40
lines changed

src/SUMMARY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@
112112
- [Constant Evaluation](const_eval.md)
113113

114114
- [Application Binary Interface](abi.md)
115-
- [Beneath `std`](beneath-std.md)
115+
116+
- [The Rust runtime](runtime.md)
116117

117118
[Appendix: Influences](influences.md)
118119

src/beneath-std.md

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/runtime.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# The Rust runtime
2+
3+
This section documents features that define some aspects of the Rust runtime. A list of such
4+
features is shown below:
5+
6+
- `#[panic_handler]`, the panicking behavior
7+
8+
## `#[panic_handler]`
9+
10+
The `panic_handler` attribute can only be applied to a function with signature
11+
`fn(&PanicInfo) -> !`. The function marked with this attribute defines the behavior of panics. The
12+
[`PanicInfo`] struct contains information about the location of the panic. There must be a single
13+
`panic_handler` function in the dependency graph of a binary, dylib or cdylib crate.
14+
15+
[`PanicInfo`]: https://doc.rust-lang.org/nightly/core/panic/struct.PanicInfo.html
16+
17+
Below is shown a `panic_handler` function that logs the panic message and then halts the
18+
thread.
19+
20+
``` rust
21+
#![no_std]
22+
23+
use core::intrinsics;
24+
use core::panic::PanicInfo;
25+
26+
#[panic_handler]
27+
fn panic(info: &PanicInfo) -> ! {
28+
let mut sink = /* .. */;
29+
30+
// logs "panicked at '$reason', src/main.rs:27:4" to some `sink`
31+
let _ = writeln!(sink, "{}", info);
32+
33+
loop {}
34+
}
35+
```
36+
37+
### Standard behavior
38+
39+
The standard library provides an implementation of `panic_handler` than can be
40+
statically customized using the `-C panic` flag. `-C panic=abort` makes panics
41+
abort the process, and `-C panic=unwind` makes panics unwind the panicking
42+
thread. If no panicking behavior is specified using `-C panic` one of these two
43+
behaviors is chosen according to the compilation target.

0 commit comments

Comments
 (0)