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