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/")]
5 #![feature(bool_to_option)]
6 #![feature(crate_visibility_modifier)]
7 #![feature(decl_macro)]
8 #![feature(inner_deref)]
10 #![feature(or_patterns)]
11 #![feature(proc_macro_internals)]
12 #![feature(proc_macro_quote)]
14 extern crate proc_macro;
16 use crate::deriving::*;
18 use rustc_expand::base::{MacroExpanderFn, ResolverExpand, SyntaxExtension, SyntaxExtensionKind};
19 use rustc_expand::proc_macro::BangProcMacro;
20 use rustc_span::edition::Edition;
21 use rustc_span::symbol::{sym, Ident};
43 pub mod cmdline_attrs;
44 pub mod proc_macro_harness;
45 pub mod standard_library_imports;
48 pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand, edition: Edition) {
49 let mut register = |name, kind| {
50 resolver.register_builtin_macro(
51 Ident::with_dummy_span(name),
52 SyntaxExtension { is_builtin: true, ..SyntaxExtension::default(kind, edition) },
55 macro register_bang($($name:ident: $f:expr,)*) {
56 $(register(sym::$name, SyntaxExtensionKind::LegacyBang(Box::new($f as MacroExpanderFn)));)*
58 macro register_attr($($name:ident: $f:expr,)*) {
59 $(register(sym::$name, SyntaxExtensionKind::LegacyAttr(Box::new($f)));)*
61 macro register_derive($($name:ident: $f:expr,)*) {
62 $(register(sym::$name, SyntaxExtensionKind::LegacyDerive(Box::new(BuiltinDerive($f))));)*
67 assert: assert::expand_assert,
69 column: source_util::expand_column,
70 compile_error: compile_error::expand_compile_error,
71 concat_idents: concat_idents::expand_concat_idents,
72 concat: concat::expand_concat,
74 file: source_util::expand_file,
75 format_args_nl: format::expand_format_args_nl,
76 format_args: format::expand_format_args,
77 global_asm: global_asm::expand_global_asm,
78 include_bytes: source_util::expand_include_bytes,
79 include_str: source_util::expand_include_str,
80 include: source_util::expand_include,
81 line: source_util::expand_line,
82 llvm_asm: llvm_asm::expand_llvm_asm,
83 log_syntax: log_syntax::expand_log_syntax,
84 module_path: source_util::expand_mod,
85 option_env: env::expand_option_env,
86 stringify: source_util::expand_stringify,
87 trace_macros: trace_macros::expand_trace_macros,
91 bench: test::expand_bench,
92 cfg_accessible: cfg_accessible::Expander,
93 global_allocator: global_allocator::expand,
94 test: test::expand_test,
95 test_case: test::expand_test_case,
99 Clone: clone::expand_deriving_clone,
100 Copy: bounds::expand_deriving_copy,
101 Debug: debug::expand_deriving_debug,
102 Default: default::expand_deriving_default,
103 Eq: eq::expand_deriving_eq,
104 Hash: hash::expand_deriving_hash,
105 Ord: ord::expand_deriving_ord,
106 PartialEq: partial_eq::expand_deriving_partial_eq,
107 PartialOrd: partial_ord::expand_deriving_partial_ord,
108 RustcDecodable: decodable::expand_deriving_rustc_decodable,
109 RustcEncodable: encodable::expand_deriving_rustc_encodable,
112 let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
113 register(sym::quote, SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client })));