File tree 3 files changed +44
-40
lines changed
3 files changed +44
-40
lines changed Original file line number Diff line number Diff line change 87
87
- [ Behavior considered undefined] ( behavior-considered-undefined.md )
88
88
- [ Behavior not considered unsafe] ( behavior-not-considered-unsafe.md )
89
89
90
- - [ Beneath ` std ` ] ( beneath-std .md)
90
+ - [ The Rust runtime ] ( runtime .md)
91
91
92
92
[ Appendix: Influences] ( influences.md )
93
93
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
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.
You can’t perform that action at this time.
0 commit comments