1 //! Syntax extensions in the Rust compiler.
3 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
5 #![deny(rust_2018_idioms)]
6 #![deny(unused_lifetimes)]
8 #![feature(crate_visibility_modifier)]
9 #![feature(decl_macro)]
11 #![feature(proc_macro_diagnostic)]
12 #![feature(proc_macro_internals)]
13 #![feature(proc_macro_span)]
14 #![feature(rustc_diagnostic_macros)]
15 #![feature(unicode_internals)]
17 extern crate proc_macro;
19 use crate::deriving::*;
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;
41 mod proc_macro_server;
48 pub mod plugin_macro_defs;
49 pub mod proc_macro_decls;
50 pub mod proc_macro_impl;
52 pub fn register_builtin_macros(resolver: &mut dyn syntax::ext::base::Resolver, edition: Edition) {
53 let mut register = |name, kind| resolver.register_builtin_macro(
54 Ident::with_empty_ctxt(name), SyntaxExtension {
55 is_builtin: true, ..SyntaxExtension::default(kind, edition)
58 macro register_bang($($name:ident: $f:expr,)*) {
59 $(register(sym::$name, SyntaxExtensionKind::LegacyBang(Box::new($f as MacroExpanderFn)));)*
61 macro register_attr($($name:ident: $f:expr,)*) {
62 $(register(sym::$name, SyntaxExtensionKind::LegacyAttr(Box::new($f)));)*
64 macro register_derive($($name:ident: $f:expr,)*) {
65 $(register(sym::$name, SyntaxExtensionKind::LegacyDerive(Box::new(BuiltinDerive($f))));)*
69 __rust_unstable_column: source_util::expand_column,
71 assert: assert::expand_assert,
73 column: source_util::expand_column,
74 compile_error: compile_error::expand_compile_error,
75 concat_idents: concat_idents::expand_syntax_ext,
76 concat: concat::expand_syntax_ext,
78 file: source_util::expand_file,
79 format_args_nl: format::expand_format_args_nl,
80 format_args: format::expand_format_args,
81 global_asm: global_asm::expand_global_asm,
82 include_bytes: source_util::expand_include_bytes,
83 include_str: source_util::expand_include_str,
84 include: source_util::expand_include,
85 line: source_util::expand_line,
86 log_syntax: log_syntax::expand_syntax_ext,
87 module_path: source_util::expand_mod,
88 option_env: env::expand_option_env,
89 stringify: source_util::expand_stringify,
90 trace_macros: trace_macros::expand_trace_macros,
94 bench: test::expand_bench,
95 global_allocator: global_allocator::expand,
96 test: test::expand_test,
97 test_case: test_case::expand,
101 Clone: clone::expand_deriving_clone,
102 Copy: bounds::expand_deriving_copy,
103 Debug: debug::expand_deriving_debug,
104 Decodable: decodable::expand_deriving_decodable,
105 Default: default::expand_deriving_default,
106 Encodable: encodable::expand_deriving_encodable,
107 Eq: eq::expand_deriving_eq,
108 Hash: hash::expand_deriving_hash,
109 Ord: ord::expand_deriving_ord,
110 PartialEq: partial_eq::expand_deriving_partial_eq,
111 PartialOrd: partial_ord::expand_deriving_partial_ord,
112 RustcDecodable: decodable::expand_deriving_rustc_decodable,
113 RustcEncodable: encodable::expand_deriving_rustc_encodable,