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