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