]> git.lizzy.rs Git - rust.git/blob - library/core/src/macros/mod.rs
Fix font color for help button in ayu and dark themes
[rust.git] / library / core / src / macros / mod.rs
1 #[doc(include = "panic.md")]
2 #[macro_export]
3 #[allow_internal_unstable(core_panic, const_caller_location)]
4 #[stable(feature = "core", since = "1.6.0")]
5 macro_rules! panic {
6     () => (
7         $crate::panic!("explicit panic")
8     );
9     ($msg:literal) => (
10         $crate::panicking::panic($msg)
11     );
12     ($msg:expr) => (
13         $crate::panic!("{}", $crate::convert::identity::<&str>($msg))
14     );
15     ($msg:expr,) => (
16         $crate::panic!($msg)
17     );
18     ($fmt:expr, $($arg:tt)+) => (
19         $crate::panicking::panic_fmt($crate::format_args!($fmt, $($arg)+))
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, however, is 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 UTF-8 encoded file as a string.
1051     ///
1052     /// The file is located relative to the current file (similarly to how
1053     /// modules are found). The provided path is interpreted in a platform-specific
1054     /// way at compile time. So, for instance, an invocation with a Windows path
1055     /// containing backslashes `\` would not compile correctly on Unix.
1056     ///
1057     /// This macro will yield an expression of type `&'static str` which is the
1058     /// contents of the file.
1059     ///
1060     /// # Examples
1061     ///
1062     /// Assume there are two files in the same directory with the following
1063     /// contents:
1064     ///
1065     /// File 'spanish.in':
1066     ///
1067     /// ```text
1068     /// adiós
1069     /// ```
1070     ///
1071     /// File 'main.rs':
1072     ///
1073     /// ```ignore (cannot-doctest-external-file-dependency)
1074     /// fn main() {
1075     ///     let my_str = include_str!("spanish.in");
1076     ///     assert_eq!(my_str, "adiós\n");
1077     ///     print!("{}", my_str);
1078     /// }
1079     /// ```
1080     ///
1081     /// Compiling 'main.rs' and running the resulting binary will print "adiós".
1082     #[stable(feature = "rust1", since = "1.0.0")]
1083     #[rustc_builtin_macro]
1084     #[macro_export]
1085     macro_rules! include_str {
1086         ($file:expr) => {{ /* compiler built-in */ }};
1087         ($file:expr,) => {{ /* compiler built-in */ }};
1088     }
1089
1090     /// Includes a file as a reference to a byte array.
1091     ///
1092     /// The file is located relative to the current file (similarly to how
1093     /// modules are found). The provided path is interpreted in a platform-specific
1094     /// way at compile time. So, for instance, an invocation with a Windows path
1095     /// containing backslashes `\` would not compile correctly on Unix.
1096     ///
1097     /// This macro will yield an expression of type `&'static [u8; N]` which is
1098     /// the contents of the file.
1099     ///
1100     /// # Examples
1101     ///
1102     /// Assume there are two files in the same directory with the following
1103     /// contents:
1104     ///
1105     /// File 'spanish.in':
1106     ///
1107     /// ```text
1108     /// adiós
1109     /// ```
1110     ///
1111     /// File 'main.rs':
1112     ///
1113     /// ```ignore (cannot-doctest-external-file-dependency)
1114     /// fn main() {
1115     ///     let bytes = include_bytes!("spanish.in");
1116     ///     assert_eq!(bytes, b"adi\xc3\xb3s\n");
1117     ///     print!("{}", String::from_utf8_lossy(bytes));
1118     /// }
1119     /// ```
1120     ///
1121     /// Compiling 'main.rs' and running the resulting binary will print "adiós".
1122     #[stable(feature = "rust1", since = "1.0.0")]
1123     #[rustc_builtin_macro]
1124     #[macro_export]
1125     macro_rules! include_bytes {
1126         ($file:expr) => {{ /* compiler built-in */ }};
1127         ($file:expr,) => {{ /* compiler built-in */ }};
1128     }
1129
1130     /// Expands to a string that represents the current module path.
1131     ///
1132     /// The current module path can be thought of as the hierarchy of modules
1133     /// leading back up to the crate root. The first component of the path
1134     /// returned is the name of the crate currently being compiled.
1135     ///
1136     /// # Examples
1137     ///
1138     /// ```
1139     /// mod test {
1140     ///     pub fn foo() {
1141     ///         assert!(module_path!().ends_with("test"));
1142     ///     }
1143     /// }
1144     ///
1145     /// test::foo();
1146     /// ```
1147     #[stable(feature = "rust1", since = "1.0.0")]
1148     #[rustc_builtin_macro]
1149     #[macro_export]
1150     macro_rules! module_path {
1151         () => {
1152             /* compiler built-in */
1153         };
1154     }
1155
1156     /// Evaluates boolean combinations of configuration flags at compile-time.
1157     ///
1158     /// In addition to the `#[cfg]` attribute, this macro is provided to allow
1159     /// boolean expression evaluation of configuration flags. This frequently
1160     /// leads to less duplicated code.
1161     ///
1162     /// The syntax given to this macro is the same syntax as the [`cfg`]
1163     /// attribute.
1164     ///
1165     /// `cfg!`, unlike `#[cfg]`, does not remove any code and only evaluates to true or false. For
1166     /// example, all blocks in an if/else expression need to be valid when `cfg!` is used for
1167     /// the condition, regardless of what `cfg!` is evaluating.
1168     ///
1169     /// [`cfg`]: ../reference/conditional-compilation.html#the-cfg-attribute
1170     ///
1171     /// # Examples
1172     ///
1173     /// ```
1174     /// let my_directory = if cfg!(windows) {
1175     ///     "windows-specific-directory"
1176     /// } else {
1177     ///     "unix-directory"
1178     /// };
1179     /// ```
1180     #[stable(feature = "rust1", since = "1.0.0")]
1181     #[rustc_builtin_macro]
1182     #[macro_export]
1183     macro_rules! cfg {
1184         ($($cfg:tt)*) => {
1185             /* compiler built-in */
1186         };
1187     }
1188
1189     /// Parses a file as an expression or an item according to the context.
1190     ///
1191     /// The file is located relative to the current file (similarly to how
1192     /// modules are found). The provided path is interpreted in a platform-specific
1193     /// way at compile time. So, for instance, an invocation with a Windows path
1194     /// containing backslashes `\` would not compile correctly on Unix.
1195     ///
1196     /// Using this macro is often a bad idea, because if the file is
1197     /// parsed as an expression, it is going to be placed in the
1198     /// surrounding code unhygienically. This could result in variables
1199     /// or functions being different from what the file expected if
1200     /// there are variables or functions that have the same name in
1201     /// the current file.
1202     ///
1203     /// # Examples
1204     ///
1205     /// Assume there are two files in the same directory with the following
1206     /// contents:
1207     ///
1208     /// File 'monkeys.in':
1209     ///
1210     /// ```ignore (only-for-syntax-highlight)
1211     /// ['🙈', '🙊', '🙉']
1212     ///     .iter()
1213     ///     .cycle()
1214     ///     .take(6)
1215     ///     .collect::<String>()
1216     /// ```
1217     ///
1218     /// File 'main.rs':
1219     ///
1220     /// ```ignore (cannot-doctest-external-file-dependency)
1221     /// fn main() {
1222     ///     let my_string = include!("monkeys.in");
1223     ///     assert_eq!("🙈🙊🙉🙈🙊🙉", my_string);
1224     ///     println!("{}", my_string);
1225     /// }
1226     /// ```
1227     ///
1228     /// Compiling 'main.rs' and running the resulting binary will print
1229     /// "🙈🙊🙉🙈🙊🙉".
1230     #[stable(feature = "rust1", since = "1.0.0")]
1231     #[rustc_builtin_macro]
1232     #[macro_export]
1233     macro_rules! include {
1234         ($file:expr) => {{ /* compiler built-in */ }};
1235         ($file:expr,) => {{ /* compiler built-in */ }};
1236     }
1237
1238     /// Asserts that a boolean expression is `true` at runtime.
1239     ///
1240     /// This will invoke the [`panic!`] macro if the provided expression cannot be
1241     /// evaluated to `true` at runtime.
1242     ///
1243     /// # Uses
1244     ///
1245     /// Assertions are always checked in both debug and release builds, and cannot
1246     /// be disabled. See [`debug_assert!`] for assertions that are not enabled in
1247     /// release builds by default.
1248     ///
1249     /// Unsafe code may rely on `assert!` to enforce run-time invariants that, if
1250     /// violated could lead to unsafety.
1251     ///
1252     /// Other use-cases of `assert!` include testing and enforcing run-time
1253     /// invariants in safe code (whose violation cannot result in unsafety).
1254     ///
1255     /// # Custom Messages
1256     ///
1257     /// This macro has a second form, where a custom panic message can
1258     /// be provided with or without arguments for formatting. See [`std::fmt`]
1259     /// for syntax for this form.
1260     ///
1261     /// [`panic!`]: macro.panic.html
1262     /// [`debug_assert!`]: macro.debug_assert.html
1263     /// [`std::fmt`]: ../std/fmt/index.html
1264     ///
1265     /// # Examples
1266     ///
1267     /// ```
1268     /// // the panic message for these assertions is the stringified value of the
1269     /// // expression given.
1270     /// assert!(true);
1271     ///
1272     /// fn some_computation() -> bool { true } // a very simple function
1273     ///
1274     /// assert!(some_computation());
1275     ///
1276     /// // assert with a custom message
1277     /// let x = true;
1278     /// assert!(x, "x wasn't true!");
1279     ///
1280     /// let a = 3; let b = 27;
1281     /// assert!(a + b == 30, "a = {}, b = {}", a, b);
1282     /// ```
1283     #[stable(feature = "rust1", since = "1.0.0")]
1284     #[rustc_builtin_macro]
1285     #[macro_export]
1286     macro_rules! assert {
1287         ($cond:expr) => {{ /* compiler built-in */ }};
1288         ($cond:expr,) => {{ /* compiler built-in */ }};
1289         ($cond:expr, $($arg:tt)+) => {{ /* compiler built-in */ }};
1290     }
1291
1292     /// Inline assembly.
1293     ///
1294     /// Read the [unstable book] for the usage.
1295     ///
1296     /// [unstable book]: ../unstable-book/library-features/asm.html
1297     #[unstable(
1298         feature = "asm",
1299         issue = "72016",
1300         reason = "inline assembly is not stable enough for use and is subject to change"
1301     )]
1302     #[rustc_builtin_macro]
1303     #[macro_export]
1304     macro_rules! asm {
1305         ("assembly template",
1306             $(operands,)*
1307             $(options($(option),*))?
1308         ) => {
1309             /* compiler built-in */
1310         };
1311     }
1312
1313     /// LLVM-style inline assembly.
1314     ///
1315     /// Read the [unstable book] for the usage.
1316     ///
1317     /// [unstable book]: ../unstable-book/library-features/llvm-asm.html
1318     #[unstable(
1319         feature = "llvm_asm",
1320         issue = "70173",
1321         reason = "prefer using the new asm! syntax instead"
1322     )]
1323     #[rustc_builtin_macro]
1324     #[macro_export]
1325     macro_rules! llvm_asm {
1326         ("assembly template"
1327                         : $("output"(operand),)*
1328                         : $("input"(operand),)*
1329                         : $("clobbers",)*
1330                         : $("options",)*) => {
1331             /* compiler built-in */
1332         };
1333     }
1334
1335     /// Module-level inline assembly.
1336     #[unstable(
1337         feature = "global_asm",
1338         issue = "35119",
1339         reason = "`global_asm!` is not stable enough for use and is subject to change"
1340     )]
1341     #[rustc_builtin_macro]
1342     #[macro_export]
1343     macro_rules! global_asm {
1344         ("assembly") => {
1345             /* compiler built-in */
1346         };
1347     }
1348
1349     /// Prints passed tokens into the standard output.
1350     #[unstable(
1351         feature = "log_syntax",
1352         issue = "29598",
1353         reason = "`log_syntax!` is not stable enough for use and is subject to change"
1354     )]
1355     #[rustc_builtin_macro]
1356     #[macro_export]
1357     macro_rules! log_syntax {
1358         ($($arg:tt)*) => {
1359             /* compiler built-in */
1360         };
1361     }
1362
1363     /// Enables or disables tracing functionality used for debugging other macros.
1364     #[unstable(
1365         feature = "trace_macros",
1366         issue = "29598",
1367         reason = "`trace_macros` is not stable enough for use and is subject to change"
1368     )]
1369     #[rustc_builtin_macro]
1370     #[macro_export]
1371     macro_rules! trace_macros {
1372         (true) => {{ /* compiler built-in */ }};
1373         (false) => {{ /* compiler built-in */ }};
1374     }
1375
1376     /// Attribute macro applied to a function to turn it into a unit test.
1377     #[stable(feature = "rust1", since = "1.0.0")]
1378     #[allow_internal_unstable(test, rustc_attrs)]
1379     #[rustc_builtin_macro]
1380     pub macro test($item:item) {
1381         /* compiler built-in */
1382     }
1383
1384     /// Attribute macro applied to a function to turn it into a benchmark test.
1385     #[unstable(
1386         feature = "test",
1387         issue = "50297",
1388         soft,
1389         reason = "`bench` is a part of custom test frameworks which are unstable"
1390     )]
1391     #[allow_internal_unstable(test, rustc_attrs)]
1392     #[rustc_builtin_macro]
1393     pub macro bench($item:item) {
1394         /* compiler built-in */
1395     }
1396
1397     /// An implementation detail of the `#[test]` and `#[bench]` macros.
1398     #[unstable(
1399         feature = "custom_test_frameworks",
1400         issue = "50297",
1401         reason = "custom test frameworks are an unstable feature"
1402     )]
1403     #[allow_internal_unstable(test, rustc_attrs)]
1404     #[rustc_builtin_macro]
1405     pub macro test_case($item:item) {
1406         /* compiler built-in */
1407     }
1408
1409     /// Attribute macro applied to a static to register it as a global allocator.
1410     #[stable(feature = "global_allocator", since = "1.28.0")]
1411     #[allow_internal_unstable(rustc_attrs)]
1412     #[rustc_builtin_macro]
1413     pub macro global_allocator($item:item) {
1414         /* compiler built-in */
1415     }
1416
1417     /// Keeps the item it's applied to if the passed path is accessible, and removes it otherwise.
1418     #[unstable(
1419         feature = "cfg_accessible",
1420         issue = "64797",
1421         reason = "`cfg_accessible` is not fully implemented"
1422     )]
1423     #[rustc_builtin_macro]
1424     pub macro cfg_accessible($item:item) {
1425         /* compiler built-in */
1426     }
1427
1428     /// Unstable implementation detail of the `rustc` compiler, do not use.
1429     #[rustc_builtin_macro]
1430     #[stable(feature = "rust1", since = "1.0.0")]
1431     #[allow_internal_unstable(core_intrinsics, libstd_sys_internals)]
1432     pub macro RustcDecodable($item:item) {
1433         /* compiler built-in */
1434     }
1435
1436     /// Unstable implementation detail of the `rustc` compiler, do not use.
1437     #[rustc_builtin_macro]
1438     #[stable(feature = "rust1", since = "1.0.0")]
1439     #[allow_internal_unstable(core_intrinsics)]
1440     pub macro RustcEncodable($item:item) {
1441         /* compiler built-in */
1442     }
1443 }