14
14
#[ macro_export]
15
15
macro_rules! fail(
16
16
( ) => (
17
- fail!( "explicit failure" )
17
+ fail!( "{}" , " explicit failure")
18
18
) ;
19
19
( $msg: expr) => (
20
- :: core :: failure :: begin_unwind ( $msg , file! ( ) , line! ( ) )
20
+ fail! ( "{}" , $msg )
21
21
) ;
22
+ ( $fmt: expr, $( $arg: tt) * ) => ( {
23
+ // a closure can't have return type !, so we need a full
24
+ // function to pass to format_args!, *and* we need the
25
+ // file and line numbers right here; so an inner bare fn
26
+ // is our only choice.
27
+ //
28
+ // LLVM doesn't tend to inline this, presumably because begin_unwind_fmt
29
+ // is #[cold] and #[inline(never)] and because this is flagged as cold
30
+ // as returning !. We really do want this to be inlined, however,
31
+ // because it's just a tiny wrapper. Small wins (156K to 149K in size)
32
+ // were seen when forcing this to be inlined, and that number just goes
33
+ // up with the number of calls to fail!()
34
+ #[ inline( always) ]
35
+ fn run_fmt( fmt: & :: std:: fmt:: Arguments ) -> ! {
36
+ :: core:: failure:: begin_unwind( fmt, file!( ) , line!( ) )
37
+ }
38
+ format_args!( run_fmt, $fmt, $( $arg) * )
39
+ } ) ;
22
40
)
23
41
24
42
/// Runtime assertion, for details see std::macros
@@ -29,6 +47,11 @@ macro_rules! assert(
29
47
fail!( concat!( "assertion failed: " , stringify!( $cond) ) )
30
48
}
31
49
) ;
50
+ ( $cond: expr, $( $arg: tt) * ) => (
51
+ if !$cond {
52
+ fail!( $( $arg) * )
53
+ }
54
+ ) ;
32
55
)
33
56
34
57
/// Runtime assertion, disableable at compile time
0 commit comments