]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_builtin_macros/src/lib.rs
Rollup merge of #83470 - danielhenrymantilla:patch-1, 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 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
5 #![feature(box_patterns)]
6 #![feature(box_syntax)]
7 #![feature(bool_to_option)]
8 #![feature(crate_visibility_modifier)]
9 #![feature(decl_macro)]
10 #![feature(nll)]
11 #![cfg_attr(bootstrap, feature(or_patterns))]
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 asm;
25 mod assert;
26 mod cfg;
27 mod cfg_accessible;
28 mod cfg_eval;
29 mod compile_error;
30 mod concat;
31 mod concat_idents;
32 mod derive;
33 mod deriving;
34 mod env;
35 mod format;
36 mod format_foreign;
37 mod global_allocator;
38 mod global_asm;
39 mod llvm_asm;
40 mod log_syntax;
41 mod panic;
42 mod source_util;
43 mod test;
44 mod trace_macros;
45 mod util;
46
47 pub mod cmdline_attrs;
48 pub mod proc_macro_harness;
49 pub mod standard_library_imports;
50 pub mod test_harness;
51
52 pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
53     let mut register = |name, kind| resolver.register_builtin_macro(name, kind);
54     macro register_bang($($name:ident: $f:expr,)*) {
55         $(register(sym::$name, SyntaxExtensionKind::LegacyBang(Box::new($f as MacroExpanderFn)));)*
56     }
57     macro register_attr($($name:ident: $f:expr,)*) {
58         $(register(sym::$name, SyntaxExtensionKind::LegacyAttr(Box::new($f)));)*
59     }
60     macro register_derive($($name:ident: $f:expr,)*) {
61         $(register(sym::$name, SyntaxExtensionKind::LegacyDerive(Box::new(BuiltinDerive($f))));)*
62     }
63
64     register_bang! {
65         asm: asm::expand_asm,
66         assert: assert::expand_assert,
67         cfg: cfg::expand_cfg,
68         column: source_util::expand_column,
69         compile_error: compile_error::expand_compile_error,
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         global_asm: global_asm::expand_global_asm,
77         include_bytes: source_util::expand_include_bytes,
78         include_str: source_util::expand_include_str,
79         include: source_util::expand_include,
80         line: source_util::expand_line,
81         llvm_asm: llvm_asm::expand_llvm_asm,
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: panic::expand_panic,
86         std_panic: panic::expand_panic,
87         stringify: source_util::expand_stringify,
88         trace_macros: trace_macros::expand_trace_macros,
89     }
90
91     register_attr! {
92         bench: test::expand_bench,
93         cfg_accessible: cfg_accessible::Expander,
94         cfg_eval: cfg_eval::expand,
95         derive: derive::Expander,
96         global_allocator: global_allocator::expand,
97         test: test::expand_test,
98         test_case: test::expand_test_case,
99     }
100
101     register_derive! {
102         Clone: clone::expand_deriving_clone,
103         Copy: bounds::expand_deriving_copy,
104         Debug: debug::expand_deriving_debug,
105         Default: default::expand_deriving_default,
106         Eq: eq::expand_deriving_eq,
107         Hash: hash::expand_deriving_hash,
108         Ord: ord::expand_deriving_ord,
109         PartialEq: partial_eq::expand_deriving_partial_eq,
110         PartialOrd: partial_ord::expand_deriving_partial_ord,
111         RustcDecodable: decodable::expand_deriving_rustc_decodable,
112         RustcEncodable: encodable::expand_deriving_rustc_encodable,
113     }
114
115     let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
116     register(sym::quote, SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client })));
117 }