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;
47 pub mod plugin_macro_defs;
48 pub mod proc_macro_decls;
49 pub mod proc_macro_impl;
51 pub fn register_builtin_macros(resolver: &mut dyn syntax::ext::base::Resolver, edition: Edition) {
52 let mut register = |name, kind| resolver.register_builtin_macro(
53 Ident::with_empty_ctxt(name), SyntaxExtension {
54 is_builtin: true, ..SyntaxExtension::default(kind, edition)
57 macro register_bang($($name:ident: $f:expr,)*) {
58 $(register(sym::$name, SyntaxExtensionKind::LegacyBang(Box::new($f as MacroExpanderFn)));)*
60 macro register_attr($($name:ident: $f:expr,)*) {
61 $(register(sym::$name, SyntaxExtensionKind::LegacyAttr(Box::new($f)));)*
63 macro register_derive($($name:ident: $f:expr,)*) {
64 $(register(sym::$name, SyntaxExtensionKind::LegacyDerive(Box::new(BuiltinDerive($f))));)*
68 __rust_unstable_column: source_util::expand_column,
70 assert: assert::expand_assert,
72 column: source_util::expand_column,
73 compile_error: compile_error::expand_compile_error,
74 concat_idents: concat_idents::expand_syntax_ext,
75 concat: concat::expand_syntax_ext,
77 file: source_util::expand_file,
78 format_args_nl: format::expand_format_args_nl,
79 format_args: format::expand_format_args,
80 global_asm: global_asm::expand_global_asm,
81 include_bytes: source_util::expand_include_bytes,
82 include_str: source_util::expand_include_str,
83 include: source_util::expand_include,
84 line: source_util::expand_line,
85 log_syntax: log_syntax::expand_syntax_ext,
86 module_path: source_util::expand_mod,
87 option_env: env::expand_option_env,
88 stringify: source_util::expand_stringify,
89 trace_macros: trace_macros::expand_trace_macros,
93 bench: test::expand_bench,
94 global_allocator: global_allocator::expand,
95 test: test::expand_test,
96 test_case: test_case::expand,
100 Clone: clone::expand_deriving_clone,
101 Copy: bounds::expand_deriving_copy,
102 Debug: debug::expand_deriving_debug,
103 Decodable: decodable::expand_deriving_decodable,
104 Default: default::expand_deriving_default,
105 Encodable: encodable::expand_deriving_encodable,
106 Eq: eq::expand_deriving_eq,
107 Hash: hash::expand_deriving_hash,
108 Ord: ord::expand_deriving_ord,
109 PartialEq: partial_eq::expand_deriving_partial_eq,
110 PartialOrd: partial_ord::expand_deriving_partial_ord,
111 RustcDecodable: decodable::expand_deriving_rustc_decodable,
112 RustcEncodable: encodable::expand_deriving_rustc_encodable,