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