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