Skip to content

Commit c005be9

Browse files
committed
panic_implementation -> panic_handler; remove unstable features
1 parent a0c1de1 commit c005be9

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@
5757
* [Implementing Arc and Mutex](arc-and-mutex.md)
5858
* [FFI](ffi.md)
5959
* [Beneath `std`](beneath-std.md)
60-
* [#[panic_implementation]](panic-implementation.md)
60+
* [#[panic_handler]](panic-handler.md)

src/panic-implementation.md renamed to src/panic-handler.md

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
## #[panic_implementation]
1+
## #[panic_handler]
22

3-
`#[panic_implementation]` is used to define the behavior of `panic!` in `#![no_std]` applications.
4-
The `#[panic_implementation]` attribute must be applied to a function with signature `fn(&PanicInfo)
3+
`#[panic_handler]` is used to define the behavior of `panic!` in `#![no_std]` applications.
4+
The `#[panic_handler]` attribute must be applied to a function with signature `fn(&PanicInfo)
55
-> !` and such function must appear *once* in the dependency graph of a binary / dylib / cdylib
66
crate. The API of `PanicInfo` can be found in the [API docs].
77

88
[API docs]: https://doc.rust-lang.org/nightly/core/panic/struct.PanicInfo.html
99

1010
Given that `#![no_std]` applications have no *standard* output and that some `#![no_std]`
1111
applications, e.g. embedded applications, need different panicking behaviors for development and for
12-
release it can be helpful to have panic crates, crate that only contain a `#[panic_implementation]`.
12+
release it can be helpful to have panic crates, crate that only contain a `#[panic_handler]`.
1313
This way applications can easily swap the panicking behavior by simply linking to a different panic
1414
crate.
1515

@@ -20,32 +20,27 @@ whether is compiled using the dev profile (`cargo build`) or using the release p
2020
``` rust
2121
// crate: panic-semihosting -- log panic message to the host stderr using semihosting
2222

23-
#![feature(core_intrinsics)]
24-
#![feature(panic_implementation)]
2523
#![no_std]
2624

27-
#[panic_implementation]
25+
#[panic_handler]
2826
fn panic(info: &PanicInfo) -> ! {
2927
let host_stderr = /* .. */;
3028

29+
// logs "panicked at '$reason', src/main.rs:27:4" to the host stderr
3130
writeln!(host_stderr, "{}", info).ok();
3231

33-
core::intrinsics::breakpoint();
34-
3532
loop {}
3633
}
3734
```
3835

3936
``` rust
40-
// crate: panic-abort -- abort on panic!
37+
// crate: panic-halt -- halt the thread on panic; messages are discarded
4138

42-
#![feature(core_intrinsics)]
43-
#![feature(panic_implementation)]
4439
#![no_std]
4540

46-
#[panic_implementation]
41+
#[panic_handler]
4742
fn panic(info: &PanicInfo) -> ! {
48-
unsafe { core::intrinsics::abort() }
43+
loop {}
4944
}
5045
```
5146

@@ -60,7 +55,7 @@ extern crate panic_semihosting;
6055

6156
// release profile
6257
#[cfg(not(debug_assertions))]
63-
extern crate panic_abort;
58+
extern crate panic_halt;
6459

6560
// omitted: other `extern crate`s
6661

0 commit comments

Comments
 (0)