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