]> git.lizzy.rs Git - rust.git/blob - src/libsyntax_ext/lib.rs
Rollup merge of #58273 - taiki-e:rename-dependency, r=matthewjasper
[rust.git] / src / libsyntax_ext / lib.rs
1 //! Syntax extensions in the Rust compiler.
2
3 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
4
5 #![deny(rust_2018_idioms)]
6
7 #![feature(in_band_lifetimes)]
8 #![feature(proc_macro_diagnostic)]
9 #![feature(proc_macro_internals)]
10 #![feature(proc_macro_span)]
11 #![feature(decl_macro)]
12 #![feature(nll)]
13 #![feature(rustc_diagnostic_macros)]
14
15 #![recursion_limit="256"]
16
17 extern crate proc_macro;
18
19 mod diagnostics;
20
21 mod asm;
22 mod assert;
23 mod cfg;
24 mod compile_error;
25 mod concat;
26 mod concat_idents;
27 mod env;
28 mod format;
29 mod format_foreign;
30 mod global_asm;
31 mod log_syntax;
32 mod proc_macro_server;
33 mod test;
34 mod test_case;
35 mod trace_macros;
36
37 pub mod deriving;
38 pub mod proc_macro_decls;
39 pub mod proc_macro_impl;
40
41 use rustc_data_structures::sync::Lrc;
42 use syntax::ast;
43 use syntax::ext::base::{MacroExpanderFn, NormalTT, NamedSyntaxExtension, MultiModifier};
44 use syntax::ext::hygiene;
45 use syntax::symbol::Symbol;
46
47 pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver,
48                          user_exts: Vec<NamedSyntaxExtension>) {
49     deriving::register_builtin_derives(resolver);
50
51     let mut register = |name, ext| {
52         resolver.add_builtin(ast::Ident::with_empty_ctxt(name), Lrc::new(ext));
53     };
54
55     macro_rules! register {
56         ($( $name:ident: $f:expr, )*) => { $(
57             register(Symbol::intern(stringify!($name)),
58                      NormalTT {
59                         expander: Box::new($f as MacroExpanderFn),
60                         def_info: None,
61                         allow_internal_unstable: None,
62                         allow_internal_unsafe: false,
63                         local_inner_macros: false,
64                         unstable_feature: None,
65                         edition: hygiene::default_edition(),
66                     });
67         )* }
68     }
69
70     use syntax::ext::source_util::*;
71     register! {
72         line: expand_line,
73         __rust_unstable_column: expand_column_gated,
74         column: expand_column,
75         file: expand_file,
76         stringify: expand_stringify,
77         include: expand_include,
78         include_str: expand_include_str,
79         include_bytes: expand_include_bytes,
80         module_path: expand_mod,
81
82         asm: asm::expand_asm,
83         global_asm: global_asm::expand_global_asm,
84         cfg: cfg::expand_cfg,
85         concat: concat::expand_syntax_ext,
86         concat_idents: concat_idents::expand_syntax_ext,
87         env: env::expand_env,
88         option_env: env::expand_option_env,
89         log_syntax: log_syntax::expand_syntax_ext,
90         trace_macros: trace_macros::expand_trace_macros,
91         compile_error: compile_error::expand_compile_error,
92         assert: assert::expand_assert,
93     }
94
95     register(Symbol::intern("test_case"), MultiModifier(Box::new(test_case::expand)));
96     register(Symbol::intern("test"), MultiModifier(Box::new(test::expand_test)));
97     register(Symbol::intern("bench"), MultiModifier(Box::new(test::expand_bench)));
98
99     // format_args uses `unstable` things internally.
100     register(Symbol::intern("format_args"),
101              NormalTT {
102                 expander: Box::new(format::expand_format_args),
103                 def_info: None,
104                 allow_internal_unstable: Some(vec![
105                     Symbol::intern("fmt_internals"),
106                 ].into()),
107                 allow_internal_unsafe: false,
108                 local_inner_macros: false,
109                 unstable_feature: None,
110                 edition: hygiene::default_edition(),
111             });
112     register(Symbol::intern("format_args_nl"),
113              NormalTT {
114                  expander: Box::new(format::expand_format_args_nl),
115                  def_info: None,
116                  allow_internal_unstable: Some(vec![
117                      Symbol::intern("fmt_internals"),
118                  ].into()),
119                  allow_internal_unsafe: false,
120                  local_inner_macros: false,
121                  unstable_feature: None,
122                  edition: hygiene::default_edition(),
123              });
124
125     for (name, ext) in user_exts {
126         register(name, ext);
127     }
128 }