@@ -20,23 +20,33 @@ macro_rules! log(
20
20
}
21
21
} )
22
22
)
23
+
23
24
#[ macro_export]
24
- macro_rules! error( ( $( $arg: tt) * ) => ( log!( 1u32 , $( $arg) * ) ) )
25
+ macro_rules! error(
26
+ ( $( $arg: tt) * ) => ( log!( 1u32 , $( $arg) * ) )
27
+ )
28
+
25
29
#[ macro_export]
26
- macro_rules! warn ( ( $( $arg: tt) * ) => ( log!( 2u32 , $( $arg) * ) ) )
30
+ macro_rules! warn(
31
+ ( $( $arg: tt) * ) => ( log!( 2u32 , $( $arg) * ) )
32
+ )
33
+
27
34
#[ macro_export]
28
- macro_rules! info ( ( $( $arg: tt) * ) => ( log!( 3u32 , $( $arg) * ) ) )
35
+ macro_rules! info(
36
+ ( $( $arg: tt) * ) => ( log!( 3u32 , $( $arg) * ) )
37
+ )
38
+
29
39
#[ macro_export]
30
- macro_rules! debug( ( $ ( $arg : tt ) * ) => (
31
- if cfg!( not( ndebug) ) { log!( 4u32 , $( $arg) * ) }
32
- ) )
40
+ macro_rules! debug(
41
+ ( $ ( $arg : tt ) * ) => ( if cfg!( not( ndebug) ) { log!( 4u32 , $( $arg) * ) } )
42
+ )
33
43
34
44
#[ macro_export]
35
45
macro_rules! log_enabled(
36
- ( $lvl: expr) => ( {
46
+ ( $lvl: expr) => ( {
37
47
let lvl = $lvl;
38
48
lvl <= __log_level( ) && ( lvl != 4 || cfg!( not( ndebug) ) )
39
- } )
49
+ } )
40
50
)
41
51
42
52
#[ macro_export]
@@ -47,54 +57,50 @@ macro_rules! fail(
47
57
( $msg: expr) => (
48
58
:: std:: rt:: begin_unwind( $msg, file!( ) , line!( ) )
49
59
) ;
50
- ( $fmt: expr, $( $arg: tt) * ) => (
51
- {
52
- // a closure can't have return type !, so we need a full
53
- // function to pass to format_args!, *and* we need the
54
- // file and line numbers right here; so an inner bare fn
55
- // is our only choice.
56
- #[ inline]
57
- fn run_fmt( fmt: & :: std:: fmt:: Arguments ) -> ! {
58
- :: std:: rt:: begin_unwind_fmt( fmt, file!( ) , line!( ) )
59
- }
60
- format_args!( run_fmt, $fmt, $( $arg) * )
60
+ ( $fmt: expr, $( $arg: tt) * ) => ( {
61
+ // a closure can't have return type !, so we need a full
62
+ // function to pass to format_args!, *and* we need the
63
+ // file and line numbers right here; so an inner bare fn
64
+ // is our only choice.
65
+ #[ inline]
66
+ fn run_fmt( fmt: & :: std:: fmt:: Arguments ) -> ! {
67
+ :: std:: rt:: begin_unwind_fmt( fmt, file!( ) , line!( ) )
61
68
}
62
- )
69
+ format_args!( run_fmt, $fmt, $( $arg) * )
70
+ } ) ;
63
71
)
64
72
65
73
#[ macro_export]
66
74
macro_rules! assert(
67
- ( $cond: expr) => {
75
+ ( $cond: expr) => (
68
76
if !$cond {
69
77
fail!( "assertion failed: {:s}" , stringify!( $cond) )
70
78
}
71
- } ;
72
- ( $cond: expr, $msg: expr) => {
79
+ ) ;
80
+ ( $cond: expr, $msg: expr) => (
73
81
if !$cond {
74
82
fail!( $msg)
75
83
}
76
- } ;
77
- ( $cond: expr, $( $arg: expr ) ,+) => {
84
+ ) ;
85
+ ( $cond: expr, $( $arg: expr) ,+) => (
78
86
if !$cond {
79
- fail!( $( $arg) ,+ )
87
+ fail!( $( $arg) ,+)
80
88
}
81
- }
89
+ ) ;
82
90
)
83
91
84
92
#[ macro_export]
85
- macro_rules! assert_eq (
86
- ( $given: expr , $expected: expr) => (
87
- {
88
- let given_val = & ( $given) ;
89
- let expected_val = & ( $expected) ;
90
- // check both directions of equality....
91
- if !( ( * given_val == * expected_val) &&
92
- ( * expected_val == * given_val) ) {
93
- fail!( "assertion failed: `(left == right) && (right == left)` \
94
- (left: `{:?}`, right: `{:?}`)", * given_val, * expected_val)
95
- }
93
+ macro_rules! assert_eq(
94
+ ( $given: expr , $expected: expr) => ( {
95
+ let given_val = & ( $given) ;
96
+ let expected_val = & ( $expected) ;
97
+ // check both directions of equality....
98
+ if !( ( * given_val == * expected_val) &&
99
+ ( * expected_val == * given_val) ) {
100
+ fail!( "assertion failed: `(left == right) && (right == left)` \
101
+ (left: `{:?}`, right: `{:?}`)", * given_val, * expected_val)
96
102
}
97
- )
103
+ } )
98
104
)
99
105
100
106
/// A utility macro for indicating unreachable code. It will fail if
@@ -103,7 +109,7 @@ macro_rules! assert_eq (
103
109
///
104
110
/// # Example
105
111
///
106
- /// ``` rust
112
+ /// ~~~ rust
107
113
/// fn choose_weighted_item(v: &[Item]) -> Item {
108
114
/// assert!(!v.is_empty());
109
115
/// let mut so_far = 0u;
@@ -117,44 +123,61 @@ macro_rules! assert_eq (
117
123
/// // type checker that it isn't possible to get down here
118
124
/// unreachable!();
119
125
/// }
120
- /// ```
126
+ /// ~~~
127
+ #[ macro_export]
128
+ macro_rules! unreachable(
129
+ ( ) => ( fail!( "internal error: entered unreachable code" ) )
130
+ )
131
+
132
+ /// A standardised placeholder for marking unfinished code. It fails with the
133
+ /// message `"not yet implemented"` when executed.
121
134
#[ macro_export]
122
- macro_rules! unreachable ( ( ) => (
123
- fail!( "internal error: entered unreachable code" ) ;
124
- ) )
135
+ macro_rules! unimplemented (
136
+ ( ) => ( fail!( "not yet implemented" ) )
137
+ )
125
138
126
139
#[ macro_export]
127
- macro_rules! format( ( $( $arg: tt) * ) => (
128
- format_args!( :: std:: fmt:: format, $( $arg) * )
129
- ) )
140
+ macro_rules! format(
141
+ ( $( $arg: tt) * ) => (
142
+ format_args!( :: std:: fmt:: format, $( $arg) * )
143
+ )
144
+ )
145
+
130
146
#[ macro_export]
131
- macro_rules! write( ( $dst: expr, $( $arg: tt) * ) => (
132
- format_args!( |args| { :: std:: fmt:: write( $dst, args) } , $( $arg) * )
133
- ) )
147
+ macro_rules! write(
148
+ ( $dst: expr, $( $arg: tt) * ) => (
149
+ format_args!( |args| { :: std:: fmt:: write( $dst, args) } , $( $arg) * )
150
+ )
151
+ )
152
+
134
153
#[ macro_export]
135
- macro_rules! writeln( ( $dst: expr, $( $arg: tt) * ) => (
136
- format_args!( |args| { :: std:: fmt:: writeln( $dst, args) } , $( $arg) * )
137
- ) )
154
+ macro_rules! writeln(
155
+ ( $dst: expr, $( $arg: tt) * ) => (
156
+ format_args!( |args| { :: std:: fmt:: writeln( $dst, args) } , $( $arg) * )
157
+ )
158
+ )
159
+
138
160
#[ macro_export]
139
- macro_rules! print (
161
+ macro_rules! print(
140
162
( $( $arg: tt) * ) => ( format_args!( :: std:: io:: stdio:: print_args, $( $arg) * ) )
141
163
)
164
+
142
165
#[ macro_export]
143
- macro_rules! println (
166
+ macro_rules! println(
144
167
( $( $arg: tt) * ) => ( format_args!( :: std:: io:: stdio:: println_args, $( $arg) * ) )
145
168
)
146
169
147
170
#[ macro_export]
148
- macro_rules! local_data_key (
171
+ macro_rules! local_data_key(
149
172
( $name: ident: $ty: ty) => (
150
173
static $name: :: std:: local_data:: Key <$ty> = & :: std:: local_data:: Key ;
151
174
) ;
152
175
( pub $name: ident: $ty: ty) => (
153
176
pub static $name: :: std:: local_data:: Key <$ty> = & :: std:: local_data:: Key ;
154
- )
177
+ ) ;
155
178
)
156
179
157
180
#[ macro_export]
158
- macro_rules! if_ok (
181
+ macro_rules! if_ok(
159
182
( $e: expr) => ( match $e { Ok ( e) => e, Err ( e) => return Err ( e) } )
160
183
)
0 commit comments