Expand description

This crate provides macros that look just like unreachable!() but instead of panicking, they cause a linking error if their calls are not optimized-out. This can be used to ensure the compiler optimizes away some code.


extern crate unreachable_checked;

fn main() {
    let x = 6 * 9;
    if x == 42 {
        unreachable_checked!("6 * 9 == 42");
let x = false;
if x {

Compile with --release or --features=panic


  • Like assert but calls unreachable_checked!() instead of unreachable!()
  • This macro doesn’t panic. Instead it tries to call a non-existing function. If the compiler can prove it can’t be called and optimizes it away, the code will compile just fine. Otherwise you get a linking error.


  • This function calls the given closure, asserting that there’s no possibility of panicking. If the compiler can’t prove this, the code will be left with a unreachable_checked! linking error.
  • This function doesn’t actually exist. It ensures a linking error if it isn’t optimized-out.