Unreachable warnings for debug-only panic
⚓ Rust 📅 2026-02-24 👤 surdeus 👁️ 1I've got a macro that looks roughly like this:
#[cfg(debug_assertions)]
macro_rules! fatal {
($($tt:tt)*) => {
if true { panic!($($tt)*) }
};
}
#[cfg(not(debug_assertions))]
macro_rules! fatal {
($($tt:tt)*) => {
::log::error!($($tt)*)
};
}
The idea is that for situations where I'd like to panic!(), I can instead use this macro, and I'll avoid taking down my entire app and log instead. But, in debug mode, it'll still force a crash and force me to go debug something. I realize it's not the most common use case, but it works nicely for me.
My problem is that in debug mode, any code after this gets warned as unreachable. This is why I added the if true {} block around the panic. I was wondering how stable that hack is? Is there a better way to silence the unreachable code lint in debug mode?
1 post - 1 participant
🏷️ Rust_feed