File tree 3 files changed +47
-0
lines changed
3 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 112
112
- [ Constant Evaluation] ( const_eval.md )
113
113
114
114
- [ Application Binary Interface] ( abi.md )
115
+ - [ Beneath ` std ` ] ( beneath-std.md )
116
+ - [ #[ panic_implementation]] ( panic-implementation.md )
115
117
116
118
[ Appendix: Influences] ( influences.md )
117
119
Original file line number Diff line number Diff line change
1
+ # Beneath ` std `
2
+
3
+ This section documents (or will document) features that are provided by the standard library and
4
+ that ` #![no_std] ` developers have to deal with (i.e. provide) to build ` #![no_std] ` binary crates. A
5
+ (likely incomplete) list of such features is shown below:
6
+
7
+ - #[ lang = "eh_personality"]
8
+ - #[ lang = "start"]
9
+ - #[ lang = "termination"]
10
+ - #[ panic_implementation]
Original file line number Diff line number Diff line change
1
+ ## #[ panic_implementation]
2
+
3
+ The ` #[panic_implementation] ` attribute can only be applied to a function with signature
4
+ ` fn(&PanicInfo) -> ! ` . The function marked with this attribute defines the behavior of ` panic! ` in
5
+ ` #![no_std] ` applications. There must be a * single* ` #[panic_implementation] ` function in the
6
+ dependency graph of a binary / dylib / cdylib crate.
7
+
8
+ The ` PanicInfo ` struct contains information about the location of the panic. The API of ` PanicInfo `
9
+ can be found in the [ API docs] . As of 1.28-beta (2018-06-21) there's a difference between
10
+ ` core::panic! ` and ` std::panic! ` : the former doesn't accept non-string payloads -- that is
11
+ ` core::panic!(42) ` is not accepted. In the future ` core::panic! ` may gain support for non-string
12
+ payloads. The implementation of ` core::panic! ` can be found in ` src/libcore/{macros,panicking}.rs `
13
+
14
+ [ API docs ] : https://doc.rust-lang.org/nightly/core/panic/struct.PanicInfo.html
15
+
16
+ Below is shown a ` #[panic_implementation] ` that logs the panic message and then aborts the program.
17
+
18
+ ``` rust
19
+ #![feature(core_intrinsics)]
20
+ #![feature(panic_implementation)]
21
+ #![no_std]
22
+
23
+ use core :: intrinsics;
24
+ use core :: panic :: PanicInfo ;
25
+
26
+ #[panic_implementation]
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
+ unsafe { intrinsics :: abort () }
34
+ }
35
+ ```
You can’t perform that action at this time.
0 commit comments