36
36
/// panic!("this is a {} {message}", "fancy", message = "message");
37
37
/// ```
38
38
#[ macro_export]
39
+ #[ stable]
39
40
macro_rules! panic {
40
41
( ) => ( {
41
42
panic!( "explicit panic" )
42
43
} ) ;
43
44
( $msg: expr) => ( {
44
- // static requires less code at runtime, more constant data
45
- static _FILE_LINE: ( & ' static str , uint) = ( file!( ) , line!( ) ) ;
46
- :: std:: rt:: begin_unwind( $msg, & _FILE_LINE)
45
+ $crate:: rt:: begin_unwind( $msg, {
46
+ // static requires less code at runtime, more constant data
47
+ static _FILE_LINE: ( & ' static str , uint) = ( file!( ) , line!( ) ) ;
48
+ & _FILE_LINE
49
+ } )
47
50
} ) ;
48
- ( $fmt: expr, $( $arg: tt) * ) => ( {
49
- // The leading _'s are to avoid dead code warnings if this is
50
- // used inside a dead function. Just `#[allow(dead_code)]` is
51
- // insufficient, since the user may have
52
- // `#[forbid(dead_code)]` and which cannot be overridden.
53
- static _FILE_LINE: ( & ' static str , uint) = ( file!( ) , line!( ) ) ;
54
- :: std:: rt:: begin_unwind_fmt( format_args!( $fmt, $( $arg) * ) , & _FILE_LINE)
55
-
51
+ ( $fmt: expr, $( $arg: tt) +) => ( {
52
+ $crate:: rt:: begin_unwind_fmt( format_args!( $fmt, $( $arg) +) , {
53
+ // The leading _'s are to avoid dead code warnings if this is
54
+ // used inside a dead function. Just `#[allow(dead_code)]` is
55
+ // insufficient, since the user may have
56
+ // `#[forbid(dead_code)]` and which cannot be overridden.
57
+ static _FILE_LINE: ( & ' static str , uint) = ( file!( ) , line!( ) ) ;
58
+ & _FILE_LINE
59
+ } )
56
60
} ) ;
57
61
}
58
62
@@ -77,15 +81,16 @@ macro_rules! panic {
77
81
/// assert!(a + b == 30, "a = {}, b = {}", a, b);
78
82
/// ```
79
83
#[ macro_export]
84
+ #[ stable]
80
85
macro_rules! assert {
81
86
( $cond: expr) => (
82
87
if !$cond {
83
88
panic!( concat!( "assertion failed: " , stringify!( $cond) ) )
84
89
}
85
90
) ;
86
- ( $cond: expr, $( $arg: expr ) , +) => (
91
+ ( $cond: expr, $( $arg: tt ) +) => (
87
92
if !$cond {
88
- panic!( $( $arg) , +)
93
+ panic!( $( $arg) +)
89
94
}
90
95
) ;
91
96
}
@@ -103,6 +108,7 @@ macro_rules! assert {
103
108
/// assert_eq!(a, b);
104
109
/// ```
105
110
#[ macro_export]
111
+ #[ stable]
106
112
macro_rules! assert_eq {
107
113
( $left: expr , $right: expr) => ( {
108
114
match ( & ( $left) , & ( $right) ) {
@@ -144,6 +150,7 @@ macro_rules! assert_eq {
144
150
/// debug_assert!(a + b == 30, "a = {}, b = {}", a, b);
145
151
/// ```
146
152
#[ macro_export]
153
+ #[ stable]
147
154
macro_rules! debug_assert {
148
155
( $( $arg: tt) * ) => ( if cfg!( not( ndebug) ) { assert!( $( $arg) * ) ; } )
149
156
}
@@ -210,6 +217,7 @@ macro_rules! debug_assert_eq {
210
217
/// }
211
218
/// ```
212
219
#[ macro_export]
220
+ #[ unstable = "relationship with panic is unclear" ]
213
221
macro_rules! unreachable {
214
222
( ) => ( {
215
223
panic!( "internal error: entered unreachable code" )
@@ -225,6 +233,7 @@ macro_rules! unreachable {
225
233
/// A standardised placeholder for marking unfinished code. It panics with the
226
234
/// message `"not yet implemented"` when executed.
227
235
#[ macro_export]
236
+ #[ unstable = "relationship with panic is unclear" ]
228
237
macro_rules! unimplemented {
229
238
( ) => ( panic!( "not yet implemented" ) )
230
239
}
@@ -242,15 +251,15 @@ macro_rules! unimplemented {
242
251
#[ macro_export]
243
252
#[ stable]
244
253
macro_rules! format {
245
- ( $( $arg: tt) * ) => ( :: std :: fmt:: format( format_args!( $( $arg) * ) ) )
254
+ ( $( $arg: tt) * ) => ( $crate :: fmt:: format( format_args!( $( $arg) * ) ) )
246
255
}
247
256
248
257
/// Equivalent to the `println!` macro except that a newline is not printed at
249
258
/// the end of the message.
250
259
#[ macro_export]
251
260
#[ stable]
252
261
macro_rules! print {
253
- ( $( $arg: tt) * ) => ( :: std :: io:: stdio:: print_args( format_args!( $( $arg) * ) ) )
262
+ ( $( $arg: tt) * ) => ( $crate :: io:: stdio:: print_args( format_args!( $( $arg) * ) ) )
254
263
}
255
264
256
265
/// Macro for printing to a task's stdout handle.
@@ -268,20 +277,19 @@ macro_rules! print {
268
277
#[ macro_export]
269
278
#[ stable]
270
279
macro_rules! println {
271
- ( $( $arg: tt) * ) => ( :: std :: io:: stdio:: println_args( format_args!( $( $arg) * ) ) )
280
+ ( $( $arg: tt) * ) => ( $crate :: io:: stdio:: println_args( format_args!( $( $arg) * ) ) )
272
281
}
273
282
274
283
/// Helper macro for unwrapping `Result` values while returning early with an
275
284
/// error if the value of the expression is `Err`. For more information, see
276
285
/// `std::io`.
277
286
#[ macro_export]
287
+ #[ stable]
278
288
macro_rules! try {
279
- ( $expr: expr) => ( {
280
- use $crate:: result:: Result :: { Ok , Err } ;
281
-
282
- match $expr {
283
- Ok ( val) => val,
284
- Err ( err) => return Err ( $crate:: error:: FromError :: from_error( err) ) ,
289
+ ( $expr: expr) => ( match $expr {
290
+ $crate:: result:: Result :: Ok ( val) => val,
291
+ $crate:: result:: Result :: Err ( err) => {
292
+ return $crate:: result:: Result :: Err ( $crate:: error:: FromError :: from_error( err) )
285
293
}
286
294
} )
287
295
}
@@ -412,26 +420,6 @@ pub mod builtin {
412
420
#[ macro_export]
413
421
macro_rules! option_env { ( $name: expr) => ( { /* compiler built-in */ } ) }
414
422
415
- /// Concatenate literals into a static byte slice.
416
- ///
417
- /// This macro takes any number of comma-separated literal expressions,
418
- /// yielding an expression of type `&'static [u8]` which is the
419
- /// concatenation (left to right) of all the literals in their byte format.
420
- ///
421
- /// This extension currently only supports string literals, character
422
- /// literals, and integers less than 256. The byte slice returned is the
423
- /// utf8-encoding of strings and characters.
424
- ///
425
- /// # Example
426
- ///
427
- /// ```
428
- /// let rust = bytes!("r", 'u', "st", 255);
429
- /// assert_eq!(rust[1], b'u');
430
- /// assert_eq!(rust[4], 255);
431
- /// ```
432
- #[ macro_export]
433
- macro_rules! bytes { ( $( $e: expr) ,* ) => ( { /* compiler built-in */ } ) }
434
-
435
423
/// Concatenate identifiers into one identifier.
436
424
///
437
425
/// This macro takes any number of comma-separated identifiers, and
@@ -565,10 +553,6 @@ pub mod builtin {
565
553
#[ macro_export]
566
554
macro_rules! include_bytes { ( $file: expr) => ( { /* compiler built-in */ } ) }
567
555
568
- /// Deprecated alias for `include_bytes!()`.
569
- #[ macro_export]
570
- macro_rules! include_bin { ( $file: expr) => ( { /* compiler built-in */ } ) }
571
-
572
556
/// Expands to a string that represents the current module path.
573
557
///
574
558
/// The current module path can be thought of as the hierarchy of modules
0 commit comments