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.
4 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
6 #![feature(crate_visibility_modifier)]
7 #![feature(decl_macro)]
10 #![feature(rustc_diagnostic_macros)]
12 use crate::deriving::*;
14 use syntax::ast::Ident;
15 use syntax::edition::Edition;
16 use syntax::ext::base::{SyntaxExtension, SyntaxExtensionKind, MacroExpanderFn};
17 use syntax::symbol::sym;
38 pub mod plugin_macro_defs;
39 pub mod proc_macro_harness;
40 pub mod standard_library_imports;
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)
49 macro register_bang($($name:ident: $f:expr,)*) {
50 $(register(sym::$name, SyntaxExtensionKind::LegacyBang(Box::new($f as MacroExpanderFn)));)*
52 macro register_attr($($name:ident: $f:expr,)*) {
53 $(register(sym::$name, SyntaxExtensionKind::LegacyAttr(Box::new($f)));)*
55 macro register_derive($($name:ident: $f:expr,)*) {
56 $(register(sym::$name, SyntaxExtensionKind::LegacyDerive(Box::new(BuiltinDerive($f))));)*
60 __rust_unstable_column: source_util::expand_column,
62 assert: assert::expand_assert,
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,
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,
85 bench: test::expand_bench,
86 global_allocator: global_allocator::expand,
87 test: test::expand_test,
88 test_case: test::expand_test_case,
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,