]> git.lizzy.rs Git - rust.git/blob - src/libstd/macros.rs
Make column macro output 1 based and document it
[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     ($fmt:expr, $($arg:tt)+) => ({
72         $crate::rt::begin_panic_fmt(&format_args!($fmt, $($arg)+),
73                                     &(file!(), line!(), __rust_unstable_column!()))
74     });
75 }
76
77 /// Macro for printing to the standard output.
78 ///
79 /// Equivalent to the [`println!`] macro except that a newline is not printed at
80 /// the end of the message.
81 ///
82 /// Note that stdout is frequently line-buffered by default so it may be
83 /// necessary to use [`io::stdout().flush()`][flush] to ensure the output is emitted
84 /// immediately.
85 ///
86 /// Use `print!` only for the primary output of your program.  Use
87 /// [`eprint!`] instead to print error and progress messages.
88 ///
89 /// [`println!`]: ../std/macro.println.html
90 /// [flush]: ../std/io/trait.Write.html#tymethod.flush
91 /// [`eprint!`]: ../std/macro.eprint.html
92 ///
93 /// # Panics
94 ///
95 /// Panics if writing to `io::stdout()` fails.
96 ///
97 /// # Examples
98 ///
99 /// ```
100 /// use std::io::{self, Write};
101 ///
102 /// print!("this ");
103 /// print!("will ");
104 /// print!("be ");
105 /// print!("on ");
106 /// print!("the ");
107 /// print!("same ");
108 /// print!("line ");
109 ///
110 /// io::stdout().flush().unwrap();
111 ///
112 /// print!("this string has a newline, why not choose println! instead?\n");
113 ///
114 /// io::stdout().flush().unwrap();
115 /// ```
116 #[macro_export]
117 #[stable(feature = "rust1", since = "1.0.0")]
118 #[allow_internal_unstable]
119 macro_rules! print {
120     ($($arg:tt)*) => ($crate::io::_print(format_args!($($arg)*)));
121 }
122
123 /// Macro for printing to the standard output, with a newline.
124 ///
125 /// On all platforms, the newline is the LINE FEED character (`\n`/`U+000A`) alone
126 /// (no additional CARRIAGE RETURN (`\r`/`U+000D`).
127 ///
128 /// Use the [`format!`] syntax to write data to the standard output.
129 /// See [`std::fmt`] for more information.
130 ///
131 /// Use `println!` only for the primary output of your program.  Use
132 /// [`eprintln!`] instead to print error and progress messages.
133 ///
134 /// [`format!`]: ../std/macro.format.html
135 /// [`std::fmt`]: ../std/fmt/index.html
136 /// [`eprintln!`]: ../std/macro.eprint.html
137 /// # Panics
138 ///
139 /// Panics if writing to `io::stdout` fails.
140 ///
141 /// # Examples
142 ///
143 /// ```
144 /// println!(); // prints just a newline
145 /// println!("hello there!");
146 /// println!("format {} arguments", "some");
147 /// ```
148 #[macro_export]
149 #[stable(feature = "rust1", since = "1.0.0")]
150 macro_rules! println {
151     () => (print!("\n"));
152     ($fmt:expr) => (print!(concat!($fmt, "\n")));
153     ($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
154 }
155
156 /// Macro for printing to the standard error.
157 ///
158 /// Equivalent to the [`print!`] macro, except that output goes to
159 /// [`io::stderr`] instead of `io::stdout`.  See [`print!`] for
160 /// example usage.
161 ///
162 /// Use `eprint!` only for error and progress messages.  Use `print!`
163 /// instead for the primary output of your program.
164 ///
165 /// [`io::stderr`]: ../std/io/struct.Stderr.html
166 /// [`print!`]: ../std/macro.print.html
167 ///
168 /// # Panics
169 ///
170 /// Panics if writing to `io::stderr` fails.
171 ///
172 /// # Examples
173 ///
174 /// ```
175 /// eprint!("Error: Could not complete task");
176 /// ```
177 #[macro_export]
178 #[stable(feature = "eprint", since = "1.19.0")]
179 #[allow_internal_unstable]
180 macro_rules! eprint {
181     ($($arg:tt)*) => ($crate::io::_eprint(format_args!($($arg)*)));
182 }
183
184 /// Macro for printing to the standard error, with a newline.
185 ///
186 /// Equivalent to the [`println!`] macro, except that output goes to
187 /// [`io::stderr`] instead of `io::stdout`.  See [`println!`] for
188 /// example usage.
189 ///
190 /// Use `eprintln!` only for error and progress messages.  Use `println!`
191 /// instead for the primary output of your program.
192 ///
193 /// [`io::stderr`]: ../std/io/struct.Stderr.html
194 /// [`println!`]: ../std/macro.println.html
195 ///
196 /// # Panics
197 ///
198 /// Panics if writing to `io::stderr` fails.
199 ///
200 /// # Examples
201 ///
202 /// ```
203 /// eprintln!("Error: Could not complete task");
204 /// ```
205 #[macro_export]
206 #[stable(feature = "eprint", since = "1.19.0")]
207 macro_rules! eprintln {
208     () => (eprint!("\n"));
209     ($fmt:expr) => (eprint!(concat!($fmt, "\n")));
210     ($fmt:expr, $($arg:tt)*) => (eprint!(concat!($fmt, "\n"), $($arg)*));
211 }
212
213 /// A macro to select an event from a number of receivers.
214 ///
215 /// This macro is used to wait for the first event to occur on a number of
216 /// receivers. It places no restrictions on the types of receivers given to
217 /// this macro, this can be viewed as a heterogeneous select.
218 ///
219 /// # Examples
220 ///
221 /// ```
222 /// #![feature(mpsc_select)]
223 ///
224 /// use std::thread;
225 /// use std::sync::mpsc;
226 ///
227 /// // two placeholder functions for now
228 /// fn long_running_thread() {}
229 /// fn calculate_the_answer() -> u32 { 42 }
230 ///
231 /// let (tx1, rx1) = mpsc::channel();
232 /// let (tx2, rx2) = mpsc::channel();
233 ///
234 /// thread::spawn(move|| { long_running_thread(); tx1.send(()).unwrap(); });
235 /// thread::spawn(move|| { tx2.send(calculate_the_answer()).unwrap(); });
236 ///
237 /// select! {
238 ///     _ = rx1.recv() => println!("the long running thread finished first"),
239 ///     answer = rx2.recv() => {
240 ///         println!("the answer was: {}", answer.unwrap());
241 ///     }
242 /// }
243 /// # drop(rx1.recv());
244 /// # drop(rx2.recv());
245 /// ```
246 ///
247 /// For more information about select, see the `std::sync::mpsc::Select` structure.
248 #[macro_export]
249 #[unstable(feature = "mpsc_select", issue = "27800")]
250 macro_rules! select {
251     (
252         $($name:pat = $rx:ident.$meth:ident() => $code:expr),+
253     ) => ({
254         use $crate::sync::mpsc::Select;
255         let sel = Select::new();
256         $( let mut $rx = sel.handle(&$rx); )+
257         unsafe {
258             $( $rx.add(); )+
259         }
260         let ret = sel.wait();
261         $( if ret == $rx.id() { let $name = $rx.$meth(); $code } else )+
262         { unreachable!() }
263     })
264 }
265
266 #[cfg(test)]
267 macro_rules! assert_approx_eq {
268     ($a:expr, $b:expr) => ({
269         let (a, b) = (&$a, &$b);
270         assert!((*a - *b).abs() < 1.0e-6,
271                 "{} is not approximately equal to {}", *a, *b);
272     })
273 }
274
275 /// Built-in macros to the compiler itself.
276 ///
277 /// These macros do not have any corresponding definition with a `macro_rules!`
278 /// macro, but are documented here. Their implementations can be found hardcoded
279 /// into libsyntax itself.
280 #[cfg(dox)]
281 pub mod builtin {
282
283     /// Unconditionally causes compilation to fail with the given error message when encountered.
284     ///
285     /// This macro should be used when a crate uses a conditional compilation strategy to provide
286     /// better error messages for errornous conditions.
287     ///
288     /// # Examples
289     ///
290     /// Two such examples are macros and `#[cfg]` environments.
291     ///
292     /// Emit better compiler error if a macro is passed invalid values.
293     ///
294     /// ```compile_fail
295     /// macro_rules! give_me_foo_or_bar {
296     ///     (foo) => {};
297     ///     (bar) => {};
298     ///     ($x:ident) => {
299     ///         compile_error!("This macro only accepts `foo` or `bar`");
300     ///     }
301     /// }
302     ///
303     /// give_me_foo_or_bar!(neither);
304     /// // ^ will fail at compile time with message "This macro only accepts `foo` or `bar`"
305     /// ```
306     ///
307     /// Emit compiler error if one of a number of features isn't available.
308     ///
309     /// ```compile_fail
310     /// #[cfg(not(any(feature = "foo", feature = "bar")))]
311     /// compile_error!("Either feature \"foo\" or \"bar\" must be enabled for this crate.")
312     /// ```
313     #[stable(feature = "compile_error_macro", since = "1.20.0")]
314     #[macro_export]
315     macro_rules! compile_error { ($msg:expr) => ({ /* compiler built-in */ }) }
316
317     /// The core macro for formatted string creation & output.
318     ///
319     /// This macro functions by taking a formatting string literal containing
320     /// `{}` for each additional argument passed.  `format_args!` prepares the
321     /// additional parameters to ensure the output can be interpreted as a string
322     /// and canonicalizes the arguments into a single type.  Any value that implements
323     /// the [`Display`] trait can be passed to `format_args!`, as can any
324     /// [`Debug`] implementation be passed to a `{:?}` within the formatting string.
325     ///
326     /// This macro produces a value of type [`fmt::Arguments`]. This value can be
327     /// passed to the macros within [`std::fmt`] for performing useful redirection.
328     /// All other formatting macros ([`format!`], [`write!`], [`println!`], etc) are
329     /// proxied through this one.  `format_args!`, unlike its derived macros, avoids
330     /// heap allocations.
331     ///
332     /// For more information, see the documentation in [`std::fmt`].
333     ///
334     /// [`Display`]: ../std/fmt/trait.Display.html
335     /// [`Debug`]: ../std/fmt/trait.Debug.html
336     /// [`fmt::Arguments`]: ../std/fmt/struct.Arguments.html
337     /// [`std::fmt`]: ../std/fmt/index.html
338     /// [`format!`]: ../std/macro.format.html
339     /// [`write!`]: ../std/macro.write.html
340     /// [`println!`]: ../std/macro.println.html
341     ///
342     /// # Examples
343     ///
344     /// ```
345     /// use std::fmt;
346     ///
347     /// let s = fmt::format(format_args!("hello {}", "world"));
348     /// assert_eq!(s, format!("hello {}", "world"));
349     ///
350     /// ```
351     #[stable(feature = "rust1", since = "1.0.0")]
352     #[macro_export]
353     macro_rules! format_args {
354         ($fmt:expr) => ({ /* compiler built-in */ });
355         ($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ });
356     }
357
358     /// Inspect an environment variable at compile time.
359     ///
360     /// This macro will expand to the value of the named environment variable at
361     /// compile time, yielding an expression of type `&'static str`.
362     ///
363     /// If the environment variable is not defined, then a compilation error
364     /// will be emitted.  To not emit a compile error, use the [`option_env!`]
365     /// macro instead.
366     ///
367     /// [`option_env!`]: ../std/macro.option_env.html
368     ///
369     /// # Examples
370     ///
371     /// ```
372     /// let path: &'static str = env!("PATH");
373     /// println!("the $PATH variable at the time of compiling was: {}", path);
374     /// ```
375     #[stable(feature = "rust1", since = "1.0.0")]
376     #[macro_export]
377     macro_rules! env {
378         ($name:expr) => ({ /* compiler built-in */ });
379         ($name:expr,) => ({ /* compiler built-in */ });
380     }
381
382     /// Optionally inspect an environment variable at compile time.
383     ///
384     /// If the named environment variable is present at compile time, this will
385     /// expand into an expression of type `Option<&'static str>` whose value is
386     /// `Some` of the value of the environment variable. If the environment
387     /// variable is not present, then this will expand to `None`.  See
388     /// [`Option<T>`][option] for more information on this type.
389     ///
390     /// A compile time error is never emitted when using this macro regardless
391     /// of whether the environment variable is present or not.
392     ///
393     /// [option]: ../std/option/enum.Option.html
394     ///
395     /// # Examples
396     ///
397     /// ```
398     /// let key: Option<&'static str> = option_env!("SECRET_KEY");
399     /// println!("the secret key might be: {:?}", key);
400     /// ```
401     #[stable(feature = "rust1", since = "1.0.0")]
402     #[macro_export]
403     macro_rules! option_env { ($name:expr) => ({ /* compiler built-in */ }) }
404
405     /// Concatenate identifiers into one identifier.
406     ///
407     /// This macro takes any number of comma-separated identifiers, and
408     /// concatenates them all into one, yielding an expression which is a new
409     /// identifier. Note that hygiene makes it such that this macro cannot
410     /// capture local variables. Also, as a general rule, macros are only
411     /// allowed in item, statement or expression position. That means while
412     /// you may use this macro for referring to existing variables, functions or
413     /// modules etc, you cannot define a new one with it.
414     ///
415     /// # Examples
416     ///
417     /// ```
418     /// #![feature(concat_idents)]
419     ///
420     /// # fn main() {
421     /// fn foobar() -> u32 { 23 }
422     ///
423     /// let f = concat_idents!(foo, bar);
424     /// println!("{}", f());
425     ///
426     /// // fn concat_idents!(new, fun, name) { } // not usable in this way!
427     /// # }
428     /// ```
429     #[unstable(feature = "concat_idents_macro", issue = "29599")]
430     #[macro_export]
431     macro_rules! concat_idents {
432         ($($e:ident),*) => ({ /* compiler built-in */ });
433         ($($e:ident,)*) => ({ /* compiler built-in */ });
434     }
435
436     /// Concatenates literals into a static string slice.
437     ///
438     /// This macro takes any number of comma-separated literals, yielding an
439     /// expression of type `&'static str` which represents all of the literals
440     /// concatenated left-to-right.
441     ///
442     /// Integer and floating point literals are stringified in order to be
443     /// concatenated.
444     ///
445     /// # Examples
446     ///
447     /// ```
448     /// let s = concat!("test", 10, 'b', true);
449     /// assert_eq!(s, "test10btrue");
450     /// ```
451     #[stable(feature = "rust1", since = "1.0.0")]
452     #[macro_export]
453     macro_rules! concat {
454         ($($e:expr),*) => ({ /* compiler built-in */ });
455         ($($e:expr,)*) => ({ /* compiler built-in */ });
456     }
457
458     /// A macro which expands to the line number on which it was invoked.
459     ///
460     /// With [`column!`] and [`file!`], these macros provide debugging information for
461     /// developers about the location within the source.
462     ///
463     /// The expanded expression has type `u32` and is 1-based, so the first line
464     /// in each file evaluates to 1, the second to 2, etc. This is consistent
465     /// with error messages by common compilers or popular editors.
466     /// The returned column is not the invocation of the `line!` macro itself,
467     /// but rather the first macro invocation leading up to the invocation
468     /// of the `line!` macro.
469     ///
470     /// [`column!`]: macro.column.html
471     /// [`file!`]: macro.file.html
472     ///
473     /// # Examples
474     ///
475     /// ```
476     /// let current_line = line!();
477     /// println!("defined on line: {}", current_line);
478     /// ```
479     #[stable(feature = "rust1", since = "1.0.0")]
480     #[macro_export]
481     macro_rules! line { () => ({ /* compiler built-in */ }) }
482
483     /// A macro which expands to the column number on which it was invoked.
484     ///
485     /// With [`line!`] and [`file!`], these macros provide debugging information for
486     /// developers about the location within the source.
487     ///
488     /// The expanded expression has type `u32` and is 1-based, so the first column
489     /// in each line evaluates to 1, the second to 2, etc. This is consistent
490     /// with error messages by common compilers or popular editors.
491     /// The returned column is not the invocation of the `column!` macro itself,
492     /// but rather the first macro invocation leading up to the invocation
493     /// of the `column!` macro.
494     ///
495     /// [`line!`]: macro.line.html
496     /// [`file!`]: macro.file.html
497     ///
498     /// # Examples
499     ///
500     /// ```
501     /// let current_col = column!();
502     /// println!("defined on column: {}", current_col);
503     /// ```
504     #[stable(feature = "rust1", since = "1.0.0")]
505     #[macro_export]
506     macro_rules! column { () => ({ /* compiler built-in */ }) }
507
508     /// A macro which expands to the file name from which it was invoked.
509     ///
510     /// With [`line!`] and [`column!`], these macros provide debugging information for
511     /// developers about the location within the source.
512     ///
513     ///
514     /// The expanded expression has type `&'static str`, and the returned file
515     /// is not the invocation of the `file!` macro itself, but rather the
516     /// first macro invocation leading up to the invocation of the `file!`
517     /// macro.
518     ///
519     /// [`line!`]: macro.line.html
520     /// [`column!`]: macro.column.html
521     ///
522     /// # Examples
523     ///
524     /// ```
525     /// let this_file = file!();
526     /// println!("defined in file: {}", this_file);
527     /// ```
528     #[stable(feature = "rust1", since = "1.0.0")]
529     #[macro_export]
530     macro_rules! file { () => ({ /* compiler built-in */ }) }
531
532     /// A macro which stringifies its arguments.
533     ///
534     /// This macro will yield an expression of type `&'static str` which is the
535     /// stringification of all the tokens passed to the macro. No restrictions
536     /// are placed on the syntax of the macro invocation itself.
537     ///
538     /// Note that the expanded results of the input tokens may change in the
539     /// future. You should be careful if you rely on the output.
540     ///
541     /// # Examples
542     ///
543     /// ```
544     /// let one_plus_one = stringify!(1 + 1);
545     /// assert_eq!(one_plus_one, "1 + 1");
546     /// ```
547     #[stable(feature = "rust1", since = "1.0.0")]
548     #[macro_export]
549     macro_rules! stringify { ($($t:tt)*) => ({ /* compiler built-in */ }) }
550
551     /// Includes a utf8-encoded file as a string.
552     ///
553     /// The file is located relative to the current file. (similarly to how
554     /// modules are found)
555     ///
556     /// This macro will yield an expression of type `&'static str` which is the
557     /// contents of the file.
558     ///
559     /// # Examples
560     ///
561     /// Assume there are two files in the same directory with the following
562     /// contents:
563     ///
564     /// File 'spanish.in':
565     ///
566     /// ```text
567     /// adiós
568     /// ```
569     ///
570     /// File 'main.rs':
571     ///
572     /// ```ignore (cannot-doctest-external-file-dependency)
573     /// fn main() {
574     ///     let my_str = include_str!("spanish.in");
575     ///     assert_eq!(my_str, "adiós\n");
576     ///     print!("{}", my_str);
577     /// }
578     /// ```
579     ///
580     /// Compiling 'main.rs' and running the resulting binary will print "adiós".
581     #[stable(feature = "rust1", since = "1.0.0")]
582     #[macro_export]
583     macro_rules! include_str { ($file:expr) => ({ /* compiler built-in */ }) }
584
585     /// Includes a file as a reference to a byte array.
586     ///
587     /// The file is located relative to the current file. (similarly to how
588     /// modules are found)
589     ///
590     /// This macro will yield an expression of type `&'static [u8; N]` which is
591     /// the contents of the file.
592     ///
593     /// # Examples
594     ///
595     /// Assume there are two files in the same directory with the following
596     /// contents:
597     ///
598     /// File 'spanish.in':
599     ///
600     /// ```text
601     /// adiós
602     /// ```
603     ///
604     /// File 'main.rs':
605     ///
606     /// ```ignore (cannot-doctest-external-file-dependency)
607     /// fn main() {
608     ///     let bytes = include_bytes!("spanish.in");
609     ///     assert_eq!(bytes, b"adi\xc3\xb3s\n");
610     ///     print!("{}", String::from_utf8_lossy(bytes));
611     /// }
612     /// ```
613     ///
614     /// Compiling 'main.rs' and running the resulting binary will print "adiós".
615     #[stable(feature = "rust1", since = "1.0.0")]
616     #[macro_export]
617     macro_rules! include_bytes { ($file:expr) => ({ /* compiler built-in */ }) }
618
619     /// Expands to a string that represents the current module path.
620     ///
621     /// The current module path can be thought of as the hierarchy of modules
622     /// leading back up to the crate root. The first component of the path
623     /// returned is the name of the crate currently being compiled.
624     ///
625     /// # Examples
626     ///
627     /// ```
628     /// mod test {
629     ///     pub fn foo() {
630     ///         assert!(module_path!().ends_with("test"));
631     ///     }
632     /// }
633     ///
634     /// test::foo();
635     /// ```
636     #[stable(feature = "rust1", since = "1.0.0")]
637     #[macro_export]
638     macro_rules! module_path { () => ({ /* compiler built-in */ }) }
639
640     /// Boolean evaluation of configuration flags, at compile-time.
641     ///
642     /// In addition to the `#[cfg]` attribute, this macro is provided to allow
643     /// boolean expression evaluation of configuration flags. This frequently
644     /// leads to less duplicated code.
645     ///
646     /// The syntax given to this macro is the same syntax as [the `cfg`
647     /// attribute](../book/first-edition/conditional-compilation.html).
648     ///
649     /// # Examples
650     ///
651     /// ```
652     /// let my_directory = if cfg!(windows) {
653     ///     "windows-specific-directory"
654     /// } else {
655     ///     "unix-directory"
656     /// };
657     /// ```
658     #[stable(feature = "rust1", since = "1.0.0")]
659     #[macro_export]
660     macro_rules! cfg { ($($cfg:tt)*) => ({ /* compiler built-in */ }) }
661
662     /// Parse a file as an expression or an item according to the context.
663     ///
664     /// The file is located relative to the current file (similarly to how
665     /// modules are found).
666     ///
667     /// Using this macro is often a bad idea, because if the file is
668     /// parsed as an expression, it is going to be placed in the
669     /// surrounding code unhygienically. This could result in variables
670     /// or functions being different from what the file expected if
671     /// there are variables or functions that have the same name in
672     /// the current file.
673     ///
674     /// # Examples
675     ///
676     /// Assume there are two files in the same directory with the following
677     /// contents:
678     ///
679     /// File 'monkeys.in':
680     ///
681     /// ```ignore (only-for-syntax-highlight)
682     /// ['🙈', '🙊', '🙉']
683     ///     .iter()
684     ///     .cycle()
685     ///     .take(6)
686     ///     .collect::<String>()
687     /// ```
688     ///
689     /// File 'main.rs':
690     ///
691     /// ```ignore (cannot-doctest-external-file-dependency)
692     /// fn main() {
693     ///     let my_string = include!("monkeys.in");
694     ///     assert_eq!("🙈🙊🙉🙈🙊🙉", my_string);
695     ///     println!("{}", my_string);
696     /// }
697     /// ```
698     ///
699     /// Compiling 'main.rs' and running the resulting binary will print
700     /// "🙈🙊🙉🙈🙊🙉".
701     #[stable(feature = "rust1", since = "1.0.0")]
702     #[macro_export]
703     macro_rules! include { ($file:expr) => ({ /* compiler built-in */ }) }
704 }
705
706 /// A macro for defining #[cfg] if-else statements.
707 ///
708 /// This is similar to the `if/elif` C preprocessor macro by allowing definition
709 /// of a cascade of `#[cfg]` cases, emitting the implementation which matches
710 /// first.
711 ///
712 /// This allows you to conveniently provide a long list #[cfg]'d blocks of code
713 /// without having to rewrite each clause multiple times.
714 macro_rules! cfg_if {
715     ($(
716         if #[cfg($($meta:meta),*)] { $($it:item)* }
717     ) else * else {
718         $($it2:item)*
719     }) => {
720         __cfg_if_items! {
721             () ;
722             $( ( ($($meta),*) ($($it)*) ), )*
723             ( () ($($it2)*) ),
724         }
725     }
726 }
727
728 macro_rules! __cfg_if_items {
729     (($($not:meta,)*) ; ) => {};
730     (($($not:meta,)*) ; ( ($($m:meta),*) ($($it:item)*) ), $($rest:tt)*) => {
731         __cfg_if_apply! { cfg(all(not(any($($not),*)), $($m,)*)), $($it)* }
732         __cfg_if_items! { ($($not,)* $($m,)*) ; $($rest)* }
733     }
734 }
735
736 macro_rules! __cfg_if_apply {
737     ($m:meta, $($it:item)*) => {
738         $(#[$m] $it)*
739     }
740 }