panic_never/lib.rs
1//! This crate guarantees that your application is free of panicking branches
2//!
3//! If your *binary* crate contains at least one panicking branch *linking* will fail.
4//!
5//! This crate has no effect on libraries. It's meant to be a direct dependency of binary crates.
6//!
7//! This crate and your program *must* be compiled using the release profile or your crate will
8//! always fail to link.
9//!
10//! # Example
11//!
12//! ```
13//! #![no_main]
14//! #![no_std]
15//!
16//! #[cfg(debug_assertions)]
17//! use panic_halt as _;
18//!
19//! // only link this crate when using the release profile
20//! #[cfg(not(debug_assertions))]
21//! use panic_never as _;
22//! ```
23//!
24//! If your program contains at least one panicking branch you'll see the following linker error:
25//!
26//! ``` text
27//! (..)
28//! error: linking with `rust-lld` failed: exit code: 1
29//! (..)
30//! = note: rust-lld: error: undefined symbol:
31//! error(panic-never): your program contains at least one panicking branch
32//! ```
33//!
34//! # Minimum Supported Rust Version (MSRV)
35//!
36//! This crate is guaranteed to compile on stable Rust 1.31 and up. It *might* compile on older
37//! versions but that may change in any new patch release.
38
39#![deny(missing_docs)]
40#![deny(rust_2018_compatibility)]
41#![deny(rust_2018_idioms)]
42#![deny(warnings)]
43#![no_std]
44
45use core::panic::PanicInfo;
46
47#[panic_handler]
48fn panic(_: &PanicInfo<'_>) -> ! {
49 extern "Rust" {
50 #[link_name = "\nerror(panic-never): your program contains at least one panicking branch"]
51 fn undefined() -> !;
52 }
53
54 unsafe { undefined() }
55}