]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_builtin_macros/src/lib.rs
orphan check: remove const generics fixme
[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 #![cfg_attr(bootstrap, 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 use crate::deriving::*;
20
21 use rustc_expand::base::{MacroExpanderFn, ResolverExpand, SyntaxExtensionKind};
22 use rustc_expand::proc_macro::BangProcMacro;
23 use rustc_span::symbol::sym;
24
25 mod assert;
26 mod cfg;
27 mod cfg_accessible;
28 mod cfg_eval;
29 mod compile_error;
30 mod concat;
31 mod concat_bytes;
32 mod concat_idents;
33 mod derive;
34 mod deriving;
35 mod edition_panic;
36 mod env;
37 mod format;
38 mod format_foreign;
39 mod global_allocator;
40 mod log_syntax;
41 mod source_util;
42 mod test;
43 mod trace_macros;
44 mod util;
45
46 pub mod asm;
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_bytes: concat_bytes::expand_concat_bytes,
71         concat_idents: concat_idents::expand_concat_idents,
72         concat: concat::expand_concat,
73         env: env::expand_env,
74         file: source_util::expand_file,
75         format_args_nl: format::expand_format_args_nl,
76         format_args: format::expand_format_args,
77         const_format_args: format::expand_format_args,
78         global_asm: asm::expand_global_asm,
79         include_bytes: source_util::expand_include_bytes,
80         include_str: source_util::expand_include_str,
81         include: source_util::expand_include,
82         line: source_util::expand_line,
83         log_syntax: log_syntax::expand_log_syntax,
84         module_path: source_util::expand_mod,
85         option_env: env::expand_option_env,
86         core_panic: edition_panic::expand_panic,
87         std_panic: edition_panic::expand_panic,
88         unreachable: edition_panic::expand_unreachable,
89         stringify: source_util::expand_stringify,
90         trace_macros: trace_macros::expand_trace_macros,
91     }
92
93     register_attr! {
94         bench: test::expand_bench,
95         cfg_accessible: cfg_accessible::Expander,
96         cfg_eval: cfg_eval::expand,
97         derive: derive::Expander,
98         global_allocator: global_allocator::expand,
99         test: test::expand_test,
100         test_case: test::expand_test_case,
101     }
102
103     register_derive! {
104         Clone: clone::expand_deriving_clone,
105         Copy: bounds::expand_deriving_copy,
106         Debug: debug::expand_deriving_debug,
107         Default: default::expand_deriving_default,
108         Eq: eq::expand_deriving_eq,
109         Hash: hash::expand_deriving_hash,
110         Ord: ord::expand_deriving_ord,
111         PartialEq: partial_eq::expand_deriving_partial_eq,
112         PartialOrd: partial_ord::expand_deriving_partial_ord,
113         RustcDecodable: decodable::expand_deriving_rustc_decodable,
114         RustcEncodable: encodable::expand_deriving_rustc_encodable,
115     }
116
117     let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
118     register(sym::quote, SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client })));
119 }