]> git.lizzy.rs Git - rust.git/blob - src/libsyntax_ext/lib.rs
Rollup merge of #63055 - Mark-Simulacrum:save-analysis-clean-2, r=Xanewok
[rust.git] / src / libsyntax_ext / 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/")]
5
6 #![feature(crate_visibility_modifier)]
7 #![feature(decl_macro)]
8 #![feature(mem_take)]
9 #![feature(nll)]
10 #![feature(rustc_diagnostic_macros)]
11
12 use crate::deriving::*;
13
14 use syntax::ast::Ident;
15 use syntax::edition::Edition;
16 use syntax::ext::base::{SyntaxExtension, SyntaxExtensionKind, MacroExpanderFn};
17 use syntax::symbol::sym;
18
19 mod error_codes;
20
21 mod asm;
22 mod assert;
23 mod cfg;
24 mod compile_error;
25 mod concat;
26 mod concat_idents;
27 mod deriving;
28 mod env;
29 mod format;
30 mod format_foreign;
31 mod global_allocator;
32 mod global_asm;
33 mod log_syntax;
34 mod source_util;
35 mod test;
36 mod trace_macros;
37
38 pub mod plugin_macro_defs;
39 pub mod proc_macro_harness;
40 pub mod standard_library_imports;
41 pub mod test_harness;
42
43 pub fn register_builtin_macros(resolver: &mut dyn syntax::ext::base::Resolver, edition: Edition) {
44     let mut register = |name, kind| resolver.register_builtin_macro(
45         Ident::with_empty_ctxt(name), SyntaxExtension {
46             is_builtin: true, ..SyntaxExtension::default(kind, edition)
47         },
48     );
49     macro register_bang($($name:ident: $f:expr,)*) {
50         $(register(sym::$name, SyntaxExtensionKind::LegacyBang(Box::new($f as MacroExpanderFn)));)*
51     }
52     macro register_attr($($name:ident: $f:expr,)*) {
53         $(register(sym::$name, SyntaxExtensionKind::LegacyAttr(Box::new($f)));)*
54     }
55     macro register_derive($($name:ident: $f:expr,)*) {
56         $(register(sym::$name, SyntaxExtensionKind::LegacyDerive(Box::new(BuiltinDerive($f))));)*
57     }
58
59     register_bang! {
60         __rust_unstable_column: source_util::expand_column,
61         asm: asm::expand_asm,
62         assert: assert::expand_assert,
63         cfg: cfg::expand_cfg,
64         column: source_util::expand_column,
65         compile_error: compile_error::expand_compile_error,
66         concat_idents: concat_idents::expand_syntax_ext,
67         concat: concat::expand_syntax_ext,
68         env: env::expand_env,
69         file: source_util::expand_file,
70         format_args_nl: format::expand_format_args_nl,
71         format_args: format::expand_format_args,
72         global_asm: global_asm::expand_global_asm,
73         include_bytes: source_util::expand_include_bytes,
74         include_str: source_util::expand_include_str,
75         include: source_util::expand_include,
76         line: source_util::expand_line,
77         log_syntax: log_syntax::expand_syntax_ext,
78         module_path: source_util::expand_mod,
79         option_env: env::expand_option_env,
80         stringify: source_util::expand_stringify,
81         trace_macros: trace_macros::expand_trace_macros,
82     }
83
84     register_attr! {
85         bench: test::expand_bench,
86         global_allocator: global_allocator::expand,
87         test: test::expand_test,
88         test_case: test::expand_test_case,
89     }
90
91     register_derive! {
92         Clone: clone::expand_deriving_clone,
93         Copy: bounds::expand_deriving_copy,
94         Debug: debug::expand_deriving_debug,
95         Decodable: decodable::expand_deriving_decodable,
96         Default: default::expand_deriving_default,
97         Encodable: encodable::expand_deriving_encodable,
98         Eq: eq::expand_deriving_eq,
99         Hash: hash::expand_deriving_hash,
100         Ord: ord::expand_deriving_ord,
101         PartialEq: partial_eq::expand_deriving_partial_eq,
102         PartialOrd: partial_ord::expand_deriving_partial_ord,
103         RustcDecodable: decodable::expand_deriving_rustc_decodable,
104         RustcEncodable: encodable::expand_deriving_rustc_encodable,
105     }
106 }