1 | #![deny (missing_docs, warnings)] |
2 | |
3 | #![no_std ] |
4 | |
5 | //! `panic!()` in debug builds, optimization hint in release. |
6 | |
7 | #[doc (hidden)] pub mod _internal { pub use core::hint::unreachable_unchecked; } |
8 | |
9 | #[macro_export ] |
10 | /// `panic!()` in debug builds, optimization hint in release. |
11 | /// |
12 | /// Example: |
13 | /// |
14 | /// ``` |
15 | /// use debug_unreachable::debug_unreachable; |
16 | /// |
17 | /// fn main() { |
18 | /// if 0 > 100 { |
19 | /// // Can't happen! |
20 | /// unsafe { debug_unreachable!() } |
21 | /// } else { |
22 | /// println!("Good, 0 <= 100." ); |
23 | /// } |
24 | /// } |
25 | /// ``` |
26 | macro_rules! debug_unreachable { |
27 | () => { debug_unreachable!("entered unreachable code" ) }; |
28 | ($e:expr) => { |
29 | if cfg!(debug_assertions) { |
30 | panic!($e) |
31 | } else { |
32 | $crate::_internal::unreachable_unchecked() |
33 | } |
34 | } |
35 | } |
36 | |
37 | |