Macro kernel::build_error

source ·
macro_rules! build_error {
    () => { ... };
    ($msg:expr) => { ... };
}
Expand description

Fails the build if the code path calling build_error! can possibly be executed.

If the macro is executed in const context, build_error! will panic. If the compiler or optimizer cannot guarantee that build_error! can never be called, a build error will be triggered.

§Examples

#[inline]
fn foo(a: usize) -> usize {
    a.checked_add(1).unwrap_or_else(|| build_error!("overflow"))
}

assert_eq!(foo(usize::MAX - 1), usize::MAX); // OK.
// foo(usize::MAX); // Fails to compile.