]> git.lizzy.rs Git - rust.git/blob - src/libcore/macros/mod.rs
Auto merge of #69576 - matthiaskrgr:nightly_bootstrap_from_beta, r=Centril
[rust.git] / src / libcore / macros / mod.rs
1 #[doc(include = "panic.md")]
2 #[macro_export]
3 #[allow_internal_unstable(core_panic, track_caller)]
4 #[stable(feature = "core", since = "1.6.0")]
5 macro_rules! panic {
6     () => (
7         $crate::panic!("explicit panic")
8     );
9     ($msg:expr) => (
10         $crate::panicking::panic($msg)
11     );
12     ($msg:expr,) => (
13         $crate::panic!($msg)
14     );
15     ($fmt:expr, $($arg:tt)+) => (
16         $crate::panicking::panic_fmt(
17             $crate::format_args!($fmt, $($arg)+),
18             $crate::panic::Location::caller(),
19         )
20     );
21 }
22
23 /// Asserts that two expressions are equal to each other (using [`PartialEq`]).
24 ///
25 /// On panic, this macro will print the values of the expressions with their
26 /// debug representations.
27 ///
28 /// Like [`assert!`], this macro has a second form, where a custom
29 /// panic message can be provided.
30 ///
31 /// [`PartialEq`]: cmp/trait.PartialEq.html
32 /// [`assert!`]: macro.assert.html
33 ///
34 /// # Examples
35 ///
36 /// ```
37 /// let a = 3;
38 /// let b = 1 + 2;
39 /// assert_eq!(a, b);
40 ///
41 /// assert_eq!(a, b, "we are testing addition with {} and {}", a, b);
42 /// ```
43 #[macro_export]
44 #[stable(feature = "rust1", since = "1.0.0")]
45 macro_rules! assert_eq {
46     ($left:expr, $right:expr) => ({
47         match (&$left, &$right) {
48             (left_val, right_val) => {
49                 if !(*left_val == *right_val) {
50                     // The reborrows below are intentional. Without them, the stack slot for the
51                     // borrow is initialized even before the values are compared, leading to a
52                     // noticeable slow down.
53                     panic!(r#"assertion failed: `(left == right)`
54   left: `{:?}`,
55  right: `{:?}`"#, &*left_val, &*right_val)
56                 }
57             }
58         }
59     });
60     ($left:expr, $right:expr,) => ({
61         $crate::assert_eq!($left, $right)
62     });
63     ($left:expr, $right:expr, $($arg:tt)+) => ({
64         match (&($left), &($right)) {
65             (left_val, right_val) => {
66                 if !(*left_val == *right_val) {
67                     // The reborrows below are intentional. Without them, the stack slot for the
68                     // borrow is initialized even before the values are compared, leading to a
69                     // noticeable slow down.
70                     panic!(r#"assertion failed: `(left == right)`
71   left: `{:?}`,
72  right: `{:?}`: {}"#, &*left_val, &*right_val,
73                            $crate::format_args!($($arg)+))
74                 }
75             }
76         }
77     });
78 }
79
80 /// Asserts that two expressions are not equal to each other (using [`PartialEq`]).
81 ///
82 /// On panic, this macro will print the values of the expressions with their
83 /// debug representations.
84 ///
85 /// Like [`assert!`], this macro has a second form, where a custom
86 /// panic message can be provided.
87 ///
88 /// [`PartialEq`]: cmp/trait.PartialEq.html
89 /// [`assert!`]: macro.assert.html
90 ///
91 /// # Examples
92 ///
93 /// ```
94 /// let a = 3;
95 /// let b = 2;
96 /// assert_ne!(a, b);
97 ///
98 /// assert_ne!(a, b, "we are testing that the values are not equal");
99 /// ```
100 #[macro_export]
101 #[stable(feature = "assert_ne", since = "1.13.0")]
102 macro_rules! assert_ne {
103     ($left:expr, $right:expr) => ({
104         match (&$left, &$right) {
105             (left_val, right_val) => {
106                 if *left_val == *right_val {
107                     // The reborrows below are intentional. Without them, the stack slot for the
108                     // borrow is initialized even before the values are compared, leading to a
109                     // noticeable slow down.
110                     panic!(r#"assertion failed: `(left != right)`
111   left: `{:?}`,
112  right: `{:?}`"#, &*left_val, &*right_val)
113                 }
114             }
115         }
116     });
117     ($left:expr, $right:expr,) => {
118         $crate::assert_ne!($left, $right)
119     };
120     ($left:expr, $right:expr, $($arg:tt)+) => ({
121         match (&($left), &($right)) {
122             (left_val, right_val) => {
123                 if *left_val == *right_val {
124                     // The reborrows below are intentional. Without them, the stack slot for the
125                     // borrow is initialized even before the values are compared, leading to a
126                     // noticeable slow down.
127                     panic!(r#"assertion failed: `(left != right)`
128   left: `{:?}`,
129  right: `{:?}`: {}"#, &*left_val, &*right_val,
130                            $crate::format_args!($($arg)+))
131                 }
132             }
133         }
134     });
135 }
136
137 /// Asserts that a boolean expression is `true` at runtime.
138 ///
139 /// This will invoke the [`panic!`] macro if the provided expression cannot be
140 /// evaluated to `true` at runtime.
141 ///
142 /// Like [`assert!`], this macro also has a second version, where a custom panic
143 /// message can be provided.
144 ///
145 /// # Uses
146 ///
147 /// Unlike [`assert!`], `debug_assert!` statements are only enabled in non
148 /// optimized builds by default. An optimized build will not execute
149 /// `debug_assert!` statements unless `-C debug-assertions` is passed to the
150 /// compiler. This makes `debug_assert!` useful for checks that are too
151 /// expensive to be present in a release build but may be helpful during
152 /// development. The result of expanding `debug_assert!` is always type checked.
153 ///
154 /// An unchecked assertion allows a program in an inconsistent state to keep
155 /// running, which might have unexpected consequences but does not introduce
156 /// unsafety as long as this only happens in safe code. The performance cost
157 /// of assertions, is however, not measurable in general. Replacing [`assert!`]
158 /// with `debug_assert!` is thus only encouraged after thorough profiling, and
159 /// more importantly, only in safe code!
160 ///
161 /// [`panic!`]: macro.panic.html
162 /// [`assert!`]: macro.assert.html
163 ///
164 /// # Examples
165 ///
166 /// ```
167 /// // the panic message for these assertions is the stringified value of the
168 /// // expression given.
169 /// debug_assert!(true);
170 ///
171 /// fn some_expensive_computation() -> bool { true } // a very simple function
172 /// debug_assert!(some_expensive_computation());
173 ///
174 /// // assert with a custom message
175 /// let x = true;
176 /// debug_assert!(x, "x wasn't true!");
177 ///
178 /// let a = 3; let b = 27;
179 /// debug_assert!(a + b == 30, "a = {}, b = {}", a, b);
180 /// ```
181 #[macro_export]
182 #[stable(feature = "rust1", since = "1.0.0")]
183 macro_rules! debug_assert {
184     ($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert!($($arg)*); })
185 }
186
187 /// Asserts that two expressions are equal to each other.
188 ///
189 /// On panic, this macro will print the values of the expressions with their
190 /// debug representations.
191 ///
192 /// Unlike [`assert_eq!`], `debug_assert_eq!` statements are only enabled in non
193 /// optimized builds by default. An optimized build will not execute
194 /// `debug_assert_eq!` statements unless `-C debug-assertions` is passed to the
195 /// compiler. This makes `debug_assert_eq!` useful for checks that are too
196 /// expensive to be present in a release build but may be helpful during
197 /// development. The result of expanding `debug_assert_eq!` is always type checked.
198 ///
199 /// [`assert_eq!`]: ../std/macro.assert_eq.html
200 ///
201 /// # Examples
202 ///
203 /// ```
204 /// let a = 3;
205 /// let b = 1 + 2;
206 /// debug_assert_eq!(a, b);
207 /// ```
208 #[macro_export]
209 #[stable(feature = "rust1", since = "1.0.0")]
210 macro_rules! debug_assert_eq {
211     ($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert_eq!($($arg)*); })
212 }
213
214 /// Asserts that two expressions are not equal to each other.
215 ///
216 /// On panic, this macro will print the values of the expressions with their
217 /// debug representations.
218 ///
219 /// Unlike [`assert_ne!`], `debug_assert_ne!` statements are only enabled in non
220 /// optimized builds by default. An optimized build will not execute
221 /// `debug_assert_ne!` statements unless `-C debug-assertions` is passed to the
222 /// compiler. This makes `debug_assert_ne!` useful for checks that are too
223 /// expensive to be present in a release build but may be helpful during
224 /// development. The result of expanding `debug_assert_ne!` is always type checked.
225 ///
226 /// [`assert_ne!`]: ../std/macro.assert_ne.html
227 ///
228 /// # Examples
229 ///
230 /// ```
231 /// let a = 3;
232 /// let b = 2;
233 /// debug_assert_ne!(a, b);
234 /// ```
235 #[macro_export]
236 #[stable(feature = "assert_ne", since = "1.13.0")]
237 macro_rules! debug_assert_ne {
238     ($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert_ne!($($arg)*); })
239 }
240
241 /// Returns whether the given expression matches any of the given patterns.
242 ///
243 /// Like in a `match` expression, the pattern can be optionally followed by `if`
244 /// and a guard expression that has access to names bound by the pattern.
245 ///
246 /// # Examples
247 ///
248 /// ```
249 /// let foo = 'f';
250 /// assert!(matches!(foo, 'A'..='Z' | 'a'..='z'));
251 ///
252 /// let bar = Some(4);
253 /// assert!(matches!(bar, Some(x) if x > 2));
254 /// ```
255 #[macro_export]
256 #[stable(feature = "matches_macro", since = "1.42.0")]
257 macro_rules! matches {
258     ($expression:expr, $( $pattern:pat )|+ $( if $guard: expr )?) => {
259         match $expression {
260             $( $pattern )|+ $( if $guard )? => true,
261             _ => false
262         }
263     }
264 }
265
266 /// Unwraps a result or propagates its error.
267 ///
268 /// The `?` operator was added to replace `try!` and should be used instead.
269 /// Furthermore, `try` is a reserved word in Rust 2018, so if you must use
270 /// it, you will need to use the [raw-identifier syntax][ris]: `r#try`.
271 ///
272 /// [ris]: https://doc.rust-lang.org/nightly/rust-by-example/compatibility/raw_identifiers.html
273 ///
274 /// `try!` matches the given [`Result`]. In case of the `Ok` variant, the
275 /// expression has the value of the wrapped value.
276 ///
277 /// In case of the `Err` variant, it retrieves the inner error. `try!` then
278 /// performs conversion using `From`. This provides automatic conversion
279 /// between specialized errors and more general ones. The resulting
280 /// error is then immediately returned.
281 ///
282 /// Because of the early return, `try!` can only be used in functions that
283 /// return [`Result`].
284 ///
285 /// [`Result`]: ../std/result/enum.Result.html
286 ///
287 /// # Examples
288 ///
289 /// ```
290 /// use std::io;
291 /// use std::fs::File;
292 /// use std::io::prelude::*;
293 ///
294 /// enum MyError {
295 ///     FileWriteError
296 /// }
297 ///
298 /// impl From<io::Error> for MyError {
299 ///     fn from(e: io::Error) -> MyError {
300 ///         MyError::FileWriteError
301 ///     }
302 /// }
303 ///
304 /// // The preferred method of quick returning Errors
305 /// fn write_to_file_question() -> Result<(), MyError> {
306 ///     let mut file = File::create("my_best_friends.txt")?;
307 ///     file.write_all(b"This is a list of my best friends.")?;
308 ///     Ok(())
309 /// }
310 ///
311 /// // The previous method of quick returning Errors
312 /// fn write_to_file_using_try() -> Result<(), MyError> {
313 ///     let mut file = r#try!(File::create("my_best_friends.txt"));
314 ///     r#try!(file.write_all(b"This is a list of my best friends."));
315 ///     Ok(())
316 /// }
317 ///
318 /// // This is equivalent to:
319 /// fn write_to_file_using_match() -> Result<(), MyError> {
320 ///     let mut file = r#try!(File::create("my_best_friends.txt"));
321 ///     match file.write_all(b"This is a list of my best friends.") {
322 ///         Ok(v) => v,
323 ///         Err(e) => return Err(From::from(e)),
324 ///     }
325 ///     Ok(())
326 /// }
327 /// ```
328 #[macro_export]
329 #[stable(feature = "rust1", since = "1.0.0")]
330 #[rustc_deprecated(since = "1.39.0", reason = "use the `?` operator instead")]
331 #[doc(alias = "?")]
332 macro_rules! r#try {
333     ($expr:expr) => {
334         match $expr {
335             $crate::result::Result::Ok(val) => val,
336             $crate::result::Result::Err(err) => {
337                 return $crate::result::Result::Err($crate::convert::From::from(err));
338             }
339         }
340     };
341     ($expr:expr,) => {
342         $crate::r#try!($expr)
343     };
344 }
345
346 /// Writes formatted data into a buffer.
347 ///
348 /// This macro accepts a format string, a list of arguments, and a 'writer'. Arguments will be
349 /// formatted according to the specified format string and the result will be passed to the writer.
350 /// The writer may be any value with a `write_fmt` method; generally this comes from an
351 /// implementation of either the [`std::fmt::Write`] or the [`std::io::Write`] trait. The macro
352 /// returns whatever the `write_fmt` method returns; commonly a [`std::fmt::Result`], or an
353 /// [`io::Result`].
354 ///
355 /// See [`std::fmt`] for more information on the format string syntax.
356 ///
357 /// [`std::fmt`]: ../std/fmt/index.html
358 /// [`std::fmt::Write`]: ../std/fmt/trait.Write.html
359 /// [`std::io::Write`]: ../std/io/trait.Write.html
360 /// [`std::fmt::Result`]: ../std/fmt/type.Result.html
361 /// [`io::Result`]: ../std/io/type.Result.html
362 ///
363 /// # Examples
364 ///
365 /// ```
366 /// use std::io::Write;
367 ///
368 /// fn main() -> std::io::Result<()> {
369 ///     let mut w = Vec::new();
370 ///     write!(&mut w, "test")?;
371 ///     write!(&mut w, "formatted {}", "arguments")?;
372 ///
373 ///     assert_eq!(w, b"testformatted arguments");
374 ///     Ok(())
375 /// }
376 /// ```
377 ///
378 /// A module can import both `std::fmt::Write` and `std::io::Write` and call `write!` on objects
379 /// implementing either, as objects do not typically implement both. However, the module must
380 /// import the traits qualified so their names do not conflict:
381 ///
382 /// ```
383 /// use std::fmt::Write as FmtWrite;
384 /// use std::io::Write as IoWrite;
385 ///
386 /// fn main() -> Result<(), Box<dyn std::error::Error>> {
387 ///     let mut s = String::new();
388 ///     let mut v = Vec::new();
389 ///
390 ///     write!(&mut s, "{} {}", "abc", 123)?; // uses fmt::Write::write_fmt
391 ///     write!(&mut v, "s = {:?}", s)?; // uses io::Write::write_fmt
392 ///     assert_eq!(v, b"s = \"abc 123\"");
393 ///     Ok(())
394 /// }
395 /// ```
396 ///
397 /// Note: This macro can be used in `no_std` setups as well.
398 /// In a `no_std` setup you are responsible for the implementation details of the components.
399 ///
400 /// ```no_run
401 /// # extern crate core;
402 /// use core::fmt::Write;
403 ///
404 /// struct Example;
405 ///
406 /// impl Write for Example {
407 ///     fn write_str(&mut self, _s: &str) -> core::fmt::Result {
408 ///          unimplemented!();
409 ///     }
410 /// }
411 ///
412 /// let mut m = Example{};
413 /// write!(&mut m, "Hello World").expect("Not written");
414 /// ```
415 #[macro_export]
416 #[stable(feature = "rust1", since = "1.0.0")]
417 macro_rules! write {
418     ($dst:expr, $($arg:tt)*) => ($dst.write_fmt($crate::format_args!($($arg)*)))
419 }
420
421 /// Write formatted data into a buffer, with a newline appended.
422 ///
423 /// On all platforms, the newline is the LINE FEED character (`\n`/`U+000A`) alone
424 /// (no additional CARRIAGE RETURN (`\r`/`U+000D`).
425 ///
426 /// For more information, see [`write!`]. For information on the format string syntax, see
427 /// [`std::fmt`].
428 ///
429 /// [`write!`]: macro.write.html
430 /// [`std::fmt`]: ../std/fmt/index.html
431 ///
432 ///
433 /// # Examples
434 ///
435 /// ```
436 /// use std::io::{Write, Result};
437 ///
438 /// fn main() -> Result<()> {
439 ///     let mut w = Vec::new();
440 ///     writeln!(&mut w)?;
441 ///     writeln!(&mut w, "test")?;
442 ///     writeln!(&mut w, "formatted {}", "arguments")?;
443 ///
444 ///     assert_eq!(&w[..], "\ntest\nformatted arguments\n".as_bytes());
445 ///     Ok(())
446 /// }
447 /// ```
448 ///
449 /// A module can import both `std::fmt::Write` and `std::io::Write` and call `write!` on objects
450 /// implementing either, as objects do not typically implement both. However, the module must
451 /// import the traits qualified so their names do not conflict:
452 ///
453 /// ```
454 /// use std::fmt::Write as FmtWrite;
455 /// use std::io::Write as IoWrite;
456 ///
457 /// fn main() -> Result<(), Box<dyn std::error::Error>> {
458 ///     let mut s = String::new();
459 ///     let mut v = Vec::new();
460 ///
461 ///     writeln!(&mut s, "{} {}", "abc", 123)?; // uses fmt::Write::write_fmt
462 ///     writeln!(&mut v, "s = {:?}", s)?; // uses io::Write::write_fmt
463 ///     assert_eq!(v, b"s = \"abc 123\\n\"\n");
464 ///     Ok(())
465 /// }
466 /// ```
467 #[macro_export]
468 #[stable(feature = "rust1", since = "1.0.0")]
469 #[allow_internal_unstable(format_args_nl)]
470 macro_rules! writeln {
471     ($dst:expr) => (
472         $crate::write!($dst, "\n")
473     );
474     ($dst:expr,) => (
475         $crate::writeln!($dst)
476     );
477     ($dst:expr, $($arg:tt)*) => (
478         $dst.write_fmt($crate::format_args_nl!($($arg)*))
479     );
480 }
481
482 /// Indicates unreachable code.
483 ///
484 /// This is useful any time that the compiler can't determine that some code is unreachable. For
485 /// example:
486 ///
487 /// * Match arms with guard conditions.
488 /// * Loops that dynamically terminate.
489 /// * Iterators that dynamically terminate.
490 ///
491 /// If the determination that the code is unreachable proves incorrect, the
492 /// program immediately terminates with a [`panic!`].
493 ///
494 /// The unsafe counterpart of this macro is the [`unreachable_unchecked`] function, which
495 /// will cause undefined behavior if the code is reached.
496 ///
497 /// [`panic!`]: ../std/macro.panic.html
498 /// [`unreachable_unchecked`]: ../std/hint/fn.unreachable_unchecked.html
499 /// [`std::hint`]: ../std/hint/index.html
500 ///
501 /// # Panics
502 ///
503 /// This will always [`panic!`]
504 ///
505 /// [`panic!`]: ../std/macro.panic.html
506 ///
507 /// # Examples
508 ///
509 /// Match arms:
510 ///
511 /// ```
512 /// # #[allow(dead_code)]
513 /// fn foo(x: Option<i32>) {
514 ///     match x {
515 ///         Some(n) if n >= 0 => println!("Some(Non-negative)"),
516 ///         Some(n) if n <  0 => println!("Some(Negative)"),
517 ///         Some(_)           => unreachable!(), // compile error if commented out
518 ///         None              => println!("None")
519 ///     }
520 /// }
521 /// ```
522 ///
523 /// Iterators:
524 ///
525 /// ```
526 /// # #[allow(dead_code)]
527 /// fn divide_by_three(x: u32) -> u32 { // one of the poorest implementations of x/3
528 ///     for i in 0.. {
529 ///         if 3*i < i { panic!("u32 overflow"); }
530 ///         if x < 3*i { return i-1; }
531 ///     }
532 ///     unreachable!();
533 /// }
534 /// ```
535 #[macro_export]
536 #[stable(feature = "rust1", since = "1.0.0")]
537 macro_rules! unreachable {
538     () => ({
539         panic!("internal error: entered unreachable code")
540     });
541     ($msg:expr) => ({
542         $crate::unreachable!("{}", $msg)
543     });
544     ($msg:expr,) => ({
545         $crate::unreachable!($msg)
546     });
547     ($fmt:expr, $($arg:tt)*) => ({
548         panic!($crate::concat!("internal error: entered unreachable code: ", $fmt), $($arg)*)
549     });
550 }
551
552 /// Indicates unimplemented code by panicking with a message of "not implemented".
553 ///
554 /// This allows your code to type-check, which is useful if you are prototyping or
555 /// implementing a trait that requires multiple methods which you don't plan of using all of.
556 ///
557 /// The difference between `unimplemented!` and [`todo!`](macro.todo.html) is that while `todo!`
558 /// conveys an intent of implementing the functionality later and the message is "not yet
559 /// implemented", `unimplemented!` makes no such claims. Its message is "not implemented".
560 /// Also some IDEs will mark `todo!`s.
561 ///
562 /// # Panics
563 ///
564 /// This will always [panic!](macro.panic.html) because `unimplemented!` is just a
565 /// shorthand for `panic!` with a fixed, specific message.
566 ///
567 /// Like `panic!`, this macro has a second form for displaying custom values.
568 ///
569 /// # Examples
570 ///
571 /// Say we have a trait `Foo`:
572 ///
573 /// ```
574 /// trait Foo {
575 ///     fn bar(&self) -> u8;
576 ///     fn baz(&self);
577 ///     fn qux(&self) -> Result<u64, ()>;
578 /// }
579 /// ```
580 ///
581 /// We want to implement `Foo` for 'MyStruct', but for some reason it only makes sense
582 /// to implement the `bar()` function. `baz()` and `qux()` will still need to be defined
583 /// in our implementation of `Foo`, but we can use `unimplemented!` in their definitions
584 /// to allow our code to compile.
585 ///
586 /// We still want to have our program stop running if the unimplemented methods are
587 /// reached.
588 ///
589 /// ```
590 /// # trait Foo {
591 /// #     fn bar(&self) -> u8;
592 /// #     fn baz(&self);
593 /// #     fn qux(&self) -> Result<u64, ()>;
594 /// # }
595 /// struct MyStruct;
596 ///
597 /// impl Foo for MyStruct {
598 ///     fn bar(&self) -> u8 {
599 ///         1 + 1
600 ///     }
601 ///
602 ///     fn baz(&self) {
603 ///         // It makes no sense to `baz` a `MyStruct`, so we have no logic here
604 ///         // at all.
605 ///         // This will display "thread 'main' panicked at 'not implemented'".
606 ///         unimplemented!();
607 ///     }
608 ///
609 ///     fn qux(&self) -> Result<u64, ()> {
610 ///         // We have some logic here,
611 ///         // We can add a message to unimplemented! to display our omission.
612 ///         // This will display:
613 ///         // "thread 'main' panicked at 'not implemented: MyStruct isn't quxable'".
614 ///         unimplemented!("MyStruct isn't quxable");
615 ///     }
616 /// }
617 ///
618 /// fn main() {
619 ///     let s = MyStruct;
620 ///     s.bar();
621 /// }
622 /// ```
623 #[macro_export]
624 #[stable(feature = "rust1", since = "1.0.0")]
625 macro_rules! unimplemented {
626     () => (panic!("not implemented"));
627     ($($arg:tt)+) => (panic!("not implemented: {}", $crate::format_args!($($arg)+)));
628 }
629
630 /// Indicates unfinished code.
631 ///
632 /// This can be useful if you are prototyping and are just looking to have your
633 /// code typecheck.
634 ///
635 /// The difference between [`unimplemented!`] and `todo!` is that while `todo!` conveys
636 /// an intent of implementing the functionality later and the message is "not yet
637 /// implemented", `unimplemented!` makes no such claims. Its message is "not implemented".
638 /// Also some IDEs will mark `todo!`s.
639 ///
640 /// [`unimplemented!`]: macro.unimplemented.html
641 ///
642 /// # Panics
643 ///
644 /// This will always [panic!](macro.panic.html)
645 ///
646 /// # Examples
647 ///
648 /// Here's an example of some in-progress code. We have a trait `Foo`:
649 ///
650 /// ```
651 /// trait Foo {
652 ///     fn bar(&self);
653 ///     fn baz(&self);
654 /// }
655 /// ```
656 ///
657 /// We want to implement `Foo` on one of our types, but we also want to work on
658 /// just `bar()` first. In order for our code to compile, we need to implement
659 /// `baz()`, so we can use `todo!`:
660 ///
661 /// ```
662 /// # trait Foo {
663 /// #     fn bar(&self);
664 /// #     fn baz(&self);
665 /// # }
666 /// struct MyStruct;
667 ///
668 /// impl Foo for MyStruct {
669 ///     fn bar(&self) {
670 ///         // implementation goes here
671 ///     }
672 ///
673 ///     fn baz(&self) {
674 ///         // let's not worry about implementing baz() for now
675 ///         todo!();
676 ///     }
677 /// }
678 ///
679 /// fn main() {
680 ///     let s = MyStruct;
681 ///     s.bar();
682 ///
683 ///     // we aren't even using baz(), so this is fine.
684 /// }
685 /// ```
686 #[macro_export]
687 #[stable(feature = "todo_macro", since = "1.40.0")]
688 macro_rules! todo {
689     () => (panic!("not yet implemented"));
690     ($($arg:tt)+) => (panic!("not yet implemented: {}", $crate::format_args!($($arg)+)));
691 }
692
693 /// Definitions of built-in macros.
694 ///
695 /// Most of the macro properties (stability, visibility, etc.) are taken from the source code here,
696 /// with exception of expansion functions transforming macro inputs into outputs,
697 /// those functions are provided by the compiler.
698 pub(crate) mod builtin {
699
700     /// Causes compilation to fail with the given error message when encountered.
701     ///
702     /// This macro should be used when a crate uses a conditional compilation strategy to provide
703     /// better error messages for erroneous conditions. It's the compiler-level form of [`panic!`],
704     /// but emits an error during *compilation* rather than at *runtime*.
705     ///
706     /// # Examples
707     ///
708     /// Two such examples are macros and `#[cfg]` environments.
709     ///
710     /// Emit better compiler error if a macro is passed invalid values. Without the final branch,
711     /// the compiler would still emit an error, but the error's message would not mention the two
712     /// valid values.
713     ///
714     /// ```compile_fail
715     /// macro_rules! give_me_foo_or_bar {
716     ///     (foo) => {};
717     ///     (bar) => {};
718     ///     ($x:ident) => {
719     ///         compile_error!("This macro only accepts `foo` or `bar`");
720     ///     }
721     /// }
722     ///
723     /// give_me_foo_or_bar!(neither);
724     /// // ^ will fail at compile time with message "This macro only accepts `foo` or `bar`"
725     /// ```
726     ///
727     /// Emit compiler error if one of a number of features isn't available.
728     ///
729     /// ```compile_fail
730     /// #[cfg(not(any(feature = "foo", feature = "bar")))]
731     /// compile_error!("Either feature \"foo\" or \"bar\" must be enabled for this crate.");
732     /// ```
733     ///
734     /// [`panic!`]: ../std/macro.panic.html
735     #[stable(feature = "compile_error_macro", since = "1.20.0")]
736     #[rustc_builtin_macro]
737     #[macro_export]
738     macro_rules! compile_error {
739         ($msg:expr) => {{ /* compiler built-in */ }};
740         ($msg:expr,) => {{ /* compiler built-in */ }};
741     }
742
743     /// Constructs parameters for the other string-formatting macros.
744     ///
745     /// This macro functions by taking a formatting string literal containing
746     /// `{}` for each additional argument passed. `format_args!` prepares the
747     /// additional parameters to ensure the output can be interpreted as a string
748     /// and canonicalizes the arguments into a single type. Any value that implements
749     /// the [`Display`] trait can be passed to `format_args!`, as can any
750     /// [`Debug`] implementation be passed to a `{:?}` within the formatting string.
751     ///
752     /// This macro produces a value of type [`fmt::Arguments`]. This value can be
753     /// passed to the macros within [`std::fmt`] for performing useful redirection.
754     /// All other formatting macros ([`format!`], [`write!`], [`println!`], etc) are
755     /// proxied through this one. `format_args!`, unlike its derived macros, avoids
756     /// heap allocations.
757     ///
758     /// You can use the [`fmt::Arguments`] value that `format_args!` returns
759     /// in `Debug` and `Display` contexts as seen below. The example also shows
760     /// that `Debug` and `Display` format to the same thing: the interpolated
761     /// format string in `format_args!`.
762     ///
763     /// ```rust
764     /// let debug = format!("{:?}", format_args!("{} foo {:?}", 1, 2));
765     /// let display = format!("{}", format_args!("{} foo {:?}", 1, 2));
766     /// assert_eq!("1 foo 2", display);
767     /// assert_eq!(display, debug);
768     /// ```
769     ///
770     /// For more information, see the documentation in [`std::fmt`].
771     ///
772     /// [`Display`]: ../std/fmt/trait.Display.html
773     /// [`Debug`]: ../std/fmt/trait.Debug.html
774     /// [`fmt::Arguments`]: ../std/fmt/struct.Arguments.html
775     /// [`std::fmt`]: ../std/fmt/index.html
776     /// [`format!`]: ../std/macro.format.html
777     /// [`write!`]: ../std/macro.write.html
778     /// [`println!`]: ../std/macro.println.html
779     ///
780     /// # Examples
781     ///
782     /// ```
783     /// use std::fmt;
784     ///
785     /// let s = fmt::format(format_args!("hello {}", "world"));
786     /// assert_eq!(s, format!("hello {}", "world"));
787     /// ```
788     #[stable(feature = "rust1", since = "1.0.0")]
789     #[allow_internal_unstable(fmt_internals)]
790     #[rustc_builtin_macro]
791     #[macro_export]
792     macro_rules! format_args {
793         ($fmt:expr) => {{ /* compiler built-in */ }};
794         ($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
795     }
796
797     /// Same as `format_args`, but adds a newline in the end.
798     #[unstable(
799         feature = "format_args_nl",
800         issue = "none",
801         reason = "`format_args_nl` is only for internal \
802                   language use and is subject to change"
803     )]
804     #[allow_internal_unstable(fmt_internals)]
805     #[rustc_builtin_macro]
806     #[macro_export]
807     macro_rules! format_args_nl {
808         ($fmt:expr) => {{ /* compiler built-in */ }};
809         ($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
810     }
811
812     /// Inspects an environment variable at compile time.
813     ///
814     /// This macro will expand to the value of the named environment variable at
815     /// compile time, yielding an expression of type `&'static str`.
816     ///
817     /// If the environment variable is not defined, then a compilation error
818     /// will be emitted. To not emit a compile error, use the [`option_env!`]
819     /// macro instead.
820     ///
821     /// [`option_env!`]: ../std/macro.option_env.html
822     ///
823     /// # Examples
824     ///
825     /// ```
826     /// let path: &'static str = env!("PATH");
827     /// println!("the $PATH variable at the time of compiling was: {}", path);
828     /// ```
829     ///
830     /// You can customize the error message by passing a string as the second
831     /// parameter:
832     ///
833     /// ```compile_fail
834     /// let doc: &'static str = env!("documentation", "what's that?!");
835     /// ```
836     ///
837     /// If the `documentation` environment variable is not defined, you'll get
838     /// the following error:
839     ///
840     /// ```text
841     /// error: what's that?!
842     /// ```
843     #[stable(feature = "rust1", since = "1.0.0")]
844     #[rustc_builtin_macro]
845     #[macro_export]
846     macro_rules! env {
847         ($name:expr) => {{ /* compiler built-in */ }};
848         ($name:expr,) => {{ /* compiler built-in */ }};
849     }
850
851     /// Optionally inspects an environment variable at compile time.
852     ///
853     /// If the named environment variable is present at compile time, this will
854     /// expand into an expression of type `Option<&'static str>` whose value is
855     /// `Some` of the value of the environment variable. If the environment
856     /// variable is not present, then this will expand to `None`. See
857     /// [`Option<T>`][option] for more information on this type.
858     ///
859     /// A compile time error is never emitted when using this macro regardless
860     /// of whether the environment variable is present or not.
861     ///
862     /// [option]: ../std/option/enum.Option.html
863     ///
864     /// # Examples
865     ///
866     /// ```
867     /// let key: Option<&'static str> = option_env!("SECRET_KEY");
868     /// println!("the secret key might be: {:?}", key);
869     /// ```
870     #[stable(feature = "rust1", since = "1.0.0")]
871     #[rustc_builtin_macro]
872     #[macro_export]
873     macro_rules! option_env {
874         ($name:expr) => {{ /* compiler built-in */ }};
875         ($name:expr,) => {{ /* compiler built-in */ }};
876     }
877
878     /// Concatenates identifiers into one identifier.
879     ///
880     /// This macro takes any number of comma-separated identifiers, and
881     /// concatenates them all into one, yielding an expression which is a new
882     /// identifier. Note that hygiene makes it such that this macro cannot
883     /// capture local variables. Also, as a general rule, macros are only
884     /// allowed in item, statement or expression position. That means while
885     /// you may use this macro for referring to existing variables, functions or
886     /// modules etc, you cannot define a new one with it.
887     ///
888     /// # Examples
889     ///
890     /// ```
891     /// #![feature(concat_idents)]
892     ///
893     /// # fn main() {
894     /// fn foobar() -> u32 { 23 }
895     ///
896     /// let f = concat_idents!(foo, bar);
897     /// println!("{}", f());
898     ///
899     /// // fn concat_idents!(new, fun, name) { } // not usable in this way!
900     /// # }
901     /// ```
902     #[unstable(
903         feature = "concat_idents",
904         issue = "29599",
905         reason = "`concat_idents` is not stable enough for use and is subject to change"
906     )]
907     #[rustc_builtin_macro]
908     #[macro_export]
909     macro_rules! concat_idents {
910         ($($e:ident),+) => {{ /* compiler built-in */ }};
911         ($($e:ident,)+) => {{ /* compiler built-in */ }};
912     }
913
914     /// Concatenates literals into a static string slice.
915     ///
916     /// This macro takes any number of comma-separated literals, yielding an
917     /// expression of type `&'static str` which represents all of the literals
918     /// concatenated left-to-right.
919     ///
920     /// Integer and floating point literals are stringified in order to be
921     /// concatenated.
922     ///
923     /// # Examples
924     ///
925     /// ```
926     /// let s = concat!("test", 10, 'b', true);
927     /// assert_eq!(s, "test10btrue");
928     /// ```
929     #[stable(feature = "rust1", since = "1.0.0")]
930     #[rustc_builtin_macro]
931     #[macro_export]
932     macro_rules! concat {
933         ($($e:expr),*) => {{ /* compiler built-in */ }};
934         ($($e:expr,)*) => {{ /* compiler built-in */ }};
935     }
936
937     /// Expands to the line number on which it was invoked.
938     ///
939     /// With [`column!`] and [`file!`], these macros provide debugging information for
940     /// developers about the location within the source.
941     ///
942     /// The expanded expression has type `u32` and is 1-based, so the first line
943     /// in each file evaluates to 1, the second to 2, etc. This is consistent
944     /// with error messages by common compilers or popular editors.
945     /// The returned line is *not necessarily* the line of the `line!` invocation itself,
946     /// but rather the first macro invocation leading up to the invocation
947     /// of the `line!` macro.
948     ///
949     /// [`column!`]: macro.column.html
950     /// [`file!`]: macro.file.html
951     ///
952     /// # Examples
953     ///
954     /// ```
955     /// let current_line = line!();
956     /// println!("defined on line: {}", current_line);
957     /// ```
958     #[stable(feature = "rust1", since = "1.0.0")]
959     #[rustc_builtin_macro]
960     #[macro_export]
961     macro_rules! line {
962         () => {
963             /* compiler built-in */
964         };
965     }
966
967     /// Expands to the column number at which it was invoked.
968     ///
969     /// With [`line!`] and [`file!`], these macros provide debugging information for
970     /// developers about the location within the source.
971     ///
972     /// The expanded expression has type `u32` and is 1-based, so the first column
973     /// in each line evaluates to 1, the second to 2, etc. This is consistent
974     /// with error messages by common compilers or popular editors.
975     /// The returned column is *not necessarily* the line of the `column!` invocation itself,
976     /// but rather the first macro invocation leading up to the invocation
977     /// of the `column!` macro.
978     ///
979     /// [`line!`]: macro.line.html
980     /// [`file!`]: macro.file.html
981     ///
982     /// # Examples
983     ///
984     /// ```
985     /// let current_col = column!();
986     /// println!("defined on column: {}", current_col);
987     /// ```
988     #[stable(feature = "rust1", since = "1.0.0")]
989     #[rustc_builtin_macro]
990     #[macro_export]
991     macro_rules! column {
992         () => {
993             /* compiler built-in */
994         };
995     }
996
997     /// Expands to the file name in which it was invoked.
998     ///
999     /// With [`line!`] and [`column!`], these macros provide debugging information for
1000     /// developers about the location within the source.
1001     ///
1002     ///
1003     /// The expanded expression has type `&'static str`, and the returned file
1004     /// is not the invocation of the `file!` macro itself, but rather the
1005     /// first macro invocation leading up to the invocation of the `file!`
1006     /// macro.
1007     ///
1008     /// [`line!`]: macro.line.html
1009     /// [`column!`]: macro.column.html
1010     ///
1011     /// # Examples
1012     ///
1013     /// ```
1014     /// let this_file = file!();
1015     /// println!("defined in file: {}", this_file);
1016     /// ```
1017     #[stable(feature = "rust1", since = "1.0.0")]
1018     #[rustc_builtin_macro]
1019     #[macro_export]
1020     macro_rules! file {
1021         () => {
1022             /* compiler built-in */
1023         };
1024     }
1025
1026     /// Stringifies its arguments.
1027     ///
1028     /// This macro will yield an expression of type `&'static str` which is the
1029     /// stringification of all the tokens passed to the macro. No restrictions
1030     /// are placed on the syntax of the macro invocation itself.
1031     ///
1032     /// Note that the expanded results of the input tokens may change in the
1033     /// future. You should be careful if you rely on the output.
1034     ///
1035     /// # Examples
1036     ///
1037     /// ```
1038     /// let one_plus_one = stringify!(1 + 1);
1039     /// assert_eq!(one_plus_one, "1 + 1");
1040     /// ```
1041     #[stable(feature = "rust1", since = "1.0.0")]
1042     #[rustc_builtin_macro]
1043     #[macro_export]
1044     macro_rules! stringify {
1045         ($($t:tt)*) => {
1046             /* compiler built-in */
1047         };
1048     }
1049
1050     /// Includes a utf8-encoded file as a string.
1051     ///
1052     /// The file is located relative to the current file. (similarly to how
1053     /// modules are found)
1054     ///
1055     /// This macro will yield an expression of type `&'static str` which is the
1056     /// contents of the file.
1057     ///
1058     /// # Examples
1059     ///
1060     /// Assume there are two files in the same directory with the following
1061     /// contents:
1062     ///
1063     /// File 'spanish.in':
1064     ///
1065     /// ```text
1066     /// adiós
1067     /// ```
1068     ///
1069     /// File 'main.rs':
1070     ///
1071     /// ```ignore (cannot-doctest-external-file-dependency)
1072     /// fn main() {
1073     ///     let my_str = include_str!("spanish.in");
1074     ///     assert_eq!(my_str, "adiós\n");
1075     ///     print!("{}", my_str);
1076     /// }
1077     /// ```
1078     ///
1079     /// Compiling 'main.rs' and running the resulting binary will print "adiós".
1080     #[stable(feature = "rust1", since = "1.0.0")]
1081     #[rustc_builtin_macro]
1082     #[macro_export]
1083     macro_rules! include_str {
1084         ($file:expr) => {{ /* compiler built-in */ }};
1085         ($file:expr,) => {{ /* compiler built-in */ }};
1086     }
1087
1088     /// Includes a file as a reference to a byte array.
1089     ///
1090     /// The file is located relative to the current file. (similarly to how
1091     /// modules are found)
1092     ///
1093     /// This macro will yield an expression of type `&'static [u8; N]` which is
1094     /// the contents of the file.
1095     ///
1096     /// # Examples
1097     ///
1098     /// Assume there are two files in the same directory with the following
1099     /// contents:
1100     ///
1101     /// File 'spanish.in':
1102     ///
1103     /// ```text
1104     /// adiós
1105     /// ```
1106     ///
1107     /// File 'main.rs':
1108     ///
1109     /// ```ignore (cannot-doctest-external-file-dependency)
1110     /// fn main() {
1111     ///     let bytes = include_bytes!("spanish.in");
1112     ///     assert_eq!(bytes, b"adi\xc3\xb3s\n");
1113     ///     print!("{}", String::from_utf8_lossy(bytes));
1114     /// }
1115     /// ```
1116     ///
1117     /// Compiling 'main.rs' and running the resulting binary will print "adiós".
1118     #[stable(feature = "rust1", since = "1.0.0")]
1119     #[rustc_builtin_macro]
1120     #[macro_export]
1121     macro_rules! include_bytes {
1122         ($file:expr) => {{ /* compiler built-in */ }};
1123         ($file:expr,) => {{ /* compiler built-in */ }};
1124     }
1125
1126     /// Expands to a string that represents the current module path.
1127     ///
1128     /// The current module path can be thought of as the hierarchy of modules
1129     /// leading back up to the crate root. The first component of the path
1130     /// returned is the name of the crate currently being compiled.
1131     ///
1132     /// # Examples
1133     ///
1134     /// ```
1135     /// mod test {
1136     ///     pub fn foo() {
1137     ///         assert!(module_path!().ends_with("test"));
1138     ///     }
1139     /// }
1140     ///
1141     /// test::foo();
1142     /// ```
1143     #[stable(feature = "rust1", since = "1.0.0")]
1144     #[rustc_builtin_macro]
1145     #[macro_export]
1146     macro_rules! module_path {
1147         () => {
1148             /* compiler built-in */
1149         };
1150     }
1151
1152     /// Evaluates boolean combinations of configuration flags at compile-time.
1153     ///
1154     /// In addition to the `#[cfg]` attribute, this macro is provided to allow
1155     /// boolean expression evaluation of configuration flags. This frequently
1156     /// leads to less duplicated code.
1157     ///
1158     /// The syntax given to this macro is the same syntax as the [`cfg`]
1159     /// attribute.
1160     ///
1161     /// [`cfg`]: ../reference/conditional-compilation.html#the-cfg-attribute
1162     ///
1163     /// # Examples
1164     ///
1165     /// ```
1166     /// let my_directory = if cfg!(windows) {
1167     ///     "windows-specific-directory"
1168     /// } else {
1169     ///     "unix-directory"
1170     /// };
1171     /// ```
1172     #[stable(feature = "rust1", since = "1.0.0")]
1173     #[rustc_builtin_macro]
1174     #[macro_export]
1175     macro_rules! cfg {
1176         ($($cfg:tt)*) => {
1177             /* compiler built-in */
1178         };
1179     }
1180
1181     /// Parses a file as an expression or an item according to the context.
1182     ///
1183     /// The file is located relative to the current file (similarly to how
1184     /// modules are found).
1185     ///
1186     /// Using this macro is often a bad idea, because if the file is
1187     /// parsed as an expression, it is going to be placed in the
1188     /// surrounding code unhygienically. This could result in variables
1189     /// or functions being different from what the file expected if
1190     /// there are variables or functions that have the same name in
1191     /// the current file.
1192     ///
1193     /// # Examples
1194     ///
1195     /// Assume there are two files in the same directory with the following
1196     /// contents:
1197     ///
1198     /// File 'monkeys.in':
1199     ///
1200     /// ```ignore (only-for-syntax-highlight)
1201     /// ['🙈', '🙊', '🙉']
1202     ///     .iter()
1203     ///     .cycle()
1204     ///     .take(6)
1205     ///     .collect::<String>()
1206     /// ```
1207     ///
1208     /// File 'main.rs':
1209     ///
1210     /// ```ignore (cannot-doctest-external-file-dependency)
1211     /// fn main() {
1212     ///     let my_string = include!("monkeys.in");
1213     ///     assert_eq!("🙈🙊🙉🙈🙊🙉", my_string);
1214     ///     println!("{}", my_string);
1215     /// }
1216     /// ```
1217     ///
1218     /// Compiling 'main.rs' and running the resulting binary will print
1219     /// "🙈🙊🙉🙈🙊🙉".
1220     #[stable(feature = "rust1", since = "1.0.0")]
1221     #[rustc_builtin_macro]
1222     #[macro_export]
1223     macro_rules! include {
1224         ($file:expr) => {{ /* compiler built-in */ }};
1225         ($file:expr,) => {{ /* compiler built-in */ }};
1226     }
1227
1228     /// Asserts that a boolean expression is `true` at runtime.
1229     ///
1230     /// This will invoke the [`panic!`] macro if the provided expression cannot be
1231     /// evaluated to `true` at runtime.
1232     ///
1233     /// # Uses
1234     ///
1235     /// Assertions are always checked in both debug and release builds, and cannot
1236     /// be disabled. See [`debug_assert!`] for assertions that are not enabled in
1237     /// release builds by default.
1238     ///
1239     /// Unsafe code relies on `assert!` to enforce run-time invariants that, if
1240     /// violated could lead to unsafety.
1241     ///
1242     /// Other use-cases of `assert!` include testing and enforcing run-time
1243     /// invariants in safe code (whose violation cannot result in unsafety).
1244     ///
1245     /// # Custom Messages
1246     ///
1247     /// This macro has a second form, where a custom panic message can
1248     /// be provided with or without arguments for formatting. See [`std::fmt`]
1249     /// for syntax for this form.
1250     ///
1251     /// [`panic!`]: macro.panic.html
1252     /// [`debug_assert!`]: macro.debug_assert.html
1253     /// [`std::fmt`]: ../std/fmt/index.html
1254     ///
1255     /// # Examples
1256     ///
1257     /// ```
1258     /// // the panic message for these assertions is the stringified value of the
1259     /// // expression given.
1260     /// assert!(true);
1261     ///
1262     /// fn some_computation() -> bool { true } // a very simple function
1263     ///
1264     /// assert!(some_computation());
1265     ///
1266     /// // assert with a custom message
1267     /// let x = true;
1268     /// assert!(x, "x wasn't true!");
1269     ///
1270     /// let a = 3; let b = 27;
1271     /// assert!(a + b == 30, "a = {}, b = {}", a, b);
1272     /// ```
1273     #[stable(feature = "rust1", since = "1.0.0")]
1274     #[rustc_builtin_macro]
1275     #[macro_export]
1276     macro_rules! assert {
1277         ($cond:expr) => {{ /* compiler built-in */ }};
1278         ($cond:expr,) => {{ /* compiler built-in */ }};
1279         ($cond:expr, $($arg:tt)+) => {{ /* compiler built-in */ }};
1280     }
1281
1282     /// Inline assembly.
1283     ///
1284     /// Read the [unstable book] for the usage.
1285     ///
1286     /// [unstable book]: ../unstable-book/library-features/asm.html
1287     #[unstable(
1288         feature = "asm",
1289         issue = "29722",
1290         reason = "inline assembly is not stable enough for use and is subject to change"
1291     )]
1292     #[rustc_builtin_macro]
1293     #[macro_export]
1294     macro_rules! asm {
1295         ("assembly template"
1296                         : $("output"(operand),)*
1297                         : $("input"(operand),)*
1298                         : $("clobbers",)*
1299                         : $("options",)*) => {
1300             /* compiler built-in */
1301         };
1302     }
1303
1304     /// Module-level inline assembly.
1305     #[unstable(
1306         feature = "global_asm",
1307         issue = "35119",
1308         reason = "`global_asm!` is not stable enough for use and is subject to change"
1309     )]
1310     #[rustc_builtin_macro]
1311     #[macro_export]
1312     macro_rules! global_asm {
1313         ("assembly") => {
1314             /* compiler built-in */
1315         };
1316     }
1317
1318     /// Prints passed tokens into the standard output.
1319     #[unstable(
1320         feature = "log_syntax",
1321         issue = "29598",
1322         reason = "`log_syntax!` is not stable enough for use and is subject to change"
1323     )]
1324     #[rustc_builtin_macro]
1325     #[macro_export]
1326     macro_rules! log_syntax {
1327         ($($arg:tt)*) => {
1328             /* compiler built-in */
1329         };
1330     }
1331
1332     /// Enables or disables tracing functionality used for debugging other macros.
1333     #[unstable(
1334         feature = "trace_macros",
1335         issue = "29598",
1336         reason = "`trace_macros` is not stable enough for use and is subject to change"
1337     )]
1338     #[rustc_builtin_macro]
1339     #[macro_export]
1340     macro_rules! trace_macros {
1341         (true) => {{ /* compiler built-in */ }};
1342         (false) => {{ /* compiler built-in */ }};
1343     }
1344
1345     /// Attribute macro applied to a function to turn it into a unit test.
1346     #[stable(feature = "rust1", since = "1.0.0")]
1347     #[allow_internal_unstable(test, rustc_attrs)]
1348     #[rustc_builtin_macro]
1349     pub macro test($item:item) {
1350         /* compiler built-in */
1351     }
1352
1353     /// Attribute macro applied to a function to turn it into a benchmark test.
1354     #[unstable(
1355         feature = "test",
1356         issue = "50297",
1357         soft,
1358         reason = "`bench` is a part of custom test frameworks which are unstable"
1359     )]
1360     #[allow_internal_unstable(test, rustc_attrs)]
1361     #[rustc_builtin_macro]
1362     pub macro bench($item:item) {
1363         /* compiler built-in */
1364     }
1365
1366     /// An implementation detail of the `#[test]` and `#[bench]` macros.
1367     #[unstable(
1368         feature = "custom_test_frameworks",
1369         issue = "50297",
1370         reason = "custom test frameworks are an unstable feature"
1371     )]
1372     #[allow_internal_unstable(test, rustc_attrs)]
1373     #[rustc_builtin_macro]
1374     pub macro test_case($item:item) {
1375         /* compiler built-in */
1376     }
1377
1378     /// Attribute macro applied to a static to register it as a global allocator.
1379     #[stable(feature = "global_allocator", since = "1.28.0")]
1380     #[allow_internal_unstable(rustc_attrs)]
1381     #[rustc_builtin_macro]
1382     pub macro global_allocator($item:item) {
1383         /* compiler built-in */
1384     }
1385
1386     /// Unstable implementation detail of the `rustc` compiler, do not use.
1387     #[rustc_builtin_macro]
1388     #[stable(feature = "rust1", since = "1.0.0")]
1389     #[allow_internal_unstable(core_intrinsics, libstd_sys_internals)]
1390     pub macro RustcDecodable($item:item) {
1391         /* compiler built-in */
1392     }
1393
1394     /// Unstable implementation detail of the `rustc` compiler, do not use.
1395     #[rustc_builtin_macro]
1396     #[stable(feature = "rust1", since = "1.0.0")]
1397     #[allow_internal_unstable(core_intrinsics)]
1398     pub macro RustcEncodable($item:item) {
1399         /* compiler built-in */
1400     }
1401 }