]> git.lizzy.rs Git - rust.git/blob - src/libsyntax_ext/lib.rs
Simplify SaveHandler trait
[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 test;
43 mod test_case;
44 mod trace_macros;
45
46 pub mod deriving;
47 pub mod plugin_macro_defs;
48 pub mod proc_macro_decls;
49 pub mod proc_macro_impl;
50
51 pub fn register_builtin_macros(resolver: &mut dyn syntax::ext::base::Resolver, edition: Edition) {
52     let mut register = |name, kind| resolver.register_builtin_macro(
53         Ident::with_empty_ctxt(name), SyntaxExtension {
54             is_builtin: true, ..SyntaxExtension::default(kind, edition)
55         },
56     );
57     macro register_bang($($name:ident: $f:expr,)*) {
58         $(register(sym::$name, SyntaxExtensionKind::LegacyBang(Box::new($f as MacroExpanderFn)));)*
59     }
60     macro register_attr($($name:ident: $f:expr,)*) {
61         $(register(sym::$name, SyntaxExtensionKind::LegacyAttr(Box::new($f)));)*
62     }
63     macro register_derive($($name:ident: $f:expr,)*) {
64         $(register(sym::$name, SyntaxExtensionKind::LegacyDerive(Box::new(BuiltinDerive($f))));)*
65     }
66
67     register_bang! {
68         __rust_unstable_column: source_util::expand_column,
69         asm: asm::expand_asm,
70         assert: assert::expand_assert,
71         cfg: cfg::expand_cfg,
72         column: source_util::expand_column,
73         compile_error: compile_error::expand_compile_error,
74         concat_idents: concat_idents::expand_syntax_ext,
75         concat: concat::expand_syntax_ext,
76         env: env::expand_env,
77         file: source_util::expand_file,
78         format_args_nl: format::expand_format_args_nl,
79         format_args: format::expand_format_args,
80         global_asm: global_asm::expand_global_asm,
81         include_bytes: source_util::expand_include_bytes,
82         include_str: source_util::expand_include_str,
83         include: source_util::expand_include,
84         line: source_util::expand_line,
85         log_syntax: log_syntax::expand_syntax_ext,
86         module_path: source_util::expand_mod,
87         option_env: env::expand_option_env,
88         stringify: source_util::expand_stringify,
89         trace_macros: trace_macros::expand_trace_macros,
90     }
91
92     register_attr! {
93         bench: test::expand_bench,
94         global_allocator: global_allocator::expand,
95         test: test::expand_test,
96         test_case: test_case::expand,
97     }
98
99     register_derive! {
100         Clone: clone::expand_deriving_clone,
101         Copy: bounds::expand_deriving_copy,
102         Debug: debug::expand_deriving_debug,
103         Decodable: decodable::expand_deriving_decodable,
104         Default: default::expand_deriving_default,
105         Encodable: encodable::expand_deriving_encodable,
106         Eq: eq::expand_deriving_eq,
107         Hash: hash::expand_deriving_hash,
108         Ord: ord::expand_deriving_ord,
109         PartialEq: partial_eq::expand_deriving_partial_eq,
110         PartialOrd: partial_ord::expand_deriving_partial_ord,
111         RustcDecodable: decodable::expand_deriving_rustc_decodable,
112         RustcEncodable: encodable::expand_deriving_rustc_encodable,
113     }
114 }