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.
§Example
#[macro_use]
extern crate unreachable_checked;
fn main() {
/*
let x = 6 * 9;
if x == 42 {
unreachable_checked!("6 * 9 == 42");
}
*/
let x = false;
if x {
unreachable_checked!("42");
}
}
Compile with --release
or --features=panic
Macros§
- dp_
assert - Like assert but calls
unreachable_checked!()
instead ofunreachable!()
- unreachable_
checked - 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.
Functions§
- call
- 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. - rust_
panic_ ⚠called_ where_ shouldnt - This function doesn’t actually exist. It ensures a linking error if it isn’t optimized-out.