]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_builtin_macros/src/lib.rs
Rollup merge of #101292 - rust-lang:notriddle/rustdoc-table-first-child, r=GuillaumeGomez
[rust.git] / compiler / rustc_builtin_macros / src / lib.rs
1 //! This crate contains implementations of built-in macros and other code generating facilities
2 //! injecting code into the crate before it is lowered to HIR.
3
4 #![allow(rustc::potential_query_instability)]
5 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
6 #![feature(array_windows)]
7 #![feature(box_patterns)]
8 #![feature(decl_macro)]
9 #![feature(if_let_guard)]
10 #![feature(is_sorted)]
11 #![feature(let_chains)]
12 #![feature(let_else)]
13 #![feature(proc_macro_internals)]
14 #![feature(proc_macro_quote)]
15 #![recursion_limit = "256"]
16
17 extern crate proc_macro;
18
19 #[macro_use]
20 extern crate tracing;
21
22 use crate::deriving::*;
23
24 use rustc_expand::base::{MacroExpanderFn, ResolverExpand, SyntaxExtensionKind};
25 use rustc_expand::proc_macro::BangProcMacro;
26 use rustc_span::symbol::sym;
27
28 mod assert;
29 mod cfg;
30 mod cfg_accessible;
31 mod cfg_eval;
32 mod compile_error;
33 mod concat;
34 mod concat_bytes;
35 mod concat_idents;
36 mod derive;
37 mod deriving;
38 mod edition_panic;
39 mod env;
40 mod format;
41 mod format_foreign;
42 mod global_allocator;
43 mod log_syntax;
44 mod source_util;
45 mod test;
46 mod trace_macros;
47 mod util;
48
49 pub mod asm;
50 pub mod cmdline_attrs;
51 pub mod proc_macro_harness;
52 pub mod standard_library_imports;
53 pub mod test_harness;
54
55 pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
56     let mut register = |name, kind| resolver.register_builtin_macro(name, kind);
57     macro register_bang($($name:ident: $f:expr,)*) {
58         $(register(sym::$name, SyntaxExtensionKind::LegacyBang(Box::new($f as MacroExpanderFn)));)*
59     }
60     macro register_attr($($name:ident: $f:expr,)*) {
61         $(register(sym::$name, SyntaxExtensionKind::LegacyAttr(Box::new($f)));)*
62     }
63     macro register_derive($($name:ident: $f:expr,)*) {
64         $(register(sym::$name, SyntaxExtensionKind::LegacyDerive(Box::new(BuiltinDerive($f))));)*
65     }
66
67     register_bang! {
68         asm: asm::expand_asm,
69         assert: assert::expand_assert,
70         cfg: cfg::expand_cfg,
71         column: source_util::expand_column,
72         compile_error: compile_error::expand_compile_error,
73         concat_bytes: concat_bytes::expand_concat_bytes,
74         concat_idents: concat_idents::expand_concat_idents,
75         concat: concat::expand_concat,
76         env: env::expand_env,
77         file: source_util::expand_file,
78         format_args_nl: format::expand_format_args_nl,
79         format_args: format::expand_format_args,
80         const_format_args: format::expand_format_args,
81         global_asm: asm::expand_global_asm,
82         include_bytes: source_util::expand_include_bytes,
83         include_str: source_util::expand_include_str,
84         include: source_util::expand_include,
85         line: source_util::expand_line,
86         log_syntax: log_syntax::expand_log_syntax,
87         module_path: source_util::expand_mod,
88         option_env: env::expand_option_env,
89         core_panic: edition_panic::expand_panic,
90         std_panic: edition_panic::expand_panic,
91         unreachable: edition_panic::expand_unreachable,
92         stringify: source_util::expand_stringify,
93         trace_macros: trace_macros::expand_trace_macros,
94     }
95
96     register_attr! {
97         bench: test::expand_bench,
98         cfg_accessible: cfg_accessible::Expander,
99         cfg_eval: cfg_eval::expand,
100         derive: derive::Expander,
101         global_allocator: global_allocator::expand,
102         test: test::expand_test,
103         test_case: test::expand_test_case,
104     }
105
106     register_derive! {
107         Clone: clone::expand_deriving_clone,
108         Copy: bounds::expand_deriving_copy,
109         Debug: debug::expand_deriving_debug,
110         Default: default::expand_deriving_default,
111         Eq: eq::expand_deriving_eq,
112         Hash: hash::expand_deriving_hash,
113         Ord: ord::expand_deriving_ord,
114         PartialEq: partial_eq::expand_deriving_partial_eq,
115         PartialOrd: partial_ord::expand_deriving_partial_ord,
116         RustcDecodable: decodable::expand_deriving_rustc_decodable,
117         RustcEncodable: encodable::expand_deriving_rustc_encodable,
118     }
119
120     let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
121     register(sym::quote, SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client })));
122 }