tuwunel_core/utils/unhandled.rs
1//! Indicate a branch which will never be taken. Currently expands to
2//! `unimplemented!()` in every build; the `unreachable_unchecked()` arm below
3//! is parked behind `#[cfg(disable)]` until callsites are vetted.
4
5#[cfg(disable)] // activate when more stable and callsites are vetted.
6// #[cfg(not(debug_assertions))]
7#[macro_export]
8macro_rules! unhandled {
9 ($msg:literal) => {
10 // SAFETY: Eliminates branches never encountered in the codebase. This can
11 // promote optimization and reduce codegen. The developer must verify for every
12 // invoking callsite that the unhandled type is in no way involved and could not
13 // possibly be encountered.
14 unsafe {
15 std::hint::unreachable_unchecked();
16 }
17 };
18}
19
20//#[cfg(debug_assertions)]
21#[macro_export]
22macro_rules! unhandled {
23 ($msg:literal) => {
24 $crate::maybe_unhandled!($msg);
25 };
26}
27
28#[macro_export]
29macro_rules! maybe_unhandled {
30 ($msg:literal) => {
31 unimplemented!($msg)
32 };
33}