]> git.lizzy.rs Git - rust.git/blob - src/libstd/macros.rs
Rollup merge of #60385 - nnethercote:earlier-metadata, r=alexcrichton
[rust.git] / src / libstd / macros.rs
1 //! Standard library macros
2 //!
3 //! This modules contains a set of macros which are exported from the standard
4 //! library. Each macro is available for use when linking against the standard
5 //! library.
6
7 /// Panics the current thread.
8 ///
9 /// This allows a program to terminate immediately and provide feedback
10 /// to the caller of the program. `panic!` should be used when a program reaches
11 /// an unrecoverable state.
12 ///
13 /// This macro is the perfect way to assert conditions in example code and in
14 /// tests. `panic!` is closely tied with the `unwrap` method of both [`Option`]
15 /// and [`Result`][runwrap] enums. Both implementations call `panic!` when they are set
16 /// to None or Err variants.
17 ///
18 /// This macro is used to inject panic into a Rust thread, causing the thread to
19 /// panic entirely. Each thread's panic can be reaped as the `Box<Any>` type,
20 /// and the single-argument form of the `panic!` macro will be the value which
21 /// is transmitted.
22 ///
23 /// [`Result`] enum is often a better solution for recovering from errors than
24 /// using the `panic!` macro. This macro should be used to avoid proceeding using
25 /// incorrect values, such as from external sources. Detailed information about
26 /// error handling is found in the [book].
27 ///
28 /// The multi-argument form of this macro panics with a string and has the
29 /// [`format!`] syntax for building a string.
30 ///
31 /// See also the macro [`compile_error!`], for raising errors during compilation.
32 ///
33 /// [runwrap]: ../std/result/enum.Result.html#method.unwrap
34 /// [`Option`]: ../std/option/enum.Option.html#method.unwrap
35 /// [`Result`]: ../std/result/enum.Result.html
36 /// [`format!`]: ../std/macro.format.html
37 /// [`compile_error!`]: ../std/macro.compile_error.html
38 /// [book]: ../book/ch09-00-error-handling.html
39 ///
40 /// # Current implementation
41 ///
42 /// If the main thread panics it will terminate all your threads and end your
43 /// program with code `101`.
44 ///
45 /// # Examples
46 ///
47 /// ```should_panic
48 /// # #![allow(unreachable_code)]
49 /// panic!();
50 /// panic!("this is a terrible mistake!");
51 /// panic!(4); // panic with the value of 4 to be collected elsewhere
52 /// panic!("this is a {} {message}", "fancy", message = "message");
53 /// ```
54 #[macro_export]
55 #[stable(feature = "rust1", since = "1.0.0")]
56 #[allow_internal_unstable(__rust_unstable_column, libstd_sys_internals)]
57 macro_rules! panic {
58     () => ({
59         panic!("explicit panic")
60     });
61     ($msg:expr) => ({
62         $crate::rt::begin_panic($msg, &(file!(), line!(), __rust_unstable_column!()))
63     });
64     ($msg:expr,) => ({
65         panic!($msg)
66     });
67     ($fmt:expr, $($arg:tt)+) => ({
68         $crate::rt::begin_panic_fmt(&format_args!($fmt, $($arg)+),
69                                     &(file!(), line!(), __rust_unstable_column!()))
70     });
71 }
72
73 /// Prints to the standard output.
74 ///
75 /// Equivalent to the [`println!`] macro except that a newline is not printed at
76 /// the end of the message.
77 ///
78 /// Note that stdout is frequently line-buffered by default so it may be
79 /// necessary to use [`io::stdout().flush()`][flush] to ensure the output is emitted
80 /// immediately.
81 ///
82 /// Use `print!` only for the primary output of your program. Use
83 /// [`eprint!`] instead to print error and progress messages.
84 ///
85 /// [`println!`]: ../std/macro.println.html
86 /// [flush]: ../std/io/trait.Write.html#tymethod.flush
87 /// [`eprint!`]: ../std/macro.eprint.html
88 ///
89 /// # Panics
90 ///
91 /// Panics if writing to `io::stdout()` fails.
92 ///
93 /// # Examples
94 ///
95 /// ```
96 /// use std::io::{self, Write};
97 ///
98 /// print!("this ");
99 /// print!("will ");
100 /// print!("be ");
101 /// print!("on ");
102 /// print!("the ");
103 /// print!("same ");
104 /// print!("line ");
105 ///
106 /// io::stdout().flush().unwrap();
107 ///
108 /// print!("this string has a newline, why not choose println! instead?\n");
109 ///
110 /// io::stdout().flush().unwrap();
111 /// ```
112 #[macro_export]
113 #[stable(feature = "rust1", since = "1.0.0")]
114 #[allow_internal_unstable(print_internals)]
115 macro_rules! print {
116     ($($arg:tt)*) => ($crate::io::_print(format_args!($($arg)*)));
117 }
118
119 /// Prints to the standard output, with a newline.
120 ///
121 /// On all platforms, the newline is the LINE FEED character (`\n`/`U+000A`) alone
122 /// (no additional CARRIAGE RETURN (`\r`/`U+000D`).
123 ///
124 /// Use the [`format!`] syntax to write data to the standard output.
125 /// See [`std::fmt`] for more information.
126 ///
127 /// Use `println!` only for the primary output of your program. Use
128 /// [`eprintln!`] instead to print error and progress messages.
129 ///
130 /// [`format!`]: ../std/macro.format.html
131 /// [`std::fmt`]: ../std/fmt/index.html
132 /// [`eprintln!`]: ../std/macro.eprintln.html
133 /// # Panics
134 ///
135 /// Panics if writing to `io::stdout` fails.
136 ///
137 /// # Examples
138 ///
139 /// ```
140 /// println!(); // prints just a newline
141 /// println!("hello there!");
142 /// println!("format {} arguments", "some");
143 /// ```
144 #[macro_export]
145 #[stable(feature = "rust1", since = "1.0.0")]
146 #[allow_internal_unstable(print_internals, format_args_nl)]
147 macro_rules! println {
148     () => (print!("\n"));
149     ($($arg:tt)*) => ({
150         $crate::io::_print(format_args_nl!($($arg)*));
151     })
152 }
153
154 /// Prints to the standard error.
155 ///
156 /// Equivalent to the [`print!`] macro, except that output goes to
157 /// [`io::stderr`] instead of `io::stdout`. See [`print!`] for
158 /// example usage.
159 ///
160 /// Use `eprint!` only for error and progress messages. Use `print!`
161 /// instead for the primary output of your program.
162 ///
163 /// [`io::stderr`]: ../std/io/struct.Stderr.html
164 /// [`print!`]: ../std/macro.print.html
165 ///
166 /// # Panics
167 ///
168 /// Panics if writing to `io::stderr` fails.
169 ///
170 /// # Examples
171 ///
172 /// ```
173 /// eprint!("Error: Could not complete task");
174 /// ```
175 #[macro_export]
176 #[stable(feature = "eprint", since = "1.19.0")]
177 #[allow_internal_unstable(print_internals)]
178 macro_rules! eprint {
179     ($($arg:tt)*) => ($crate::io::_eprint(format_args!($($arg)*)));
180 }
181
182 /// Prints to the standard error, with a newline.
183 ///
184 /// Equivalent to the [`println!`] macro, except that output goes to
185 /// [`io::stderr`] instead of `io::stdout`. See [`println!`] for
186 /// example usage.
187 ///
188 /// Use `eprintln!` only for error and progress messages. Use `println!`
189 /// instead for the primary output of your program.
190 ///
191 /// [`io::stderr`]: ../std/io/struct.Stderr.html
192 /// [`println!`]: ../std/macro.println.html
193 ///
194 /// # Panics
195 ///
196 /// Panics if writing to `io::stderr` fails.
197 ///
198 /// # Examples
199 ///
200 /// ```
201 /// eprintln!("Error: Could not complete task");
202 /// ```
203 #[macro_export]
204 #[stable(feature = "eprint", since = "1.19.0")]
205 #[allow_internal_unstable(print_internals, format_args_nl)]
206 macro_rules! eprintln {
207     () => (eprint!("\n"));
208     ($($arg:tt)*) => ({
209         $crate::io::_eprint(format_args_nl!($($arg)*));
210     })
211 }
212
213 /// Prints and returns the value of a given expression for quick and dirty
214 /// debugging.
215 ///
216 /// An example:
217 ///
218 /// ```rust
219 /// let a = 2;
220 /// let b = dbg!(a * 2) + 1;
221 /// //      ^-- prints: [src/main.rs:2] a * 2 = 4
222 /// assert_eq!(b, 5);
223 /// ```
224 ///
225 /// The macro works by using the `Debug` implementation of the type of
226 /// the given expression to print the value to [stderr] along with the
227 /// source location of the macro invocation as well as the source code
228 /// of the expression.
229 ///
230 /// Invoking the macro on an expression moves and takes ownership of it
231 /// before returning the evaluated expression unchanged. If the type
232 /// of the expression does not implement `Copy` and you don't want
233 /// to give up ownership, you can instead borrow with `dbg!(&expr)`
234 /// for some expression `expr`.
235 ///
236 /// The `dbg!` macro works exactly the same in release builds.
237 /// This is useful when debugging issues that only occur in release
238 /// builds or when debugging in release mode is significantly faster.
239 ///
240 /// Note that the macro is intended as a debugging tool and therefore you
241 /// should avoid having uses of it in version control for longer periods.
242 /// Use cases involving debug output that should be added to version control
243 /// are better served by macros such as [`debug!`] from the [`log`] crate.
244 ///
245 /// # Stability
246 ///
247 /// The exact output printed by this macro should not be relied upon
248 /// and is subject to future changes.
249 ///
250 /// # Panics
251 ///
252 /// Panics if writing to `io::stderr` fails.
253 ///
254 /// # Further examples
255 ///
256 /// With a method call:
257 ///
258 /// ```rust
259 /// fn foo(n: usize) {
260 ///     if let Some(_) = dbg!(n.checked_sub(4)) {
261 ///         // ...
262 ///     }
263 /// }
264 ///
265 /// foo(3)
266 /// ```
267 ///
268 /// This prints to [stderr]:
269 ///
270 /// ```text,ignore
271 /// [src/main.rs:4] n.checked_sub(4) = None
272 /// ```
273 ///
274 /// Naive factorial implementation:
275 ///
276 /// ```rust
277 /// fn factorial(n: u32) -> u32 {
278 ///     if dbg!(n <= 1) {
279 ///         dbg!(1)
280 ///     } else {
281 ///         dbg!(n * factorial(n - 1))
282 ///     }
283 /// }
284 ///
285 /// dbg!(factorial(4));
286 /// ```
287 ///
288 /// This prints to [stderr]:
289 ///
290 /// ```text,ignore
291 /// [src/main.rs:3] n <= 1 = false
292 /// [src/main.rs:3] n <= 1 = false
293 /// [src/main.rs:3] n <= 1 = false
294 /// [src/main.rs:3] n <= 1 = true
295 /// [src/main.rs:4] 1 = 1
296 /// [src/main.rs:5] n * factorial(n - 1) = 2
297 /// [src/main.rs:5] n * factorial(n - 1) = 6
298 /// [src/main.rs:5] n * factorial(n - 1) = 24
299 /// [src/main.rs:11] factorial(4) = 24
300 /// ```
301 ///
302 /// The `dbg!(..)` macro moves the input:
303 ///
304 /// ```compile_fail
305 /// /// A wrapper around `usize` which importantly is not Copyable.
306 /// #[derive(Debug)]
307 /// struct NoCopy(usize);
308 ///
309 /// let a = NoCopy(42);
310 /// let _ = dbg!(a); // <-- `a` is moved here.
311 /// let _ = dbg!(a); // <-- `a` is moved again; error!
312 /// ```
313 ///
314 /// You can also use `dbg!()` without a value to just print the
315 /// file and line whenever it's reached.
316 ///
317 /// Finally, if you want to `dbg!(..)` multiple values, it will treat them as
318 /// a tuple (and return it, too):
319 ///
320 /// ```
321 /// assert_eq!(dbg!(1usize, 2u32), (1, 2));
322 /// ```
323 ///
324 /// However, a single argument with a trailing comma will still not be treated
325 /// as a tuple, following the convention of ignoring trailing commas in macro
326 /// invocations. You can use a 1-tuple directly if you need one:
327 ///
328 /// ```
329 /// assert_eq!(1, dbg!(1u32,)); // trailing comma ignored
330 /// assert_eq!((1,), dbg!((1u32,))); // 1-tuple
331 /// ```
332 ///
333 /// [stderr]: https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)
334 /// [`debug!`]: https://docs.rs/log/*/log/macro.debug.html
335 /// [`log`]: https://crates.io/crates/log
336 #[macro_export]
337 #[stable(feature = "dbg_macro", since = "1.32.0")]
338 macro_rules! dbg {
339     () => {
340         eprintln!("[{}:{}]", file!(), line!());
341     };
342     ($val:expr) => {
343         // Use of `match` here is intentional because it affects the lifetimes
344         // of temporaries - https://stackoverflow.com/a/48732525/1063961
345         match $val {
346             tmp => {
347                 eprintln!("[{}:{}] {} = {:#?}",
348                     file!(), line!(), stringify!($val), &tmp);
349                 tmp
350             }
351         }
352     };
353     // Trailing comma with single argument is ignored
354     ($val:expr,) => { dbg!($val) };
355     ($($val:expr),+ $(,)?) => {
356         ($(dbg!($val)),+,)
357     };
358 }
359
360 /// Awaits the completion of an async call.
361 #[macro_export]
362 #[unstable(feature = "await_macro", issue = "50547")]
363 #[allow_internal_unstable(gen_future, generators)]
364 #[allow_internal_unsafe]
365 macro_rules! r#await {
366     ($e:expr) => { {
367         let mut pinned = $e;
368         loop {
369             if let $crate::task::Poll::Ready(x) =
370                 $crate::future::poll_with_tls_context(unsafe {
371                     $crate::pin::Pin::new_unchecked(&mut pinned)
372                 })
373             {
374                 break x;
375             }
376             // FIXME(cramertj) prior to stabilizing await, we have to ensure that this
377             // can't be used to create a generator on stable via `|| await!()`.
378             yield
379         }
380     } }
381 }
382
383 /// Selects the first successful receive event from a number of receivers.
384 ///
385 /// This macro is used to wait for the first event to occur on a number of
386 /// receivers. It places no restrictions on the types of receivers given to
387 /// this macro, this can be viewed as a heterogeneous select.
388 ///
389 /// # Examples
390 ///
391 /// ```
392 /// #![feature(mpsc_select)]
393 ///
394 /// use std::thread;
395 /// use std::sync::mpsc;
396 ///
397 /// // two placeholder functions for now
398 /// fn long_running_thread() {}
399 /// fn calculate_the_answer() -> u32 { 42 }
400 ///
401 /// let (tx1, rx1) = mpsc::channel();
402 /// let (tx2, rx2) = mpsc::channel();
403 ///
404 /// thread::spawn(move|| { long_running_thread(); tx1.send(()).unwrap(); });
405 /// thread::spawn(move|| { tx2.send(calculate_the_answer()).unwrap(); });
406 ///
407 /// select! {
408 ///     _ = rx1.recv() => println!("the long running thread finished first"),
409 ///     answer = rx2.recv() => {
410 ///         println!("the answer was: {}", answer.unwrap());
411 ///     }
412 /// }
413 /// # drop(rx1.recv());
414 /// # drop(rx2.recv());
415 /// ```
416 ///
417 /// For more information about select, see the `std::sync::mpsc::Select` structure.
418 #[macro_export]
419 #[unstable(feature = "mpsc_select", issue = "27800")]
420 #[rustc_deprecated(since = "1.32.0",
421                    reason = "channel selection will be removed in a future release")]
422 macro_rules! select {
423     (
424         $($name:pat = $rx:ident.$meth:ident() => $code:expr),+
425     ) => ({
426         use $crate::sync::mpsc::Select;
427         let sel = Select::new();
428         $( let mut $rx = sel.handle(&$rx); )+
429         unsafe {
430             $( $rx.add(); )+
431         }
432         let ret = sel.wait();
433         $( if ret == $rx.id() { let $name = $rx.$meth(); $code } else )+
434         { unreachable!() }
435     })
436 }
437
438 #[cfg(test)]
439 macro_rules! assert_approx_eq {
440     ($a:expr, $b:expr) => ({
441         let (a, b) = (&$a, &$b);
442         assert!((*a - *b).abs() < 1.0e-6,
443                 "{} is not approximately equal to {}", *a, *b);
444     })
445 }
446
447 /// Built-in macros to the compiler itself.
448 ///
449 /// These macros do not have any corresponding definition with a `macro_rules!`
450 /// macro, but are documented here. Their implementations can be found hardcoded
451 /// into libsyntax itself.
452 #[cfg(rustdoc)]
453 mod builtin {
454
455     /// Causes compilation to fail with the given error message when encountered.
456     ///
457     /// This macro should be used when a crate uses a conditional compilation strategy to provide
458     /// better error messages for erroneous conditions. It's the compiler-level form of [`panic!`],
459     /// which emits an error at *runtime*, rather than during compilation.
460     ///
461     /// # Examples
462     ///
463     /// Two such examples are macros and `#[cfg]` environments.
464     ///
465     /// Emit better compiler error if a macro is passed invalid values. Without the final branch,
466     /// the compiler would still emit an error, but the error's message would not mention the two
467     /// valid values.
468     ///
469     /// ```compile_fail
470     /// macro_rules! give_me_foo_or_bar {
471     ///     (foo) => {};
472     ///     (bar) => {};
473     ///     ($x:ident) => {
474     ///         compile_error!("This macro only accepts `foo` or `bar`");
475     ///     }
476     /// }
477     ///
478     /// give_me_foo_or_bar!(neither);
479     /// // ^ will fail at compile time with message "This macro only accepts `foo` or `bar`"
480     /// ```
481     ///
482     /// Emit compiler error if one of a number of features isn't available.
483     ///
484     /// ```compile_fail
485     /// #[cfg(not(any(feature = "foo", feature = "bar")))]
486     /// compile_error!("Either feature \"foo\" or \"bar\" must be enabled for this crate.")
487     /// ```
488     ///
489     /// [`panic!`]: ../std/macro.panic.html
490     #[stable(feature = "compile_error_macro", since = "1.20.0")]
491     #[rustc_doc_only_macro]
492     macro_rules! compile_error {
493         ($msg:expr) => ({ /* compiler built-in */ });
494         ($msg:expr,) => ({ /* compiler built-in */ });
495     }
496
497     /// Constructs parameters for the other string-formatting macros.
498     ///
499     /// This macro functions by taking a formatting string literal containing
500     /// `{}` for each additional argument passed. `format_args!` prepares the
501     /// additional parameters to ensure the output can be interpreted as a string
502     /// and canonicalizes the arguments into a single type. Any value that implements
503     /// the [`Display`] trait can be passed to `format_args!`, as can any
504     /// [`Debug`] implementation be passed to a `{:?}` within the formatting string.
505     ///
506     /// This macro produces a value of type [`fmt::Arguments`]. This value can be
507     /// passed to the macros within [`std::fmt`] for performing useful redirection.
508     /// All other formatting macros ([`format!`], [`write!`], [`println!`], etc) are
509     /// proxied through this one. `format_args!`, unlike its derived macros, avoids
510     /// heap allocations.
511     ///
512     /// You can use the [`fmt::Arguments`] value that `format_args!` returns
513     /// in `Debug` and `Display` contexts as seen below. The example also shows
514     /// that `Debug` and `Display` format to the same thing: the interpolated
515     /// format string in `format_args!`.
516     ///
517     /// ```rust
518     /// let debug = format!("{:?}", format_args!("{} foo {:?}", 1, 2));
519     /// let display = format!("{}", format_args!("{} foo {:?}", 1, 2));
520     /// assert_eq!("1 foo 2", display);
521     /// assert_eq!(display, debug);
522     /// ```
523     ///
524     /// For more information, see the documentation in [`std::fmt`].
525     ///
526     /// [`Display`]: ../std/fmt/trait.Display.html
527     /// [`Debug`]: ../std/fmt/trait.Debug.html
528     /// [`fmt::Arguments`]: ../std/fmt/struct.Arguments.html
529     /// [`std::fmt`]: ../std/fmt/index.html
530     /// [`format!`]: ../std/macro.format.html
531     /// [`write!`]: ../std/macro.write.html
532     /// [`println!`]: ../std/macro.println.html
533     ///
534     /// # Examples
535     ///
536     /// ```
537     /// use std::fmt;
538     ///
539     /// let s = fmt::format(format_args!("hello {}", "world"));
540     /// assert_eq!(s, format!("hello {}", "world"));
541     /// ```
542     #[stable(feature = "rust1", since = "1.0.0")]
543     #[rustc_doc_only_macro]
544     macro_rules! format_args {
545         ($fmt:expr) => ({ /* compiler built-in */ });
546         ($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ });
547     }
548
549     /// Inspects an environment variable at compile time.
550     ///
551     /// This macro will expand to the value of the named environment variable at
552     /// compile time, yielding an expression of type `&'static str`.
553     ///
554     /// If the environment variable is not defined, then a compilation error
555     /// will be emitted. To not emit a compile error, use the [`option_env!`]
556     /// macro instead.
557     ///
558     /// [`option_env!`]: ../std/macro.option_env.html
559     ///
560     /// # Examples
561     ///
562     /// ```
563     /// let path: &'static str = env!("PATH");
564     /// println!("the $PATH variable at the time of compiling was: {}", path);
565     /// ```
566     ///
567     /// You can customize the error message by passing a string as the second
568     /// parameter:
569     ///
570     /// ```compile_fail
571     /// let doc: &'static str = env!("documentation", "what's that?!");
572     /// ```
573     ///
574     /// If the `documentation` environment variable is not defined, you'll get
575     /// the following error:
576     ///
577     /// ```text
578     /// error: what's that?!
579     /// ```
580     #[stable(feature = "rust1", since = "1.0.0")]
581     #[rustc_doc_only_macro]
582     macro_rules! env {
583         ($name:expr) => ({ /* compiler built-in */ });
584         ($name:expr,) => ({ /* compiler built-in */ });
585     }
586
587     /// Optionally inspects an environment variable at compile time.
588     ///
589     /// If the named environment variable is present at compile time, this will
590     /// expand into an expression of type `Option<&'static str>` whose value is
591     /// `Some` of the value of the environment variable. If the environment
592     /// variable is not present, then this will expand to `None`. See
593     /// [`Option<T>`][option] for more information on this type.
594     ///
595     /// A compile time error is never emitted when using this macro regardless
596     /// of whether the environment variable is present or not.
597     ///
598     /// [option]: ../std/option/enum.Option.html
599     ///
600     /// # Examples
601     ///
602     /// ```
603     /// let key: Option<&'static str> = option_env!("SECRET_KEY");
604     /// println!("the secret key might be: {:?}", key);
605     /// ```
606     #[stable(feature = "rust1", since = "1.0.0")]
607     #[rustc_doc_only_macro]
608     macro_rules! option_env {
609         ($name:expr) => ({ /* compiler built-in */ });
610         ($name:expr,) => ({ /* compiler built-in */ });
611     }
612
613     /// Concatenates identifiers into one identifier.
614     ///
615     /// This macro takes any number of comma-separated identifiers, and
616     /// concatenates them all into one, yielding an expression which is a new
617     /// identifier. Note that hygiene makes it such that this macro cannot
618     /// capture local variables. Also, as a general rule, macros are only
619     /// allowed in item, statement or expression position. That means while
620     /// you may use this macro for referring to existing variables, functions or
621     /// modules etc, you cannot define a new one with it.
622     ///
623     /// # Examples
624     ///
625     /// ```
626     /// #![feature(concat_idents)]
627     ///
628     /// # fn main() {
629     /// fn foobar() -> u32 { 23 }
630     ///
631     /// let f = concat_idents!(foo, bar);
632     /// println!("{}", f());
633     ///
634     /// // fn concat_idents!(new, fun, name) { } // not usable in this way!
635     /// # }
636     /// ```
637     #[unstable(feature = "concat_idents_macro", issue = "29599")]
638     #[rustc_doc_only_macro]
639     macro_rules! concat_idents {
640         ($($e:ident),+) => ({ /* compiler built-in */ });
641         ($($e:ident,)+) => ({ /* compiler built-in */ });
642     }
643
644     /// Concatenates literals into a static string slice.
645     ///
646     /// This macro takes any number of comma-separated literals, yielding an
647     /// expression of type `&'static str` which represents all of the literals
648     /// concatenated left-to-right.
649     ///
650     /// Integer and floating point literals are stringified in order to be
651     /// concatenated.
652     ///
653     /// # Examples
654     ///
655     /// ```
656     /// let s = concat!("test", 10, 'b', true);
657     /// assert_eq!(s, "test10btrue");
658     /// ```
659     #[stable(feature = "rust1", since = "1.0.0")]
660     #[rustc_doc_only_macro]
661     macro_rules! concat {
662         ($($e:expr),*) => ({ /* compiler built-in */ });
663         ($($e:expr,)*) => ({ /* compiler built-in */ });
664     }
665
666     /// Expands to the line number on which it was invoked.
667     ///
668     /// With [`column!`] and [`file!`], these macros provide debugging information for
669     /// developers about the location within the source.
670     ///
671     /// The expanded expression has type `u32` and is 1-based, so the first line
672     /// in each file evaluates to 1, the second to 2, etc. This is consistent
673     /// with error messages by common compilers or popular editors.
674     /// The returned line is *not necessarily* the line of the `line!` invocation itself,
675     /// but rather the first macro invocation leading up to the invocation
676     /// of the `line!` macro.
677     ///
678     /// [`column!`]: macro.column.html
679     /// [`file!`]: macro.file.html
680     ///
681     /// # Examples
682     ///
683     /// ```
684     /// let current_line = line!();
685     /// println!("defined on line: {}", current_line);
686     /// ```
687     #[stable(feature = "rust1", since = "1.0.0")]
688     #[rustc_doc_only_macro]
689     macro_rules! line { () => ({ /* compiler built-in */ }) }
690
691     /// Expands to the column number at which it was invoked.
692     ///
693     /// With [`line!`] and [`file!`], these macros provide debugging information for
694     /// developers about the location within the source.
695     ///
696     /// The expanded expression has type `u32` and is 1-based, so the first column
697     /// in each line evaluates to 1, the second to 2, etc. This is consistent
698     /// with error messages by common compilers or popular editors.
699     /// The returned column is *not necessarily* the line of the `column!` invocation itself,
700     /// but rather the first macro invocation leading up to the invocation
701     /// of the `column!` macro.
702     ///
703     /// [`line!`]: macro.line.html
704     /// [`file!`]: macro.file.html
705     ///
706     /// # Examples
707     ///
708     /// ```
709     /// let current_col = column!();
710     /// println!("defined on column: {}", current_col);
711     /// ```
712     #[stable(feature = "rust1", since = "1.0.0")]
713     #[rustc_doc_only_macro]
714     macro_rules! column { () => ({ /* compiler built-in */ }) }
715
716     /// Expands to the file name in which it was invoked.
717     ///
718     /// With [`line!`] and [`column!`], these macros provide debugging information for
719     /// developers about the location within the source.
720     ///
721     ///
722     /// The expanded expression has type `&'static str`, and the returned file
723     /// is not the invocation of the `file!` macro itself, but rather the
724     /// first macro invocation leading up to the invocation of the `file!`
725     /// macro.
726     ///
727     /// [`line!`]: macro.line.html
728     /// [`column!`]: macro.column.html
729     ///
730     /// # Examples
731     ///
732     /// ```
733     /// let this_file = file!();
734     /// println!("defined in file: {}", this_file);
735     /// ```
736     #[stable(feature = "rust1", since = "1.0.0")]
737     #[rustc_doc_only_macro]
738     macro_rules! file { () => ({ /* compiler built-in */ }) }
739
740     /// Stringifies its arguments.
741     ///
742     /// This macro will yield an expression of type `&'static str` which is the
743     /// stringification of all the tokens passed to the macro. No restrictions
744     /// are placed on the syntax of the macro invocation itself.
745     ///
746     /// Note that the expanded results of the input tokens may change in the
747     /// future. You should be careful if you rely on the output.
748     ///
749     /// # Examples
750     ///
751     /// ```
752     /// let one_plus_one = stringify!(1 + 1);
753     /// assert_eq!(one_plus_one, "1 + 1");
754     /// ```
755     #[stable(feature = "rust1", since = "1.0.0")]
756     #[rustc_doc_only_macro]
757     macro_rules! stringify { ($($t:tt)*) => ({ /* compiler built-in */ }) }
758
759     /// Includes a utf8-encoded file as a string.
760     ///
761     /// The file is located relative to the current file. (similarly to how
762     /// modules are found)
763     ///
764     /// This macro will yield an expression of type `&'static str` which is the
765     /// contents of the file.
766     ///
767     /// # Examples
768     ///
769     /// Assume there are two files in the same directory with the following
770     /// contents:
771     ///
772     /// File 'spanish.in':
773     ///
774     /// ```text
775     /// adiรณs
776     /// ```
777     ///
778     /// File 'main.rs':
779     ///
780     /// ```ignore (cannot-doctest-external-file-dependency)
781     /// fn main() {
782     ///     let my_str = include_str!("spanish.in");
783     ///     assert_eq!(my_str, "adiรณs\n");
784     ///     print!("{}", my_str);
785     /// }
786     /// ```
787     ///
788     /// Compiling 'main.rs' and running the resulting binary will print "adiรณs".
789     #[stable(feature = "rust1", since = "1.0.0")]
790     #[rustc_doc_only_macro]
791     macro_rules! include_str {
792         ($file:expr) => ({ /* compiler built-in */ });
793         ($file:expr,) => ({ /* compiler built-in */ });
794     }
795
796     /// Includes a file as a reference to a byte array.
797     ///
798     /// The file is located relative to the current file. (similarly to how
799     /// modules are found)
800     ///
801     /// This macro will yield an expression of type `&'static [u8; N]` which is
802     /// the contents of the file.
803     ///
804     /// # Examples
805     ///
806     /// Assume there are two files in the same directory with the following
807     /// contents:
808     ///
809     /// File 'spanish.in':
810     ///
811     /// ```text
812     /// adiรณs
813     /// ```
814     ///
815     /// File 'main.rs':
816     ///
817     /// ```ignore (cannot-doctest-external-file-dependency)
818     /// fn main() {
819     ///     let bytes = include_bytes!("spanish.in");
820     ///     assert_eq!(bytes, b"adi\xc3\xb3s\n");
821     ///     print!("{}", String::from_utf8_lossy(bytes));
822     /// }
823     /// ```
824     ///
825     /// Compiling 'main.rs' and running the resulting binary will print "adiรณs".
826     #[stable(feature = "rust1", since = "1.0.0")]
827     #[rustc_doc_only_macro]
828     macro_rules! include_bytes {
829         ($file:expr) => ({ /* compiler built-in */ });
830         ($file:expr,) => ({ /* compiler built-in */ });
831     }
832
833     /// Expands to a string that represents the current module path.
834     ///
835     /// The current module path can be thought of as the hierarchy of modules
836     /// leading back up to the crate root. The first component of the path
837     /// returned is the name of the crate currently being compiled.
838     ///
839     /// # Examples
840     ///
841     /// ```
842     /// mod test {
843     ///     pub fn foo() {
844     ///         assert!(module_path!().ends_with("test"));
845     ///     }
846     /// }
847     ///
848     /// test::foo();
849     /// ```
850     #[stable(feature = "rust1", since = "1.0.0")]
851     #[rustc_doc_only_macro]
852     macro_rules! module_path { () => ({ /* compiler built-in */ }) }
853
854     /// Evaluates boolean combinations of configuration flags at compile-time.
855     ///
856     /// In addition to the `#[cfg]` attribute, this macro is provided to allow
857     /// boolean expression evaluation of configuration flags. This frequently
858     /// leads to less duplicated code.
859     ///
860     /// The syntax given to this macro is the same syntax as the [`cfg`]
861     /// attribute.
862     ///
863     /// [`cfg`]: ../reference/conditional-compilation.html#the-cfg-attribute
864     ///
865     /// # Examples
866     ///
867     /// ```
868     /// let my_directory = if cfg!(windows) {
869     ///     "windows-specific-directory"
870     /// } else {
871     ///     "unix-directory"
872     /// };
873     /// ```
874     #[stable(feature = "rust1", since = "1.0.0")]
875     #[rustc_doc_only_macro]
876     macro_rules! cfg { ($($cfg:tt)*) => ({ /* compiler built-in */ }) }
877
878     /// Parses a file as an expression or an item according to the context.
879     ///
880     /// The file is located relative to the current file (similarly to how
881     /// modules are found).
882     ///
883     /// Using this macro is often a bad idea, because if the file is
884     /// parsed as an expression, it is going to be placed in the
885     /// surrounding code unhygienically. This could result in variables
886     /// or functions being different from what the file expected if
887     /// there are variables or functions that have the same name in
888     /// the current file.
889     ///
890     /// # Examples
891     ///
892     /// Assume there are two files in the same directory with the following
893     /// contents:
894     ///
895     /// File 'monkeys.in':
896     ///
897     /// ```ignore (only-for-syntax-highlight)
898     /// ['๐Ÿ™ˆ', '๐Ÿ™Š', '๐Ÿ™‰']
899     ///     .iter()
900     ///     .cycle()
901     ///     .take(6)
902     ///     .collect::<String>()
903     /// ```
904     ///
905     /// File 'main.rs':
906     ///
907     /// ```ignore (cannot-doctest-external-file-dependency)
908     /// fn main() {
909     ///     let my_string = include!("monkeys.in");
910     ///     assert_eq!("๐Ÿ™ˆ๐Ÿ™Š๐Ÿ™‰๐Ÿ™ˆ๐Ÿ™Š๐Ÿ™‰", my_string);
911     ///     println!("{}", my_string);
912     /// }
913     /// ```
914     ///
915     /// Compiling 'main.rs' and running the resulting binary will print
916     /// "๐Ÿ™ˆ๐Ÿ™Š๐Ÿ™‰๐Ÿ™ˆ๐Ÿ™Š๐Ÿ™‰".
917     #[stable(feature = "rust1", since = "1.0.0")]
918     #[rustc_doc_only_macro]
919     macro_rules! include {
920         ($file:expr) => ({ /* compiler built-in */ });
921         ($file:expr,) => ({ /* compiler built-in */ });
922     }
923
924     /// Asserts that a boolean expression is `true` at runtime.
925     ///
926     /// This will invoke the [`panic!`] macro if the provided expression cannot be
927     /// evaluated to `true` at runtime.
928     ///
929     /// # Uses
930     ///
931     /// Assertions are always checked in both debug and release builds, and cannot
932     /// be disabled. See [`debug_assert!`] for assertions that are not enabled in
933     /// release builds by default.
934     ///
935     /// Unsafe code relies on `assert!` to enforce run-time invariants that, if
936     /// violated could lead to unsafety.
937     ///
938     /// Other use-cases of `assert!` include testing and enforcing run-time
939     /// invariants in safe code (whose violation cannot result in unsafety).
940     ///
941     /// # Custom Messages
942     ///
943     /// This macro has a second form, where a custom panic message can
944     /// be provided with or without arguments for formatting. See [`std::fmt`]
945     /// for syntax for this form.
946     ///
947     /// [`panic!`]: macro.panic.html
948     /// [`debug_assert!`]: macro.debug_assert.html
949     /// [`std::fmt`]: ../std/fmt/index.html
950     ///
951     /// # Examples
952     ///
953     /// ```
954     /// // the panic message for these assertions is the stringified value of the
955     /// // expression given.
956     /// assert!(true);
957     ///
958     /// fn some_computation() -> bool { true } // a very simple function
959     ///
960     /// assert!(some_computation());
961     ///
962     /// // assert with a custom message
963     /// let x = true;
964     /// assert!(x, "x wasn't true!");
965     ///
966     /// let a = 3; let b = 27;
967     /// assert!(a + b == 30, "a = {}, b = {}", a, b);
968     /// ```
969     #[stable(feature = "rust1", since = "1.0.0")]
970     #[rustc_doc_only_macro]
971     macro_rules! assert {
972         ($cond:expr) => ({ /* compiler built-in */ });
973         ($cond:expr,) => ({ /* compiler built-in */ });
974         ($cond:expr, $($arg:tt)+) => ({ /* compiler built-in */ });
975     }
976 }
977
978 /// Defines `#[cfg]` if-else statements.
979 ///
980 /// This is similar to the `if/elif` C preprocessor macro by allowing definition
981 /// of a cascade of `#[cfg]` cases, emitting the implementation which matches
982 /// first.
983 ///
984 /// This allows you to conveniently provide a long list `#[cfg]`'d blocks of code
985 /// without having to rewrite each clause multiple times.
986 macro_rules! cfg_if {
987     ($(
988         if #[cfg($($meta:meta),*)] { $($it:item)* }
989     ) else * else {
990         $($it2:item)*
991     }) => {
992         __cfg_if_items! {
993             () ;
994             $( ( ($($meta),*) ($($it)*) ), )*
995             ( () ($($it2)*) ),
996         }
997     }
998 }
999
1000 macro_rules! __cfg_if_items {
1001     (($($not:meta,)*) ; ) => {};
1002     (($($not:meta,)*) ; ( ($($m:meta),*) ($($it:item)*) ), $($rest:tt)*) => {
1003         __cfg_if_apply! { cfg(all(not(any($($not),*)), $($m,)*)), $($it)* }
1004         __cfg_if_items! { ($($not,)* $($m,)*) ; $($rest)* }
1005     }
1006 }
1007
1008 macro_rules! __cfg_if_apply {
1009     ($m:meta, $($it:item)*) => {
1010         $(#[$m] $it)*
1011     }
1012 }