std::macros::fail![src]
macro_rules! fail( () => ( fail!("explicit failure") ); ($msg:expr) => ( ::std::rt::begin_unwind($msg, file!(), line!()) ); ($fmt:expr, $($arg:tt)*) => ({ // a closure can't have return type !, so we need a full // function to pass to format_args!, *and* we need the // file and line numbers right here; so an inner bare fn // is our only choice. // // LLVM doesn't tend to inline this, presumably because begin_unwind_fmt // is #[cold] and #[inline(never)] and because this is flagged as cold // as returning !. We really do want this to be inlined, however, // because it's just a tiny wrapper. Small wins (156K to 149K in size) // were seen when forcing this to be inlined, and that number just goes // up with the number of calls to fail!() #[inline(always)] fn run_fmt(fmt: &::std::fmt::Arguments) -> ! { ::std::rt::begin_unwind_fmt(fmt, file!(), line!()) } format_args!(run_fmt, $fmt, $($arg)*) }); )
The entry point for failure of rust tasks.
This macro is used to inject failure into a rust task, causing the task to
unwind and fail entirely. Each task's failure can be reaped as the
Box<Any> type, and the single-argument form of the fail! macro will be
the value which is transmitted.
The multi-argument form of this macro fails with a string and has the
format! syntax for building a string.
Example
fn main() { #![allow(unreachable_code)] fail!(); fail!("this is a terrible mistake!"); fail!(4i); // fail with the value of 4 to be collected elsewhere fail!("this is a {} {message}", "fancy", message = "message"); }fail!(); fail!("this is a terrible mistake!"); fail!(4i); // fail with the value of 4 to be collected elsewhere fail!("this is a {} {message}", "fancy", message = "message");