rustc_builtin_macros/
lib.rs1#![allow(internal_features)]
6#![allow(rustc::diagnostic_outside_of_impl)]
7#![allow(rustc::untranslatable_diagnostic)]
8#![cfg_attr(not(bootstrap), feature(autodiff))]
9#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
10#![doc(rust_logo)]
11#![feature(assert_matches)]
12#![feature(box_patterns)]
13#![feature(decl_macro)]
14#![feature(if_let_guard)]
15#![feature(proc_macro_internals)]
16#![feature(proc_macro_quote)]
17#![feature(rustdoc_internals)]
18#![feature(string_from_utf8_lossy_owned)]
19#![feature(try_blocks)]
20#![recursion_limit = "256"]
21use std::sync::Arc;
24
25use rustc_expand::base::{MacroExpanderFn, ResolverExpand, SyntaxExtensionKind};
26use rustc_expand::proc_macro::BangProcMacro;
27use rustc_span::sym;
28
29use crate::deriving::*;
30
31mod alloc_error_handler;
32mod assert;
33mod autodiff;
34mod cfg;
35mod cfg_accessible;
36mod cfg_eval;
37mod compile_error;
38mod concat;
39mod concat_bytes;
40mod concat_idents;
41mod define_opaque;
42mod derive;
43mod deriving;
44mod edition_panic;
45mod env;
46mod errors;
47mod format;
48mod format_foreign;
49mod global_allocator;
50mod iter;
51mod log_syntax;
52mod pattern_type;
53mod source_util;
54mod test;
55mod trace_macros;
56
57pub mod asm;
58pub mod cmdline_attrs;
59pub mod contracts;
60pub mod proc_macro_harness;
61pub mod standard_library_imports;
62pub mod test_harness;
63pub mod util;
64
65rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
66
67pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
68 let mut register = |name, kind| resolver.register_builtin_macro(name, kind);
69 macro register_bang($($name:ident: $f:expr,)*) {
70 $(register(sym::$name, SyntaxExtensionKind::LegacyBang(Arc::new($f as MacroExpanderFn)));)*
71 }
72 macro register_attr($($name:ident: $f:expr,)*) {
73 $(register(sym::$name, SyntaxExtensionKind::LegacyAttr(Arc::new($f)));)*
74 }
75 macro register_derive($($name:ident: $f:expr,)*) {
76 $(register(sym::$name, SyntaxExtensionKind::LegacyDerive(Arc::new(BuiltinDerive($f))));)*
77 }
78
79 register_bang! {
80 asm: asm::expand_asm,
82 assert: assert::expand_assert,
83 cfg: cfg::expand_cfg,
84 column: source_util::expand_column,
85 compile_error: compile_error::expand_compile_error,
86 concat: concat::expand_concat,
87 concat_bytes: concat_bytes::expand_concat_bytes,
88 concat_idents: concat_idents::expand_concat_idents,
89 const_format_args: format::expand_format_args,
90 core_panic: edition_panic::expand_panic,
91 env: env::expand_env,
92 file: source_util::expand_file,
93 format_args: format::expand_format_args,
94 format_args_nl: format::expand_format_args_nl,
95 global_asm: asm::expand_global_asm,
96 include: source_util::expand_include,
97 include_bytes: source_util::expand_include_bytes,
98 include_str: source_util::expand_include_str,
99 iter: iter::expand,
100 line: source_util::expand_line,
101 log_syntax: log_syntax::expand_log_syntax,
102 module_path: source_util::expand_mod,
103 naked_asm: asm::expand_naked_asm,
104 option_env: env::expand_option_env,
105 pattern_type: pattern_type::expand,
106 std_panic: edition_panic::expand_panic,
107 stringify: source_util::expand_stringify,
108 trace_macros: trace_macros::expand_trace_macros,
109 unreachable: edition_panic::expand_unreachable,
110 }
112
113 register_attr! {
114 alloc_error_handler: alloc_error_handler::expand,
115 autodiff_forward: autodiff::expand_forward,
116 autodiff_reverse: autodiff::expand_reverse,
117 bench: test::expand_bench,
118 cfg_accessible: cfg_accessible::Expander,
119 cfg_eval: cfg_eval::expand,
120 define_opaque: define_opaque::expand,
121 derive: derive::Expander { is_const: false },
122 derive_const: derive::Expander { is_const: true },
123 global_allocator: global_allocator::expand,
124 test: test::expand_test,
125 test_case: test::expand_test_case,
126 }
127
128 register_derive! {
129 Clone: clone::expand_deriving_clone,
130 Copy: bounds::expand_deriving_copy,
131 ConstParamTy: bounds::expand_deriving_const_param_ty,
132 UnsizedConstParamTy: bounds::expand_deriving_unsized_const_param_ty,
133 Debug: debug::expand_deriving_debug,
134 Default: default::expand_deriving_default,
135 Eq: eq::expand_deriving_eq,
136 Hash: hash::expand_deriving_hash,
137 Ord: ord::expand_deriving_ord,
138 PartialEq: partial_eq::expand_deriving_partial_eq,
139 PartialOrd: partial_ord::expand_deriving_partial_ord,
140 CoercePointee: coerce_pointee::expand_deriving_coerce_pointee,
141 }
142
143 let client = rustc_proc_macro::bridge::client::Client::expand1(rustc_proc_macro::quote);
144 register(sym::quote, SyntaxExtensionKind::Bang(Arc::new(BangProcMacro { client })));
145 let requires = SyntaxExtensionKind::Attr(Arc::new(contracts::ExpandRequires));
146 register(sym::contracts_requires, requires);
147 let ensures = SyntaxExtensionKind::Attr(Arc::new(contracts::ExpandEnsures));
148 register(sym::contracts_ensures, ensures);
149}