core/macros/mod.rs
1#[doc = include_str!("panic.md")]
2#[macro_export]
3#[rustc_builtin_macro(core_panic)]
4#[allow_internal_unstable(edition_panic)]
5#[stable(feature = "core", since = "1.6.0")]
6#[rustc_diagnostic_item = "core_panic_macro"]
7macro_rules! panic {
8 // Expands to either `$crate::panic::panic_2015` or `$crate::panic::panic_2021`
9 // depending on the edition of the caller.
10 ($($arg:tt)*) => {
11 /* compiler built-in */
12 };
13}
14
15/// Asserts that two expressions are equal to each other (using [`PartialEq`]).
16///
17/// Assertions are always checked in both debug and release builds, and cannot
18/// be disabled. See [`debug_assert_eq!`] for assertions that are disabled in
19/// release builds by default.
20///
21/// [`debug_assert_eq!`]: crate::debug_assert_eq
22///
23/// On panic, this macro will print the values of the expressions with their
24/// debug representations.
25///
26/// Like [`assert!`], this macro has a second form, where a custom
27/// panic message can be provided.
28///
29/// # Examples
30///
31/// ```
32/// let a = 3;
33/// let b = 1 + 2;
34/// assert_eq!(a, b);
35///
36/// assert_eq!(a, b, "we are testing addition with {} and {}", a, b);
37/// ```
38#[macro_export]
39#[stable(feature = "rust1", since = "1.0.0")]
40#[rustc_diagnostic_item = "assert_eq_macro"]
41#[allow_internal_unstable(panic_internals)]
42macro_rules! assert_eq {
43 ($left:expr, $right:expr $(,)?) => {
44 match (&$left, &$right) {
45 (left_val, right_val) => {
46 if !(*left_val == *right_val) {
47 let kind = $crate::panicking::AssertKind::Eq;
48 // The reborrows below are intentional. Without them, the stack slot for the
49 // borrow is initialized even before the values are compared, leading to a
50 // noticeable slow down.
51 $crate::panicking::assert_failed(kind, &*left_val, &*right_val, $crate::option::Option::None);
52 }
53 }
54 }
55 };
56 ($left:expr, $right:expr, $($arg:tt)+) => {
57 match (&$left, &$right) {
58 (left_val, right_val) => {
59 if !(*left_val == *right_val) {
60 let kind = $crate::panicking::AssertKind::Eq;
61 // The reborrows below are intentional. Without them, the stack slot for the
62 // borrow is initialized even before the values are compared, leading to a
63 // noticeable slow down.
64 $crate::panicking::assert_failed(kind, &*left_val, &*right_val, $crate::option::Option::Some($crate::format_args!($($arg)+)));
65 }
66 }
67 }
68 };
69}
70
71/// Asserts that two expressions are not equal to each other (using [`PartialEq`]).
72///
73/// Assertions are always checked in both debug and release builds, and cannot
74/// be disabled. See [`debug_assert_ne!`] for assertions that are disabled in
75/// release builds by default.
76///
77/// [`debug_assert_ne!`]: crate::debug_assert_ne
78///
79/// On panic, this macro will print the values of the expressions with their
80/// debug representations.
81///
82/// Like [`assert!`], this macro has a second form, where a custom
83/// panic message can be provided.
84///
85/// # Examples
86///
87/// ```
88/// let a = 3;
89/// let b = 2;
90/// assert_ne!(a, b);
91///
92/// assert_ne!(a, b, "we are testing that the values are not equal");
93/// ```
94#[macro_export]
95#[stable(feature = "assert_ne", since = "1.13.0")]
96#[rustc_diagnostic_item = "assert_ne_macro"]
97#[allow_internal_unstable(panic_internals)]
98macro_rules! assert_ne {
99 ($left:expr, $right:expr $(,)?) => {
100 match (&$left, &$right) {
101 (left_val, right_val) => {
102 if *left_val == *right_val {
103 let kind = $crate::panicking::AssertKind::Ne;
104 // The reborrows below are intentional. Without them, the stack slot for the
105 // borrow is initialized even before the values are compared, leading to a
106 // noticeable slow down.
107 $crate::panicking::assert_failed(kind, &*left_val, &*right_val, $crate::option::Option::None);
108 }
109 }
110 }
111 };
112 ($left:expr, $right:expr, $($arg:tt)+) => {
113 match (&($left), &($right)) {
114 (left_val, right_val) => {
115 if *left_val == *right_val {
116 let kind = $crate::panicking::AssertKind::Ne;
117 // The reborrows below are intentional. Without them, the stack slot for the
118 // borrow is initialized even before the values are compared, leading to a
119 // noticeable slow down.
120 $crate::panicking::assert_failed(kind, &*left_val, &*right_val, $crate::option::Option::Some($crate::format_args!($($arg)+)));
121 }
122 }
123 }
124 };
125}
126
127// FIXME add back debug_assert_matches doc link after bootstrap.
128
129/// Asserts that an expression matches the provided pattern.
130///
131/// This macro is generally preferable to `assert!(matches!(value, pattern))`, because it can print
132/// the debug representation of the actual value shape that did not meet expectations. In contrast,
133/// using [`assert!`] will only print that expectations were not met, but not why.
134///
135/// The pattern syntax is exactly the same as found in a match arm and the `matches!` macro. The
136/// optional if guard can be used to add additional checks that must be true for the matched value,
137/// otherwise this macro will panic.
138///
139/// Assertions are always checked in both debug and release builds, and cannot
140/// be disabled. See `debug_assert_matches!` for assertions that are disabled in
141/// release builds by default.
142///
143/// On panic, this macro will print the value of the expression with its debug representation.
144///
145/// Like [`assert!`], this macro has a second form, where a custom panic message can be provided.
146///
147/// # Examples
148///
149/// ```
150/// use std::assert_matches;
151///
152/// let a = Some(345);
153/// let b = Some(56);
154/// assert_matches!(a, Some(_));
155/// assert_matches!(b, Some(_));
156///
157/// assert_matches!(a, Some(345));
158/// assert_matches!(a, Some(345) | None);
159///
160/// // assert_matches!(a, None); // panics
161/// // assert_matches!(b, Some(345)); // panics
162/// // assert_matches!(b, Some(345) | None); // panics
163///
164/// assert_matches!(a, Some(x) if x > 100);
165/// // assert_matches!(a, Some(x) if x < 100); // panics
166/// ```
167#[stable(feature = "assert_matches", since = "CURRENT_RUSTC_VERSION")]
168#[allow_internal_unstable(panic_internals)]
169#[rustc_macro_transparency = "semiopaque"]
170pub macro assert_matches {
171 ($left:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => {
172 match $left {
173 $( $pattern )|+ $( if $guard )? => {}
174 ref left_val => {
175 $crate::panicking::assert_matches_failed(
176 left_val,
177 $crate::stringify!($($pattern)|+ $(if $guard)?),
178 $crate::option::Option::None
179 );
180 }
181 }
182 },
183 ($left:expr, $(|)? $( $pattern:pat_param )|+ $( if $guard: expr )?, $($arg:tt)+) => {
184 match $left {
185 $( $pattern )|+ $( if $guard )? => {}
186 ref left_val => {
187 $crate::panicking::assert_matches_failed(
188 left_val,
189 $crate::stringify!($($pattern)|+ $(if $guard)?),
190 $crate::option::Option::Some($crate::format_args!($($arg)+))
191 );
192 }
193 }
194 },
195}
196
197/// Selects code at compile-time based on `cfg` predicates.
198///
199/// This macro evaluates, at compile-time, a series of `cfg` predicates,
200/// selects the first that is true, and emits the code guarded by that
201/// predicate. The code guarded by other predicates is not emitted.
202///
203/// An optional trailing `_` wildcard can be used to specify a fallback. If
204/// none of the predicates are true, a [`compile_error`] is emitted.
205///
206/// # Example
207///
208/// ```
209/// #![feature(cfg_select)]
210///
211/// cfg_select! {
212/// unix => {
213/// fn foo() { /* unix specific functionality */ }
214/// }
215/// target_pointer_width = "32" => {
216/// fn foo() { /* non-unix, 32-bit functionality */ }
217/// }
218/// _ => {
219/// fn foo() { /* fallback implementation */ }
220/// }
221/// }
222/// ```
223///
224/// The `cfg_select!` macro can also be used in expression position, with or without braces on the
225/// right-hand side:
226///
227/// ```
228/// #![feature(cfg_select)]
229///
230/// let _some_string = cfg_select! {
231/// unix => "With great power comes great electricity bills",
232/// _ => { "Behind every successful diet is an unwatched pizza" }
233/// };
234/// ```
235#[unstable(feature = "cfg_select", issue = "115585")]
236#[rustc_diagnostic_item = "cfg_select"]
237#[rustc_builtin_macro]
238pub macro cfg_select($($tt:tt)*) {
239 /* compiler built-in */
240}
241
242/// Asserts that a boolean expression is `true` at runtime.
243///
244/// This will invoke the [`panic!`] macro if the provided expression cannot be
245/// evaluated to `true` at runtime.
246///
247/// Like [`assert!`], this macro also has a second version, where a custom panic
248/// message can be provided.
249///
250/// # Uses
251///
252/// Unlike [`assert!`], `debug_assert!` statements are only enabled in non
253/// optimized builds by default. An optimized build will not execute
254/// `debug_assert!` statements unless `-C debug-assertions` is passed to the
255/// compiler. This makes `debug_assert!` useful for checks that are too
256/// expensive to be present in a release build but may be helpful during
257/// development. The result of expanding `debug_assert!` is always type checked.
258///
259/// An unchecked assertion allows a program in an inconsistent state to keep
260/// running, which might have unexpected consequences but does not introduce
261/// unsafety as long as this only happens in safe code. The performance cost
262/// of assertions, however, is not measurable in general. Replacing [`assert!`]
263/// with `debug_assert!` is thus only encouraged after thorough profiling, and
264/// more importantly, only in safe code!
265///
266/// # Examples
267///
268/// ```
269/// // the panic message for these assertions is the stringified value of the
270/// // expression given.
271/// debug_assert!(true);
272///
273/// fn some_expensive_computation() -> bool {
274/// // Some expensive computation here
275/// true
276/// }
277/// debug_assert!(some_expensive_computation());
278///
279/// // assert with a custom message
280/// let x = true;
281/// debug_assert!(x, "x wasn't true!");
282///
283/// let a = 3; let b = 27;
284/// debug_assert!(a + b == 30, "a = {}, b = {}", a, b);
285/// ```
286#[macro_export]
287#[stable(feature = "rust1", since = "1.0.0")]
288#[rustc_diagnostic_item = "debug_assert_macro"]
289#[allow_internal_unstable(edition_panic)]
290macro_rules! debug_assert {
291 ($($arg:tt)*) => {
292 if $crate::cfg!(debug_assertions) {
293 $crate::assert!($($arg)*);
294 }
295 };
296}
297
298/// Asserts that two expressions are equal to each other.
299///
300/// On panic, this macro will print the values of the expressions with their
301/// debug representations.
302///
303/// Unlike [`assert_eq!`], `debug_assert_eq!` statements are only enabled in non
304/// optimized builds by default. An optimized build will not execute
305/// `debug_assert_eq!` statements unless `-C debug-assertions` is passed to the
306/// compiler. This makes `debug_assert_eq!` useful for checks that are too
307/// expensive to be present in a release build but may be helpful during
308/// development. The result of expanding `debug_assert_eq!` is always type checked.
309///
310/// # Examples
311///
312/// ```
313/// let a = 3;
314/// let b = 1 + 2;
315/// debug_assert_eq!(a, b);
316/// ```
317#[macro_export]
318#[stable(feature = "rust1", since = "1.0.0")]
319#[rustc_diagnostic_item = "debug_assert_eq_macro"]
320macro_rules! debug_assert_eq {
321 ($($arg:tt)*) => {
322 if $crate::cfg!(debug_assertions) {
323 $crate::assert_eq!($($arg)*);
324 }
325 };
326}
327
328/// Asserts that two expressions are not equal to each other.
329///
330/// On panic, this macro will print the values of the expressions with their
331/// debug representations.
332///
333/// Unlike [`assert_ne!`], `debug_assert_ne!` statements are only enabled in non
334/// optimized builds by default. An optimized build will not execute
335/// `debug_assert_ne!` statements unless `-C debug-assertions` is passed to the
336/// compiler. This makes `debug_assert_ne!` useful for checks that are too
337/// expensive to be present in a release build but may be helpful during
338/// development. The result of expanding `debug_assert_ne!` is always type checked.
339///
340/// # Examples
341///
342/// ```
343/// let a = 3;
344/// let b = 2;
345/// debug_assert_ne!(a, b);
346/// ```
347#[macro_export]
348#[stable(feature = "assert_ne", since = "1.13.0")]
349#[rustc_diagnostic_item = "debug_assert_ne_macro"]
350macro_rules! debug_assert_ne {
351 ($($arg:tt)*) => {
352 if $crate::cfg!(debug_assertions) {
353 $crate::assert_ne!($($arg)*);
354 }
355 };
356}
357
358/// Asserts that an expression matches the provided pattern.
359///
360/// This macro is generally preferable to `debug_assert!(matches!(value, pattern))`, because it can
361/// print the debug representation of the actual value shape that did not meet expectations. In
362/// contrast, using [`debug_assert!`] will only print that expectations were not met, but not why.
363///
364/// The pattern syntax is exactly the same as found in a match arm and the `matches!` macro. The
365/// optional if guard can be used to add additional checks that must be true for the matched value,
366/// otherwise this macro will panic.
367///
368/// On panic, this macro will print the value of the expression with its debug representation.
369///
370/// Like [`assert!`], this macro has a second form, where a custom panic message can be provided.
371///
372/// Unlike [`assert_matches!`], `debug_assert_matches!` statements are only enabled in non optimized
373/// builds by default. An optimized build will not execute `debug_assert_matches!` statements unless
374/// `-C debug-assertions` is passed to the compiler. This makes `debug_assert_matches!` useful for
375/// checks that are too expensive to be present in a release build but may be helpful during
376/// development. The result of expanding `debug_assert_matches!` is always type checked.
377///
378/// # Examples
379///
380/// ```
381/// use std::debug_assert_matches;
382///
383/// let a = Some(345);
384/// let b = Some(56);
385/// debug_assert_matches!(a, Some(_));
386/// debug_assert_matches!(b, Some(_));
387///
388/// debug_assert_matches!(a, Some(345));
389/// debug_assert_matches!(a, Some(345) | None);
390///
391/// // debug_assert_matches!(a, None); // panics
392/// // debug_assert_matches!(b, Some(345)); // panics
393/// // debug_assert_matches!(b, Some(345) | None); // panics
394///
395/// debug_assert_matches!(a, Some(x) if x > 100);
396/// // debug_assert_matches!(a, Some(x) if x < 100); // panics
397/// ```
398#[stable(feature = "assert_matches", since = "CURRENT_RUSTC_VERSION")]
399#[allow_internal_unstable(assert_matches)]
400#[rustc_macro_transparency = "semiopaque"]
401pub macro debug_assert_matches($($arg:tt)*) {
402 if $crate::cfg!(debug_assertions) {
403 $crate::assert_matches!($($arg)*);
404 }
405}
406
407/// Returns whether the given expression matches the provided pattern.
408///
409/// The pattern syntax is exactly the same as found in a match arm. The optional if guard can be
410/// used to add additional checks that must be true for the matched value, otherwise this macro will
411/// return `false`.
412///
413/// When testing that a value matches a pattern, it's generally preferable to use
414/// [`assert_matches!`] as it will print the debug representation of the value if the assertion
415/// fails.
416///
417/// # Examples
418///
419/// ```
420/// let foo = 'f';
421/// assert!(matches!(foo, 'A'..='Z' | 'a'..='z'));
422///
423/// let bar = Some(4);
424/// assert!(matches!(bar, Some(x) if x > 2));
425/// ```
426#[macro_export]
427#[stable(feature = "matches_macro", since = "1.42.0")]
428#[rustc_diagnostic_item = "matches_macro"]
429#[allow_internal_unstable(non_exhaustive_omitted_patterns_lint, stmt_expr_attributes)]
430macro_rules! matches {
431 ($expression:expr, $pattern:pat $(if $guard:expr)? $(,)?) => {
432 #[allow(non_exhaustive_omitted_patterns)]
433 match $expression {
434 $pattern $(if $guard)? => true,
435 _ => false
436 }
437 };
438}
439
440/// Unwraps a result or propagates its error.
441///
442/// The [`?` operator][propagating-errors] was added to replace `try!`
443/// and should be used instead. Furthermore, `try` is a reserved word
444/// in Rust 2018, so if you must use it, you will need to use the
445/// [raw-identifier syntax][ris]: `r#try`.
446///
447/// [propagating-errors]: https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html#a-shortcut-for-propagating-errors-the--operator
448/// [ris]: https://doc.rust-lang.org/nightly/rust-by-example/compatibility/raw_identifiers.html
449///
450/// `try!` matches the given [`Result`]. In case of the `Ok` variant, the
451/// expression has the value of the wrapped value.
452///
453/// In case of the `Err` variant, it retrieves the inner error. `try!` then
454/// performs conversion using `From`. This provides automatic conversion
455/// between specialized errors and more general ones. The resulting
456/// error is then immediately returned.
457///
458/// Because of the early return, `try!` can only be used in functions that
459/// return [`Result`].
460///
461/// # Examples
462///
463/// ```
464/// use std::io;
465/// use std::fs::File;
466/// use std::io::prelude::*;
467///
468/// enum MyError {
469/// FileWriteError
470/// }
471///
472/// impl From<io::Error> for MyError {
473/// fn from(e: io::Error) -> MyError {
474/// MyError::FileWriteError
475/// }
476/// }
477///
478/// // The preferred method of quick returning Errors
479/// fn write_to_file_question() -> Result<(), MyError> {
480/// let mut file = File::create("my_best_friends.txt")?;
481/// file.write_all(b"This is a list of my best friends.")?;
482/// Ok(())
483/// }
484///
485/// // The previous method of quick returning Errors
486/// fn write_to_file_using_try() -> Result<(), MyError> {
487/// let mut file = r#try!(File::create("my_best_friends.txt"));
488/// r#try!(file.write_all(b"This is a list of my best friends."));
489/// Ok(())
490/// }
491///
492/// // This is equivalent to:
493/// fn write_to_file_using_match() -> Result<(), MyError> {
494/// let mut file = r#try!(File::create("my_best_friends.txt"));
495/// match file.write_all(b"This is a list of my best friends.") {
496/// Ok(v) => v,
497/// Err(e) => return Err(From::from(e)),
498/// }
499/// Ok(())
500/// }
501/// ```
502#[macro_export]
503#[stable(feature = "rust1", since = "1.0.0")]
504#[deprecated(since = "1.39.0", note = "use the `?` operator instead")]
505#[doc(alias = "?")]
506macro_rules! r#try {
507 ($expr:expr $(,)?) => {
508 match $expr {
509 $crate::result::Result::Ok(val) => val,
510 $crate::result::Result::Err(err) => {
511 return $crate::result::Result::Err($crate::convert::From::from(err));
512 }
513 }
514 };
515}
516
517/// Writes formatted data into a buffer.
518///
519/// This macro accepts a 'writer', a format string, and a list of arguments. Arguments will be
520/// formatted according to the specified format string and the result will be passed to the writer.
521/// The writer may be any value with a `write_fmt` method; generally this comes from an
522/// implementation of either the [`fmt::Write`] or the [`io::Write`] trait. The macro
523/// returns whatever the `write_fmt` method returns; commonly a [`fmt::Result`], or an
524/// [`io::Result`].
525///
526/// See [`std::fmt`] for more information on the format string syntax.
527///
528/// [`std::fmt`]: ../std/fmt/index.html
529/// [`fmt::Write`]: crate::fmt::Write
530/// [`io::Write`]: ../std/io/trait.Write.html
531/// [`fmt::Result`]: crate::fmt::Result
532/// [`io::Result`]: ../std/io/type.Result.html
533///
534/// # Examples
535///
536/// ```
537/// use std::io::Write;
538///
539/// fn main() -> std::io::Result<()> {
540/// let mut w = Vec::new();
541/// write!(&mut w, "test")?;
542/// write!(&mut w, "formatted {}", "arguments")?;
543///
544/// assert_eq!(w, b"testformatted arguments");
545/// Ok(())
546/// }
547/// ```
548///
549/// A module can import both `std::fmt::Write` and `std::io::Write` and call `write!` on objects
550/// implementing either, as objects do not typically implement both. However, the module must
551/// avoid conflict between the trait names, such as by importing them as `_` or otherwise renaming
552/// them:
553///
554/// ```
555/// use std::fmt::Write as _;
556/// use std::io::Write as _;
557///
558/// fn main() -> Result<(), Box<dyn std::error::Error>> {
559/// let mut s = String::new();
560/// let mut v = Vec::new();
561///
562/// write!(&mut s, "{} {}", "abc", 123)?; // uses fmt::Write::write_fmt
563/// write!(&mut v, "s = {:?}", s)?; // uses io::Write::write_fmt
564/// assert_eq!(v, b"s = \"abc 123\"");
565/// Ok(())
566/// }
567/// ```
568///
569/// If you also need the trait names themselves, such as to implement one or both on your types,
570/// import the containing module and then name them with a prefix:
571///
572/// ```
573/// # #![allow(unused_imports)]
574/// use std::fmt::{self, Write as _};
575/// use std::io::{self, Write as _};
576///
577/// struct Example;
578///
579/// impl fmt::Write for Example {
580/// fn write_str(&mut self, _s: &str) -> core::fmt::Result {
581/// unimplemented!();
582/// }
583/// }
584/// ```
585///
586/// Note: This macro can be used in `no_std` setups as well.
587/// In a `no_std` setup you are responsible for the implementation details of the components.
588///
589/// ```no_run
590/// use core::fmt::Write;
591///
592/// struct Example;
593///
594/// impl Write for Example {
595/// fn write_str(&mut self, _s: &str) -> core::fmt::Result {
596/// unimplemented!();
597/// }
598/// }
599///
600/// let mut m = Example{};
601/// write!(&mut m, "Hello World").expect("Not written");
602/// ```
603#[macro_export]
604#[stable(feature = "rust1", since = "1.0.0")]
605#[rustc_diagnostic_item = "write_macro"]
606macro_rules! write {
607 ($dst:expr, $($arg:tt)*) => {
608 $dst.write_fmt($crate::format_args!($($arg)*))
609 };
610}
611
612/// Writes formatted data into a buffer, with a newline appended.
613///
614/// On all platforms, the newline is the LINE FEED character (`\n`/`U+000A`) alone
615/// (no additional CARRIAGE RETURN (`\r`/`U+000D`).
616///
617/// For more information, see [`write!`]. For information on the format string syntax, see
618/// [`std::fmt`].
619///
620/// [`std::fmt`]: ../std/fmt/index.html
621///
622/// # Examples
623///
624/// ```
625/// use std::io::{Write, Result};
626///
627/// fn main() -> Result<()> {
628/// let mut w = Vec::new();
629/// writeln!(&mut w)?;
630/// writeln!(&mut w, "test")?;
631/// writeln!(&mut w, "formatted {}", "arguments")?;
632///
633/// assert_eq!(&w[..], "\ntest\nformatted arguments\n".as_bytes());
634/// Ok(())
635/// }
636/// ```
637#[macro_export]
638#[stable(feature = "rust1", since = "1.0.0")]
639#[rustc_diagnostic_item = "writeln_macro"]
640#[allow_internal_unstable(format_args_nl)]
641macro_rules! writeln {
642 ($dst:expr $(,)?) => {
643 $crate::write!($dst, "\n")
644 };
645 ($dst:expr, $($arg:tt)*) => {
646 $dst.write_fmt($crate::format_args_nl!($($arg)*))
647 };
648}
649
650/// Indicates unreachable code.
651///
652/// This is useful any time that the compiler can't determine that some code is unreachable. For
653/// example:
654///
655/// * Match arms with guard conditions.
656/// * Loops that dynamically terminate.
657/// * Iterators that dynamically terminate.
658///
659/// If the determination that the code is unreachable proves incorrect, the
660/// program immediately terminates with a [`panic!`].
661///
662/// The unsafe counterpart of this macro is the [`unreachable_unchecked`] function, which
663/// will cause undefined behavior if the code is reached.
664///
665/// [`unreachable_unchecked`]: crate::hint::unreachable_unchecked
666///
667/// # Panics
668///
669/// This will always [`panic!`] because `unreachable!` is just a shorthand for `panic!` with a
670/// fixed, specific message.
671///
672/// Like `panic!`, this macro has a second form for displaying custom values.
673///
674/// # Examples
675///
676/// Match arms:
677///
678/// ```
679/// # #[allow(dead_code)]
680/// fn foo(x: Option<i32>) {
681/// match x {
682/// Some(n) if n >= 0 => println!("Some(Non-negative)"),
683/// Some(n) if n < 0 => println!("Some(Negative)"),
684/// Some(_) => unreachable!(), // compile error if commented out
685/// None => println!("None")
686/// }
687/// }
688/// ```
689///
690/// Iterators:
691///
692/// ```
693/// # #[allow(dead_code)]
694/// fn divide_by_three(x: u32) -> u32 { // one of the poorest implementations of x/3
695/// for i in 0.. {
696/// if 3*i < i { panic!("u32 overflow"); }
697/// if x < 3*i { return i-1; }
698/// }
699/// unreachable!("The loop should always return");
700/// }
701/// ```
702#[macro_export]
703#[rustc_builtin_macro(unreachable)]
704#[allow_internal_unstable(edition_panic)]
705#[stable(feature = "rust1", since = "1.0.0")]
706#[rustc_diagnostic_item = "unreachable_macro"]
707macro_rules! unreachable {
708 // Expands to either `$crate::panic::unreachable_2015` or `$crate::panic::unreachable_2021`
709 // depending on the edition of the caller.
710 ($($arg:tt)*) => {
711 /* compiler built-in */
712 };
713}
714
715/// Indicates unimplemented code by panicking with a message of "not implemented".
716///
717/// This allows your code to type-check, which is useful if you are prototyping or
718/// implementing a trait that requires multiple methods which you don't plan to use all of.
719///
720/// The difference between `unimplemented!` and [`todo!`] is that while `todo!`
721/// conveys an intent of implementing the functionality later and the message is "not yet
722/// implemented", `unimplemented!` makes no such claims. Its message is "not implemented".
723///
724/// Also, some IDEs will mark `todo!`s.
725///
726/// # Panics
727///
728/// This will always [`panic!`] because `unimplemented!` is just a shorthand for `panic!` with a
729/// fixed, specific message.
730///
731/// Like `panic!`, this macro has a second form for displaying custom values.
732///
733/// [`todo!`]: crate::todo
734///
735/// # Examples
736///
737/// Say we have a trait `Foo`:
738///
739/// ```
740/// trait Foo {
741/// fn bar(&self) -> u8;
742/// fn baz(&self);
743/// fn qux(&self) -> Result<u64, ()>;
744/// }
745/// ```
746///
747/// We want to implement `Foo` for 'MyStruct', but for some reason it only makes sense
748/// to implement the `bar()` function. `baz()` and `qux()` will still need to be defined
749/// in our implementation of `Foo`, but we can use `unimplemented!` in their definitions
750/// to allow our code to compile.
751///
752/// We still want to have our program stop running if the unimplemented methods are
753/// reached.
754///
755/// ```
756/// # trait Foo {
757/// # fn bar(&self) -> u8;
758/// # fn baz(&self);
759/// # fn qux(&self) -> Result<u64, ()>;
760/// # }
761/// struct MyStruct;
762///
763/// impl Foo for MyStruct {
764/// fn bar(&self) -> u8 {
765/// 1 + 1
766/// }
767///
768/// fn baz(&self) {
769/// // It makes no sense to `baz` a `MyStruct`, so we have no logic here
770/// // at all.
771/// // This will display "thread 'main' panicked at 'not implemented'".
772/// unimplemented!();
773/// }
774///
775/// fn qux(&self) -> Result<u64, ()> {
776/// // We have some logic here,
777/// // We can add a message to unimplemented! to display our omission.
778/// // This will display:
779/// // "thread 'main' panicked at 'not implemented: MyStruct isn't quxable'".
780/// unimplemented!("MyStruct isn't quxable");
781/// }
782/// }
783///
784/// fn main() {
785/// let s = MyStruct;
786/// s.bar();
787/// }
788/// ```
789#[macro_export]
790#[stable(feature = "rust1", since = "1.0.0")]
791#[rustc_diagnostic_item = "unimplemented_macro"]
792#[allow_internal_unstable(panic_internals)]
793macro_rules! unimplemented {
794 () => {
795 $crate::panicking::panic("not implemented")
796 };
797 ($($arg:tt)+) => {
798 $crate::panic!("not implemented: {}", $crate::format_args!($($arg)+))
799 };
800}
801
802/// Indicates unfinished code.
803///
804/// This can be useful if you are prototyping and just
805/// want a placeholder to let your code pass type analysis.
806///
807/// The difference between [`unimplemented!`] and `todo!` is that while `todo!` conveys
808/// an intent of implementing the functionality later and the message is "not yet
809/// implemented", `unimplemented!` makes no such claims. Its message is "not implemented".
810///
811/// Also, some IDEs will mark `todo!`s.
812///
813/// # Panics
814///
815/// This will always [`panic!`] because `todo!` is just a shorthand for `panic!` with a
816/// fixed, specific message.
817///
818/// Like `panic!`, this macro has a second form for displaying custom values.
819///
820/// # Examples
821///
822/// Here's an example of some in-progress code. We have a trait `Foo`:
823///
824/// ```
825/// trait Foo {
826/// fn bar(&self) -> u8;
827/// fn baz(&self);
828/// fn qux(&self) -> Result<u64, ()>;
829/// }
830/// ```
831///
832/// We want to implement `Foo` on one of our types, but we also want to work on
833/// just `bar()` first. In order for our code to compile, we need to implement
834/// `baz()` and `qux()`, so we can use `todo!`:
835///
836/// ```
837/// # trait Foo {
838/// # fn bar(&self) -> u8;
839/// # fn baz(&self);
840/// # fn qux(&self) -> Result<u64, ()>;
841/// # }
842/// struct MyStruct;
843///
844/// impl Foo for MyStruct {
845/// fn bar(&self) -> u8 {
846/// 1 + 1
847/// }
848///
849/// fn baz(&self) {
850/// // Let's not worry about implementing baz() for now
851/// todo!();
852/// }
853///
854/// fn qux(&self) -> Result<u64, ()> {
855/// // We can add a message to todo! to display our omission.
856/// // This will display:
857/// // "thread 'main' panicked at 'not yet implemented: MyStruct is not yet quxable'".
858/// todo!("MyStruct is not yet quxable");
859/// }
860/// }
861///
862/// fn main() {
863/// let s = MyStruct;
864/// s.bar();
865///
866/// // We aren't even using baz() or qux(), so this is fine.
867/// }
868/// ```
869#[macro_export]
870#[stable(feature = "todo_macro", since = "1.40.0")]
871#[rustc_diagnostic_item = "todo_macro"]
872#[allow_internal_unstable(panic_internals)]
873macro_rules! todo {
874 () => {
875 $crate::panicking::panic("not yet implemented")
876 };
877 ($($arg:tt)+) => {
878 $crate::panic!("not yet implemented: {}", $crate::format_args!($($arg)+))
879 };
880}
881
882/// Definitions of built-in macros.
883///
884/// Most of the macro properties (stability, visibility, etc.) are taken from the source code here,
885/// with exception of expansion functions transforming macro inputs into outputs,
886/// those functions are provided by the compiler.
887pub(crate) mod builtin {
888
889 /// Causes compilation to fail with the given error message when encountered.
890 ///
891 /// This macro should be used when a crate uses a conditional compilation strategy to provide
892 /// better error messages for erroneous conditions. It's the compiler-level form of [`panic!`],
893 /// but emits an error during *compilation* rather than at *runtime*.
894 ///
895 /// # Examples
896 ///
897 /// Two such examples are macros and `#[cfg]` environments.
898 ///
899 /// Emit a better compiler error if a macro is passed invalid values. Without the final branch,
900 /// the compiler would still emit an error, but the error's message would not mention the two
901 /// valid values.
902 ///
903 /// ```compile_fail
904 /// macro_rules! give_me_foo_or_bar {
905 /// (foo) => {};
906 /// (bar) => {};
907 /// ($x:ident) => {
908 /// compile_error!("This macro only accepts `foo` or `bar`");
909 /// }
910 /// }
911 ///
912 /// give_me_foo_or_bar!(neither);
913 /// // ^ will fail at compile time with message "This macro only accepts `foo` or `bar`"
914 /// ```
915 ///
916 /// Emit a compiler error if one of a number of features isn't available.
917 ///
918 /// ```compile_fail
919 /// #[cfg(not(any(feature = "foo", feature = "bar")))]
920 /// compile_error!("Either feature \"foo\" or \"bar\" must be enabled for this crate.");
921 /// ```
922 #[stable(feature = "compile_error_macro", since = "1.20.0")]
923 #[rustc_builtin_macro]
924 #[macro_export]
925 macro_rules! compile_error {
926 ($msg:expr $(,)?) => {{ /* compiler built-in */ }};
927 }
928
929 /// Constructs parameters for the other string-formatting macros.
930 ///
931 /// This macro functions by taking a formatting string literal containing
932 /// `{}` for each additional argument passed. `format_args!` prepares the
933 /// additional parameters to ensure the output can be interpreted as a string
934 /// and canonicalizes the arguments into a single type. Any value that implements
935 /// the [`Display`] trait can be passed to `format_args!`, as can any
936 /// [`Debug`] implementation be passed to a `{:?}` within the formatting string.
937 ///
938 /// This macro produces a value of type [`fmt::Arguments`]. This value can be
939 /// passed to the macros within [`std::fmt`] for performing useful redirection.
940 /// All other formatting macros ([`format!`], [`write!`], [`println!`], etc) are
941 /// proxied through this one. `format_args!`, unlike its derived macros, avoids
942 /// heap allocations.
943 ///
944 /// You can use the [`fmt::Arguments`] value that `format_args!` returns
945 /// in `Debug` and `Display` contexts as seen below. The example also shows
946 /// that `Debug` and `Display` format to the same thing: the interpolated
947 /// format string in `format_args!`.
948 ///
949 /// ```rust
950 /// let args = format_args!("{} foo {:?}", 1, 2);
951 /// let debug = format!("{args:?}");
952 /// let display = format!("{args}");
953 /// assert_eq!("1 foo 2", display);
954 /// assert_eq!(display, debug);
955 /// ```
956 ///
957 /// See [the formatting documentation in `std::fmt`](../std/fmt/index.html)
958 /// for details of the macro argument syntax, and further information.
959 ///
960 /// [`Display`]: crate::fmt::Display
961 /// [`Debug`]: crate::fmt::Debug
962 /// [`fmt::Arguments`]: crate::fmt::Arguments
963 /// [`std::fmt`]: ../std/fmt/index.html
964 /// [`format!`]: ../std/macro.format.html
965 /// [`println!`]: ../std/macro.println.html
966 ///
967 /// # Examples
968 ///
969 /// ```
970 /// use std::fmt;
971 ///
972 /// let s = fmt::format(format_args!("hello {}", "world"));
973 /// assert_eq!(s, format!("hello {}", "world"));
974 /// ```
975 ///
976 /// # Argument lifetimes
977 ///
978 /// Except when no formatting arguments are used,
979 /// the produced `fmt::Arguments` value borrows temporary values.
980 /// To allow it to be stored for later use, the arguments' lifetimes, as well as those of
981 /// temporaries they borrow, may be [extended] when `format_args!` appears in the initializer
982 /// expression of a `let` statement. The syntactic rules used to determine when temporaries'
983 /// lifetimes are extended are documented in the [Reference].
984 ///
985 /// [extended]: ../reference/destructors.html#temporary-lifetime-extension
986 /// [Reference]: ../reference/destructors.html#extending-based-on-expressions
987 #[stable(feature = "rust1", since = "1.0.0")]
988 #[rustc_diagnostic_item = "format_args_macro"]
989 #[allow_internal_unsafe]
990 #[allow_internal_unstable(fmt_internals, fmt_arguments_from_str)]
991 #[rustc_builtin_macro]
992 #[macro_export]
993 macro_rules! format_args {
994 ($fmt:expr) => {{ /* compiler built-in */ }};
995 ($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
996 }
997
998 /// Same as [`format_args`], but can be used in some const contexts.
999 ///
1000 /// This macro is used by the panic macros for the `const_panic` feature.
1001 ///
1002 /// This macro will be removed once `format_args` is allowed in const contexts.
1003 #[unstable(feature = "const_format_args", issue = "none")]
1004 #[allow_internal_unstable(fmt_internals, fmt_arguments_from_str)]
1005 #[rustc_builtin_macro]
1006 #[macro_export]
1007 macro_rules! const_format_args {
1008 ($fmt:expr) => {{ /* compiler built-in */ }};
1009 ($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
1010 }
1011
1012 /// Same as [`format_args`], but adds a newline in the end.
1013 #[unstable(
1014 feature = "format_args_nl",
1015 issue = "none",
1016 reason = "`format_args_nl` is only for internal \
1017 language use and is subject to change"
1018 )]
1019 #[allow_internal_unstable(fmt_internals, fmt_arguments_from_str)]
1020 #[rustc_builtin_macro]
1021 #[doc(hidden)]
1022 #[macro_export]
1023 macro_rules! format_args_nl {
1024 ($fmt:expr) => {{ /* compiler built-in */ }};
1025 ($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
1026 }
1027
1028 /// Inspects an environment variable at compile time.
1029 ///
1030 /// This macro will expand to the value of the named environment variable at
1031 /// compile time, yielding an expression of type `&'static str`. Use
1032 /// [`std::env::var`] instead if you want to read the value at runtime.
1033 ///
1034 /// [`std::env::var`]: ../std/env/fn.var.html
1035 ///
1036 /// If the environment variable is not defined, then a compilation error
1037 /// will be emitted. To not emit a compile error, use the [`option_env!`]
1038 /// macro instead. A compilation error will also be emitted if the
1039 /// environment variable is not a valid Unicode string.
1040 ///
1041 /// # Examples
1042 ///
1043 /// ```
1044 /// let path: &'static str = env!("PATH");
1045 /// println!("the $PATH variable at the time of compiling was: {path}");
1046 /// ```
1047 ///
1048 /// You can customize the error message by passing a string as the second
1049 /// parameter:
1050 ///
1051 /// ```compile_fail
1052 /// let doc: &'static str = env!("documentation", "what's that?!");
1053 /// ```
1054 ///
1055 /// If the `documentation` environment variable is not defined, you'll get
1056 /// the following error:
1057 ///
1058 /// ```text
1059 /// error: what's that?!
1060 /// ```
1061 #[stable(feature = "rust1", since = "1.0.0")]
1062 #[rustc_builtin_macro]
1063 #[macro_export]
1064 #[rustc_diagnostic_item = "env_macro"] // useful for external lints
1065 macro_rules! env {
1066 ($name:expr $(,)?) => {{ /* compiler built-in */ }};
1067 ($name:expr, $error_msg:expr $(,)?) => {{ /* compiler built-in */ }};
1068 }
1069
1070 /// Optionally inspects an environment variable at compile time.
1071 ///
1072 /// If the named environment variable is present at compile time, this will
1073 /// expand into an expression of type `Option<&'static str>` whose value is
1074 /// `Some` of the value of the environment variable (a compilation error
1075 /// will be emitted if the environment variable is not a valid Unicode
1076 /// string). If the environment variable is not present, then this will
1077 /// expand to `None`. See [`Option<T>`][Option] for more information on this
1078 /// type. Use [`std::env::var`] instead if you want to read the value at
1079 /// runtime.
1080 ///
1081 /// [`std::env::var`]: ../std/env/fn.var.html
1082 ///
1083 /// A compile time error is only emitted when using this macro if the
1084 /// environment variable exists and is not a valid Unicode string. To also
1085 /// emit a compile error if the environment variable is not present, use the
1086 /// [`env!`] macro instead.
1087 ///
1088 /// # Examples
1089 ///
1090 /// ```
1091 /// let key: Option<&'static str> = option_env!("SECRET_KEY");
1092 /// println!("the secret key might be: {key:?}");
1093 /// ```
1094 #[stable(feature = "rust1", since = "1.0.0")]
1095 #[rustc_builtin_macro]
1096 #[macro_export]
1097 #[rustc_diagnostic_item = "option_env_macro"] // useful for external lints
1098 macro_rules! option_env {
1099 ($name:expr $(,)?) => {{ /* compiler built-in */ }};
1100 }
1101
1102 /// Concatenates literals into a byte slice.
1103 ///
1104 /// This macro takes any number of comma-separated literals, and concatenates them all into
1105 /// one, yielding an expression of type `&[u8; _]`, which represents all of the literals
1106 /// concatenated left-to-right. The literals passed can be any combination of:
1107 ///
1108 /// - byte literals (`b'r'`)
1109 /// - byte strings (`b"Rust"`)
1110 /// - arrays of bytes/numbers (`[b'A', 66, b'C']`)
1111 ///
1112 /// # Examples
1113 ///
1114 /// ```
1115 /// #![feature(concat_bytes)]
1116 ///
1117 /// # fn main() {
1118 /// let s: &[u8; 6] = concat_bytes!(b'A', b"BC", [68, b'E', 70]);
1119 /// assert_eq!(s, b"ABCDEF");
1120 /// # }
1121 /// ```
1122 #[unstable(feature = "concat_bytes", issue = "87555")]
1123 #[rustc_builtin_macro]
1124 #[macro_export]
1125 macro_rules! concat_bytes {
1126 ($($e:literal),+ $(,)?) => {{ /* compiler built-in */ }};
1127 }
1128
1129 /// Concatenates literals into a static string slice.
1130 ///
1131 /// This macro takes any number of comma-separated literals, yielding an
1132 /// expression of type `&'static str` which represents all of the literals
1133 /// concatenated left-to-right.
1134 ///
1135 /// Integer and floating point literals are [stringified](core::stringify) in order to be
1136 /// concatenated.
1137 ///
1138 /// # Examples
1139 ///
1140 /// ```
1141 /// let s = concat!("test", 10, 'b', true);
1142 /// assert_eq!(s, "test10btrue");
1143 /// ```
1144 #[stable(feature = "rust1", since = "1.0.0")]
1145 #[rustc_builtin_macro]
1146 #[rustc_diagnostic_item = "macro_concat"]
1147 #[macro_export]
1148 macro_rules! concat {
1149 ($($e:expr),* $(,)?) => {{ /* compiler built-in */ }};
1150 }
1151
1152 /// Expands to the line number on which it was invoked.
1153 ///
1154 /// With [`column!`] and [`file!`], these macros provide debugging information for
1155 /// developers about the location within the source.
1156 ///
1157 /// The expanded expression has type `u32` and is 1-based, so the first line
1158 /// in each file evaluates to 1, the second to 2, etc. This is consistent
1159 /// with error messages by common compilers or popular editors.
1160 /// The returned line is *not necessarily* the line of the `line!` invocation itself,
1161 /// but rather the first macro invocation leading up to the invocation
1162 /// of the `line!` macro.
1163 ///
1164 /// # Examples
1165 ///
1166 /// ```
1167 /// let current_line = line!();
1168 /// println!("defined on line: {current_line}");
1169 /// ```
1170 #[stable(feature = "rust1", since = "1.0.0")]
1171 #[rustc_builtin_macro]
1172 #[macro_export]
1173 macro_rules! line {
1174 () => {
1175 /* compiler built-in */
1176 };
1177 }
1178
1179 /// Expands to the column number at which it was invoked.
1180 ///
1181 /// With [`line!`] and [`file!`], these macros provide debugging information for
1182 /// developers about the location within the source.
1183 ///
1184 /// The expanded expression has type `u32` and is 1-based, so the first column
1185 /// in each line evaluates to 1, the second to 2, etc. This is consistent
1186 /// with error messages by common compilers or popular editors.
1187 /// The returned column is *not necessarily* the line of the `column!` invocation itself,
1188 /// but rather the first macro invocation leading up to the invocation
1189 /// of the `column!` macro.
1190 ///
1191 /// # Examples
1192 ///
1193 /// ```
1194 /// let current_col = column!();
1195 /// println!("defined on column: {current_col}");
1196 /// ```
1197 ///
1198 /// `column!` counts Unicode code points, not bytes or graphemes. As a result, the first two
1199 /// invocations return the same value, but the third does not.
1200 ///
1201 /// ```
1202 /// let a = ("foobar", column!()).1;
1203 /// let b = ("人之初性本善", column!()).1;
1204 /// let c = ("f̅o̅o̅b̅a̅r̅", column!()).1; // Uses combining overline (U+0305)
1205 ///
1206 /// assert_eq!(a, b);
1207 /// assert_ne!(b, c);
1208 /// ```
1209 #[stable(feature = "rust1", since = "1.0.0")]
1210 #[rustc_builtin_macro]
1211 #[macro_export]
1212 macro_rules! column {
1213 () => {
1214 /* compiler built-in */
1215 };
1216 }
1217
1218 /// Expands to the file name in which it was invoked.
1219 ///
1220 /// With [`line!`] and [`column!`], these macros provide debugging information for
1221 /// developers about the location within the source.
1222 ///
1223 /// The expanded expression has type `&'static str`, and the returned file
1224 /// is not the invocation of the `file!` macro itself, but rather the
1225 /// first macro invocation leading up to the invocation of the `file!`
1226 /// macro.
1227 ///
1228 /// The file name is derived from the crate root's source path passed to the Rust compiler
1229 /// and the sequence the compiler takes to get from the crate root to the
1230 /// module containing `file!`, modified by any flags passed to the Rust compiler (e.g.
1231 /// `--remap-path-prefix`). If the crate's source path is relative, the initial base
1232 /// directory will be the working directory of the Rust compiler. For example, if the source
1233 /// path passed to the compiler is `./src/lib.rs` which has a `mod foo;` with a source path of
1234 /// `src/foo/mod.rs`, then calling `file!` inside `mod foo;` will return `./src/foo/mod.rs`.
1235 ///
1236 /// Future compiler options might make further changes to the behavior of `file!`,
1237 /// including potentially making it entirely empty. Code (e.g. test libraries)
1238 /// relying on `file!` producing an openable file path would be incompatible
1239 /// with such options, and might wish to recommend not using those options.
1240 ///
1241 /// # Examples
1242 ///
1243 /// ```
1244 /// let this_file = file!();
1245 /// println!("defined in file: {this_file}");
1246 /// ```
1247 #[stable(feature = "rust1", since = "1.0.0")]
1248 #[rustc_builtin_macro]
1249 #[macro_export]
1250 macro_rules! file {
1251 () => {
1252 /* compiler built-in */
1253 };
1254 }
1255
1256 /// Stringifies its arguments.
1257 ///
1258 /// This macro will yield an expression of type `&'static str` which is the
1259 /// stringification of all the tokens passed to the macro. No restrictions
1260 /// are placed on the syntax of the macro invocation itself.
1261 ///
1262 /// Note that the expanded results of the input tokens may change in the
1263 /// future. You should be careful if you rely on the output.
1264 ///
1265 /// # Examples
1266 ///
1267 /// ```
1268 /// let one_plus_one = stringify!(1 + 1);
1269 /// assert_eq!(one_plus_one, "1 + 1");
1270 /// ```
1271 #[stable(feature = "rust1", since = "1.0.0")]
1272 #[rustc_builtin_macro]
1273 #[macro_export]
1274 macro_rules! stringify {
1275 ($($t:tt)*) => {
1276 /* compiler built-in */
1277 };
1278 }
1279
1280 /// Includes a UTF-8 encoded file as a string.
1281 ///
1282 /// The file is located relative to the current file (similarly to how
1283 /// modules are found). The provided path is interpreted in a platform-specific
1284 /// way at compile time. So, for instance, an invocation with a Windows path
1285 /// containing backslashes `\` would not compile correctly on Unix.
1286 ///
1287 /// This macro will yield an expression of type `&'static str` which is the
1288 /// contents of the file.
1289 ///
1290 /// # Examples
1291 ///
1292 /// Assume there are two files in the same directory with the following
1293 /// contents:
1294 ///
1295 /// File 'spanish.in':
1296 ///
1297 /// ```text
1298 /// adiós
1299 /// ```
1300 ///
1301 /// File 'main.rs':
1302 ///
1303 /// ```ignore (cannot-doctest-external-file-dependency)
1304 /// fn main() {
1305 /// let my_str = include_str!("spanish.in");
1306 /// assert_eq!(my_str, "adiós\n");
1307 /// print!("{my_str}");
1308 /// }
1309 /// ```
1310 ///
1311 /// Compiling 'main.rs' and running the resulting binary will print "adiós".
1312 #[stable(feature = "rust1", since = "1.0.0")]
1313 #[rustc_builtin_macro]
1314 #[macro_export]
1315 #[rustc_diagnostic_item = "include_str_macro"]
1316 macro_rules! include_str {
1317 ($file:expr $(,)?) => {{ /* compiler built-in */ }};
1318 }
1319
1320 /// Includes a file as a reference to a byte array.
1321 ///
1322 /// The file is located relative to the current file (similarly to how
1323 /// modules are found). The provided path is interpreted in a platform-specific
1324 /// way at compile time. So, for instance, an invocation with a Windows path
1325 /// containing backslashes `\` would not compile correctly on Unix.
1326 ///
1327 /// This macro will yield an expression of type `&'static [u8; N]` which is
1328 /// the contents of the file.
1329 ///
1330 /// # Examples
1331 ///
1332 /// Assume there are two files in the same directory with the following
1333 /// contents:
1334 ///
1335 /// File 'spanish.in':
1336 ///
1337 /// ```text
1338 /// adiós
1339 /// ```
1340 ///
1341 /// File 'main.rs':
1342 ///
1343 /// ```ignore (cannot-doctest-external-file-dependency)
1344 /// fn main() {
1345 /// let bytes = include_bytes!("spanish.in");
1346 /// assert_eq!(bytes, b"adi\xc3\xb3s\n");
1347 /// print!("{}", String::from_utf8_lossy(bytes));
1348 /// }
1349 /// ```
1350 ///
1351 /// Compiling 'main.rs' and running the resulting binary will print "adiós".
1352 #[stable(feature = "rust1", since = "1.0.0")]
1353 #[rustc_builtin_macro]
1354 #[macro_export]
1355 #[rustc_diagnostic_item = "include_bytes_macro"]
1356 macro_rules! include_bytes {
1357 ($file:expr $(,)?) => {{ /* compiler built-in */ }};
1358 }
1359
1360 /// Expands to a string that represents the current module path.
1361 ///
1362 /// The current module path can be thought of as the hierarchy of modules
1363 /// leading back up to the crate root. The first component of the path
1364 /// returned is the name of the crate currently being compiled.
1365 ///
1366 /// # Examples
1367 ///
1368 /// ```
1369 /// mod test {
1370 /// pub fn foo() {
1371 /// assert!(module_path!().ends_with("test"));
1372 /// }
1373 /// }
1374 ///
1375 /// test::foo();
1376 /// ```
1377 #[stable(feature = "rust1", since = "1.0.0")]
1378 #[rustc_builtin_macro]
1379 #[macro_export]
1380 macro_rules! module_path {
1381 () => {
1382 /* compiler built-in */
1383 };
1384 }
1385
1386 /// Evaluates boolean combinations of configuration flags at compile-time.
1387 ///
1388 /// In addition to the `#[cfg]` attribute, this macro is provided to allow
1389 /// boolean expression evaluation of configuration flags. This frequently
1390 /// leads to less duplicated code.
1391 ///
1392 /// The syntax given to this macro is the same syntax as the [`cfg`]
1393 /// attribute.
1394 ///
1395 /// `cfg!`, unlike `#[cfg]`, does not remove any code and only evaluates to true or false. For
1396 /// example, all blocks in an if/else expression need to be valid when `cfg!` is used for
1397 /// the condition, regardless of what `cfg!` is evaluating.
1398 ///
1399 /// [`cfg`]: ../reference/conditional-compilation.html#the-cfg-attribute
1400 ///
1401 /// # Examples
1402 ///
1403 /// ```
1404 /// let my_directory = if cfg!(windows) {
1405 /// "windows-specific-directory"
1406 /// } else {
1407 /// "unix-directory"
1408 /// };
1409 /// ```
1410 #[stable(feature = "rust1", since = "1.0.0")]
1411 #[rustc_builtin_macro]
1412 #[macro_export]
1413 macro_rules! cfg {
1414 ($($cfg:tt)*) => {
1415 /* compiler built-in */
1416 };
1417 }
1418
1419 /// Parses a file as an expression or an item according to the context.
1420 ///
1421 /// **Warning**: For multi-file Rust projects, the `include!` macro is probably not what you
1422 /// are looking for. Usually, multi-file Rust projects use
1423 /// [modules](https://doc.rust-lang.org/reference/items/modules.html). Multi-file projects and
1424 /// modules are explained in the Rust-by-Example book
1425 /// [here](https://doc.rust-lang.org/rust-by-example/mod/split.html) and the module system is
1426 /// explained in the Rust Book
1427 /// [here](https://doc.rust-lang.org/book/ch07-02-defining-modules-to-control-scope-and-privacy.html).
1428 ///
1429 /// The included file is placed in the surrounding code
1430 /// [unhygienically](https://doc.rust-lang.org/reference/macros-by-example.html#hygiene). If
1431 /// the included file is parsed as an expression and variables or functions share names across
1432 /// both files, it could result in variables or functions being different from what the
1433 /// included file expected.
1434 ///
1435 /// The included file is located relative to the current file (similarly to how modules are
1436 /// found). The provided path is interpreted in a platform-specific way at compile time. So,
1437 /// for instance, an invocation with a Windows path containing backslashes `\` would not
1438 /// compile correctly on Unix.
1439 ///
1440 /// # Uses
1441 ///
1442 /// The `include!` macro is primarily used for two purposes. It is used to include
1443 /// documentation that is written in a separate file and it is used to include [build artifacts
1444 /// usually as a result from the `build.rs`
1445 /// script](https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script).
1446 ///
1447 /// When using the `include` macro to include stretches of documentation, remember that the
1448 /// included file still needs to be a valid Rust syntax. It is also possible to
1449 /// use the [`include_str`] macro as `#![doc = include_str!("...")]` (at the module level) or
1450 /// `#[doc = include_str!("...")]` (at the item level) to include documentation from a plain
1451 /// text or markdown file.
1452 ///
1453 /// # Examples
1454 ///
1455 /// Assume there are two files in the same directory with the following contents:
1456 ///
1457 /// File 'monkeys.in':
1458 ///
1459 /// ```ignore (only-for-syntax-highlight)
1460 /// ['🙈', '🙊', '🙉']
1461 /// .iter()
1462 /// .cycle()
1463 /// .take(6)
1464 /// .collect::<String>()
1465 /// ```
1466 ///
1467 /// File 'main.rs':
1468 ///
1469 /// ```ignore (cannot-doctest-external-file-dependency)
1470 /// fn main() {
1471 /// let my_string = include!("monkeys.in");
1472 /// assert_eq!("🙈🙊🙉🙈🙊🙉", my_string);
1473 /// println!("{my_string}");
1474 /// }
1475 /// ```
1476 ///
1477 /// Compiling 'main.rs' and running the resulting binary will print
1478 /// "🙈🙊🙉🙈🙊🙉".
1479 #[stable(feature = "rust1", since = "1.0.0")]
1480 #[rustc_builtin_macro]
1481 #[macro_export]
1482 #[rustc_diagnostic_item = "include_macro"] // useful for external lints
1483 macro_rules! include {
1484 ($file:expr $(,)?) => {{ /* compiler built-in */ }};
1485 }
1486
1487 /// This macro uses forward-mode automatic differentiation to generate a new function.
1488 /// It may only be applied to a function. The new function will compute the derivative
1489 /// of the function to which the macro was applied.
1490 ///
1491 /// The expected usage syntax is:
1492 /// `#[autodiff_forward(NAME, INPUT_ACTIVITIES, OUTPUT_ACTIVITY)]`
1493 ///
1494 /// - `NAME`: A string that represents a valid function name.
1495 /// - `INPUT_ACTIVITIES`: Specifies one valid activity for each input parameter.
1496 /// - `OUTPUT_ACTIVITY`: Must not be set if the function implicitly returns nothing
1497 /// (or explicitly returns `-> ()`). Otherwise, it must be set to one of the allowed activities.
1498 ///
1499 /// ACTIVITIES might either be `Dual` or `Const`, more options will be exposed later.
1500 ///
1501 /// `Const` should be used on non-float arguments, or float-based arguments as an optimization
1502 /// if we are not interested in computing the derivatives with respect to this argument.
1503 ///
1504 /// `Dual` can be used for float scalar values or for references, raw pointers, or other
1505 /// indirect input arguments. It can also be used on a scalar float return value.
1506 /// If used on a return value, the generated function will return a tuple of two float scalars.
1507 /// If used on an input argument, a new shadow argument of the same type will be created,
1508 /// directly following the original argument.
1509 ///
1510 /// ### Usage examples:
1511 ///
1512 /// ```rust,ignore (autodiff requires a -Z flag as well as fat-lto for testing)
1513 /// #![feature(autodiff)]
1514 /// use std::autodiff::*;
1515 /// #[autodiff_forward(rb_fwd1, Dual, Const, Dual)]
1516 /// #[autodiff_forward(rb_fwd2, Const, Dual, Dual)]
1517 /// #[autodiff_forward(rb_fwd3, Dual, Dual, Dual)]
1518 /// fn rosenbrock(x: f64, y: f64) -> f64 {
1519 /// (1.0 - x).powi(2) + 100.0 * (y - x.powi(2)).powi(2)
1520 /// }
1521 /// #[autodiff_forward(rb_inp_fwd, Dual, Dual, Dual)]
1522 /// fn rosenbrock_inp(x: f64, y: f64, out: &mut f64) {
1523 /// *out = (1.0 - x).powi(2) + 100.0 * (y - x.powi(2)).powi(2);
1524 /// }
1525 ///
1526 /// fn main() {
1527 /// let x0 = rosenbrock(1.0, 3.0); // 400.0
1528 /// let (x1, dx1) = rb_fwd1(1.0, 1.0, 3.0); // (400.0, -800.0)
1529 /// let (x2, dy1) = rb_fwd2(1.0, 3.0, 1.0); // (400.0, 400.0)
1530 /// // When seeding both arguments at once the tangent return is the sum of both.
1531 /// let (x3, dxy) = rb_fwd3(1.0, 1.0, 3.0, 1.0); // (400.0, -400.0)
1532 ///
1533 /// let mut out = 0.0;
1534 /// let mut dout = 0.0;
1535 /// rb_inp_fwd(1.0, 1.0, 3.0, 1.0, &mut out, &mut dout);
1536 /// // (out, dout) == (400.0, -400.0)
1537 /// }
1538 /// ```
1539 ///
1540 /// We might want to track how one input float affects one or more output floats. In this case,
1541 /// the shadow of one input should be initialized to `1.0`, while the shadows of the other
1542 /// inputs should be initialized to `0.0`. The shadow of the output(s) should be initialized to
1543 /// `0.0`. After calling the generated function, the shadow of the input will be zeroed,
1544 /// while the shadow(s) of the output(s) will contain the derivatives. Forward mode is generally
1545 /// more efficient if we have more output floats marked as `Dual` than input floats.
1546 /// Related information can also be found under the term "Vector-Jacobian product" (VJP).
1547 #[unstable(feature = "autodiff", issue = "124509")]
1548 #[allow_internal_unstable(rustc_attrs)]
1549 #[allow_internal_unstable(core_intrinsics)]
1550 #[rustc_builtin_macro]
1551 pub macro autodiff_forward($item:item) {
1552 /* compiler built-in */
1553 }
1554
1555 /// This macro uses reverse-mode automatic differentiation to generate a new function.
1556 /// It may only be applied to a function. The new function will compute the derivative
1557 /// of the function to which the macro was applied.
1558 ///
1559 /// The expected usage syntax is:
1560 /// `#[autodiff_reverse(NAME, INPUT_ACTIVITIES, OUTPUT_ACTIVITY)]`
1561 ///
1562 /// - `NAME`: A string that represents a valid function name.
1563 /// - `INPUT_ACTIVITIES`: Specifies one valid activity for each input parameter.
1564 /// - `OUTPUT_ACTIVITY`: Must not be set if the function implicitly returns nothing
1565 /// (or explicitly returns `-> ()`). Otherwise, it must be set to one of the allowed activities.
1566 ///
1567 /// ACTIVITIES might either be `Active`, `Duplicated` or `Const`, more options will be exposed later.
1568 ///
1569 /// `Active` can be used for float scalar values.
1570 /// If used on an input, a new float will be appended to the return tuple of the generated
1571 /// function. If the function returns a float scalar, `Active` can be used for the return as
1572 /// well. In this case a float scalar will be appended to the argument list, it works as seed.
1573 ///
1574 /// `Duplicated` can be used on references, raw pointers, or other indirect input
1575 /// arguments. It creates a new shadow argument of the same type, following the original argument.
1576 /// A const reference or pointer argument will receive a mutable reference or pointer as shadow.
1577 ///
1578 /// `Const` should be used on non-float arguments, or float-based arguments as an optimization
1579 /// if we are not interested in computing the derivatives with respect to this argument.
1580 ///
1581 /// ### Usage examples:
1582 ///
1583 /// ```rust,ignore (autodiff requires a -Z flag as well as fat-lto for testing)
1584 /// #![feature(autodiff)]
1585 /// use std::autodiff::*;
1586 /// #[autodiff_reverse(rb_rev, Active, Active, Active)]
1587 /// fn rosenbrock(x: f64, y: f64) -> f64 {
1588 /// (1.0 - x).powi(2) + 100.0 * (y - x.powi(2)).powi(2)
1589 /// }
1590 /// #[autodiff_reverse(rb_inp_rev, Active, Active, Duplicated)]
1591 /// fn rosenbrock_inp(x: f64, y: f64, out: &mut f64) {
1592 /// *out = (1.0 - x).powi(2) + 100.0 * (y - x.powi(2)).powi(2);
1593 /// }
1594 ///
1595 /// fn main() {
1596 /// let (output1, dx1, dy1) = rb_rev(1.0, 3.0, 1.0);
1597 /// dbg!(output1, dx1, dy1); // (400.0, -800.0, 400.0)
1598 /// let mut output2 = 0.0;
1599 /// let mut seed = 1.0;
1600 /// let (dx2, dy2) = rb_inp_rev(1.0, 3.0, &mut output2, &mut seed);
1601 /// // (dx2, dy2, output2, seed) == (-800.0, 400.0, 400.0, 0.0)
1602 /// }
1603 /// ```
1604 ///
1605 ///
1606 /// We often want to track how one or more input floats affect one output float. This output can
1607 /// be a scalar return value, or a mutable reference or pointer argument. In the latter case, the
1608 /// mutable input should be marked as duplicated and its shadow initialized to `0.0`. The shadow of
1609 /// the output should be marked as active or duplicated and initialized to `1.0`. After calling
1610 /// the generated function, the shadow(s) of the input(s) will contain the derivatives. The
1611 /// shadow of the outputs ("seed") will be reset to zero.
1612 /// If the function has more than one output float marked as active or duplicated, users might want to
1613 /// set one of them to `1.0` and the others to `0.0` to compute partial derivatives.
1614 /// Unlike forward-mode, a call to the generated function does not reset the shadow of the
1615 /// inputs.
1616 /// Reverse mode is generally more efficient if we have more active/duplicated input than
1617 /// output floats.
1618 ///
1619 /// Related information can also be found under the term "Jacobian-Vector Product" (JVP).
1620 #[unstable(feature = "autodiff", issue = "124509")]
1621 #[allow_internal_unstable(rustc_attrs)]
1622 #[allow_internal_unstable(core_intrinsics)]
1623 #[rustc_builtin_macro]
1624 pub macro autodiff_reverse($item:item) {
1625 /* compiler built-in */
1626 }
1627
1628 /// Asserts that a boolean expression is `true` at runtime.
1629 ///
1630 /// This will invoke the [`panic!`] macro if the provided expression cannot be
1631 /// evaluated to `true` at runtime.
1632 ///
1633 /// # Uses
1634 ///
1635 /// Assertions are always checked in both debug and release builds, and cannot
1636 /// be disabled. See [`debug_assert!`] for assertions that are not enabled in
1637 /// release builds by default.
1638 ///
1639 /// Unsafe code may rely on `assert!` to enforce run-time invariants that, if
1640 /// violated could lead to unsafety.
1641 ///
1642 /// Other use-cases of `assert!` include testing and enforcing run-time
1643 /// invariants in safe code (whose violation cannot result in unsafety).
1644 ///
1645 /// # Custom Messages
1646 ///
1647 /// This macro has a second form, where a custom panic message can
1648 /// be provided with or without arguments for formatting. See [`std::fmt`]
1649 /// for syntax for this form. Expressions used as format arguments will only
1650 /// be evaluated if the assertion fails.
1651 ///
1652 /// [`std::fmt`]: ../std/fmt/index.html
1653 ///
1654 /// # Examples
1655 ///
1656 /// ```
1657 /// // the panic message for these assertions is the stringified value of the
1658 /// // expression given.
1659 /// assert!(true);
1660 ///
1661 /// fn some_computation() -> bool {
1662 /// // Some expensive computation here
1663 /// true
1664 /// }
1665 ///
1666 /// assert!(some_computation());
1667 ///
1668 /// // assert with a custom message
1669 /// let x = true;
1670 /// assert!(x, "x wasn't true!");
1671 ///
1672 /// let a = 3; let b = 27;
1673 /// assert!(a + b == 30, "a = {}, b = {}", a, b);
1674 /// ```
1675 #[stable(feature = "rust1", since = "1.0.0")]
1676 #[rustc_builtin_macro]
1677 #[macro_export]
1678 #[rustc_diagnostic_item = "assert_macro"]
1679 #[allow_internal_unstable(
1680 core_intrinsics,
1681 panic_internals,
1682 edition_panic,
1683 generic_assert_internals
1684 )]
1685 macro_rules! assert {
1686 ($cond:expr $(,)?) => {{ /* compiler built-in */ }};
1687 ($cond:expr, $($arg:tt)+) => {{ /* compiler built-in */ }};
1688 }
1689
1690 /// Prints passed tokens into the standard output.
1691 #[unstable(
1692 feature = "log_syntax",
1693 issue = "29598",
1694 reason = "`log_syntax!` is not stable enough for use and is subject to change"
1695 )]
1696 #[rustc_builtin_macro]
1697 #[macro_export]
1698 macro_rules! log_syntax {
1699 ($($arg:tt)*) => {
1700 /* compiler built-in */
1701 };
1702 }
1703
1704 /// Enables or disables tracing functionality used for debugging other macros.
1705 #[unstable(
1706 feature = "trace_macros",
1707 issue = "29598",
1708 reason = "`trace_macros` is not stable enough for use and is subject to change"
1709 )]
1710 #[rustc_builtin_macro]
1711 #[macro_export]
1712 macro_rules! trace_macros {
1713 (true) => {{ /* compiler built-in */ }};
1714 (false) => {{ /* compiler built-in */ }};
1715 }
1716
1717 /// Attribute macro used to apply derive macros.
1718 ///
1719 /// See [the reference] for more info.
1720 ///
1721 /// [the reference]: ../../../reference/attributes/derive.html
1722 #[stable(feature = "rust1", since = "1.0.0")]
1723 #[rustc_builtin_macro]
1724 pub macro derive($item:item) {
1725 /* compiler built-in */
1726 }
1727
1728 /// Attribute macro used to apply derive macros for implementing traits
1729 /// in a const context.
1730 ///
1731 /// See [the reference] for more info.
1732 ///
1733 /// [the reference]: ../../../reference/attributes/derive.html
1734 #[unstable(feature = "derive_const", issue = "118304")]
1735 #[rustc_builtin_macro]
1736 pub macro derive_const($item:item) {
1737 /* compiler built-in */
1738 }
1739
1740 /// Attribute macro applied to a function to turn it into a unit test.
1741 ///
1742 /// See [the reference] for more info.
1743 ///
1744 /// [the reference]: ../../../reference/attributes/testing.html#the-test-attribute
1745 #[stable(feature = "rust1", since = "1.0.0")]
1746 #[allow_internal_unstable(test, rustc_attrs, coverage_attribute)]
1747 #[rustc_builtin_macro]
1748 pub macro test($item:item) {
1749 /* compiler built-in */
1750 }
1751
1752 /// Attribute macro applied to a function to turn it into a benchmark test.
1753 #[unstable(
1754 feature = "test",
1755 issue = "50297",
1756 reason = "`bench` is a part of custom test frameworks which are unstable"
1757 )]
1758 #[allow_internal_unstable(test, rustc_attrs, coverage_attribute)]
1759 #[rustc_builtin_macro]
1760 pub macro bench($item:item) {
1761 /* compiler built-in */
1762 }
1763
1764 /// An implementation detail of the `#[test]` and `#[bench]` macros.
1765 #[unstable(
1766 feature = "custom_test_frameworks",
1767 issue = "50297",
1768 reason = "custom test frameworks are an unstable feature"
1769 )]
1770 #[allow_internal_unstable(test, rustc_attrs)]
1771 #[rustc_builtin_macro]
1772 pub macro test_case($item:item) {
1773 /* compiler built-in */
1774 }
1775
1776 /// Attribute macro applied to a static to register it as a global allocator.
1777 ///
1778 /// See also [`std::alloc::GlobalAlloc`](../../../std/alloc/trait.GlobalAlloc.html).
1779 #[stable(feature = "global_allocator", since = "1.28.0")]
1780 #[allow_internal_unstable(rustc_attrs)]
1781 #[rustc_builtin_macro]
1782 pub macro global_allocator($item:item) {
1783 /* compiler built-in */
1784 }
1785
1786 /// Attribute macro applied to a function to give it a post-condition.
1787 ///
1788 /// The attribute carries an argument token-tree which is
1789 /// eventually parsed as a unary closure expression that is
1790 /// invoked on a reference to the return value.
1791 #[unstable(feature = "contracts", issue = "128044")]
1792 #[allow_internal_unstable(contracts_internals)]
1793 #[rustc_builtin_macro]
1794 pub macro contracts_ensures($item:item) {
1795 /* compiler built-in */
1796 }
1797
1798 /// Attribute macro applied to a function to give it a precondition.
1799 ///
1800 /// The attribute carries an argument token-tree which is
1801 /// eventually parsed as an boolean expression with access to the
1802 /// function's formal parameters
1803 #[unstable(feature = "contracts", issue = "128044")]
1804 #[allow_internal_unstable(contracts_internals)]
1805 #[rustc_builtin_macro]
1806 pub macro contracts_requires($item:item) {
1807 /* compiler built-in */
1808 }
1809
1810 /// Attribute macro applied to a function to register it as a handler for allocation failure.
1811 ///
1812 /// See also [`std::alloc::handle_alloc_error`](../../../std/alloc/fn.handle_alloc_error.html).
1813 #[unstable(feature = "alloc_error_handler", issue = "51540")]
1814 #[allow_internal_unstable(rustc_attrs)]
1815 #[rustc_builtin_macro]
1816 pub macro alloc_error_handler($item:item) {
1817 /* compiler built-in */
1818 }
1819
1820 /// Keeps the item it's applied to if the passed path is accessible, and removes it otherwise.
1821 #[unstable(
1822 feature = "cfg_accessible",
1823 issue = "64797",
1824 reason = "`cfg_accessible` is not fully implemented"
1825 )]
1826 #[rustc_builtin_macro]
1827 pub macro cfg_accessible($item:item) {
1828 /* compiler built-in */
1829 }
1830
1831 /// Expands all `#[cfg]` and `#[cfg_attr]` attributes in the code fragment it's applied to.
1832 #[unstable(
1833 feature = "cfg_eval",
1834 issue = "82679",
1835 reason = "`cfg_eval` is a recently implemented feature"
1836 )]
1837 #[rustc_builtin_macro]
1838 pub macro cfg_eval($($tt:tt)*) {
1839 /* compiler built-in */
1840 }
1841
1842 /// Provide a list of type aliases and other opaque-type-containing type definitions
1843 /// to an item with a body. This list will be used in that body to define opaque
1844 /// types' hidden types.
1845 /// Can only be applied to things that have bodies.
1846 #[unstable(
1847 feature = "type_alias_impl_trait",
1848 issue = "63063",
1849 reason = "`type_alias_impl_trait` has open design concerns"
1850 )]
1851 #[rustc_builtin_macro]
1852 pub macro define_opaque($($tt:tt)*) {
1853 /* compiler built-in */
1854 }
1855
1856 /// Unstable placeholder for type ascription.
1857 #[allow_internal_unstable(builtin_syntax)]
1858 #[unstable(
1859 feature = "type_ascription",
1860 issue = "23416",
1861 reason = "placeholder syntax for type ascription"
1862 )]
1863 #[rustfmt::skip]
1864 pub macro type_ascribe($expr:expr, $ty:ty) {
1865 builtin # type_ascribe($expr, $ty)
1866 }
1867
1868 /// Unstable placeholder for deref patterns.
1869 #[allow_internal_unstable(builtin_syntax)]
1870 #[unstable(
1871 feature = "deref_patterns",
1872 issue = "87121",
1873 reason = "placeholder syntax for deref patterns"
1874 )]
1875 pub macro deref($pat:pat) {
1876 builtin # deref($pat)
1877 }
1878
1879 /// Derive macro generating an impl of the trait `From`.
1880 /// Currently, it can only be used on single-field structs.
1881 // Note that the macro is in a different module than the `From` trait,
1882 // to avoid triggering an unstable feature being used if someone imports
1883 // `std::convert::From`.
1884 #[rustc_builtin_macro]
1885 #[unstable(feature = "derive_from", issue = "144889")]
1886 pub macro From($item: item) {
1887 /* compiler built-in */
1888 }
1889
1890 /// Externally Implementable Item: Defines an attribute macro that can override the item
1891 /// this is applied to.
1892 #[unstable(feature = "extern_item_impls", issue = "125418")]
1893 #[rustc_builtin_macro]
1894 #[allow_internal_unstable(eii_internals, decl_macro, rustc_attrs)]
1895 pub macro eii($item:item) {
1896 /* compiler built-in */
1897 }
1898
1899 /// Unsafely Externally Implementable Item: Defines an unsafe attribute macro that can override
1900 /// the item this is applied to.
1901 #[unstable(feature = "extern_item_impls", issue = "125418")]
1902 #[rustc_builtin_macro]
1903 #[allow_internal_unstable(eii_internals, decl_macro, rustc_attrs)]
1904 pub macro unsafe_eii($item:item) {
1905 /* compiler built-in */
1906 }
1907
1908 /// Impl detail of EII
1909 #[unstable(feature = "eii_internals", issue = "none")]
1910 #[rustc_builtin_macro]
1911 pub macro eii_declaration($item:item) {
1912 /* compiler built-in */
1913 }
1914}