2015-12-10 14:23:14 +00:00
|
|
|
//! Syntax extensions in the Rust compiler.
|
|
|
|
|
2019-02-05 13:37:15 +00:00
|
|
|
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
|
2015-12-15 07:23:18 +00:00
|
|
|
|
2019-02-04 12:49:54 +00:00
|
|
|
#![deny(rust_2018_idioms)]
|
2019-06-11 09:21:12 +00:00
|
|
|
#![deny(unused_lifetimes)]
|
2019-02-04 12:49:54 +00:00
|
|
|
|
2019-06-20 08:52:31 +00:00
|
|
|
#![feature(crate_visibility_modifier)]
|
|
|
|
#![feature(decl_macro)]
|
|
|
|
#![feature(nll)]
|
2018-05-10 18:02:19 +00:00
|
|
|
#![feature(rustc_diagnostic_macros)]
|
2019-07-22 09:09:34 +00:00
|
|
|
#![feature(unicode_internals)]
|
2018-02-12 22:21:20 +00:00
|
|
|
|
2016-10-03 16:49:39 +00:00
|
|
|
extern crate proc_macro;
|
2019-02-04 12:49:54 +00:00
|
|
|
|
2019-06-20 08:52:31 +00:00
|
|
|
use crate::deriving::*;
|
|
|
|
|
|
|
|
use syntax::ast::Ident;
|
|
|
|
use syntax::edition::Edition;
|
|
|
|
use syntax::ext::base::{SyntaxExtension, SyntaxExtensionKind, MacroExpanderFn};
|
|
|
|
use syntax::ext::source_util;
|
|
|
|
use syntax::symbol::sym;
|
|
|
|
|
2019-04-16 22:35:54 +00:00
|
|
|
mod error_codes;
|
2018-02-12 22:21:20 +00:00
|
|
|
|
2015-12-10 14:23:14 +00:00
|
|
|
mod asm;
|
2018-05-17 19:17:53 +00:00
|
|
|
mod assert;
|
2015-12-10 14:23:14 +00:00
|
|
|
mod cfg;
|
2017-05-07 03:26:45 +00:00
|
|
|
mod compile_error;
|
2015-12-10 14:23:14 +00:00
|
|
|
mod concat;
|
|
|
|
mod concat_idents;
|
2019-07-18 18:02:34 +00:00
|
|
|
mod deriving;
|
2015-12-10 14:23:14 +00:00
|
|
|
mod env;
|
|
|
|
mod format;
|
2016-11-11 04:23:15 +00:00
|
|
|
mod format_foreign;
|
2019-07-18 21:24:58 +00:00
|
|
|
mod global_allocator;
|
2017-03-16 02:27:40 +00:00
|
|
|
mod global_asm;
|
2015-12-10 14:23:14 +00:00
|
|
|
mod log_syntax;
|
2019-07-17 22:49:10 +00:00
|
|
|
mod source_util;
|
2018-07-21 01:04:02 +00:00
|
|
|
mod test;
|
2018-09-02 16:03:24 +00:00
|
|
|
mod test_case;
|
2018-09-16 09:20:47 +00:00
|
|
|
mod trace_macros;
|
2015-12-10 14:23:14 +00:00
|
|
|
|
2019-06-20 08:52:31 +00:00
|
|
|
pub mod plugin_macro_defs;
|
2018-03-15 23:09:22 +00:00
|
|
|
pub mod proc_macro_decls;
|
2017-01-09 09:31:14 +00:00
|
|
|
|
2019-06-20 08:52:31 +00:00
|
|
|
pub fn register_builtin_macros(resolver: &mut dyn syntax::ext::base::Resolver, edition: Edition) {
|
|
|
|
let mut register = |name, kind| resolver.register_builtin_macro(
|
|
|
|
Ident::with_empty_ctxt(name), SyntaxExtension {
|
|
|
|
is_builtin: true, ..SyntaxExtension::default(kind, edition)
|
|
|
|
},
|
|
|
|
);
|
|
|
|
macro register_bang($($name:ident: $f:expr,)*) {
|
|
|
|
$(register(sym::$name, SyntaxExtensionKind::LegacyBang(Box::new($f as MacroExpanderFn)));)*
|
|
|
|
}
|
|
|
|
macro register_attr($($name:ident: $f:expr,)*) {
|
|
|
|
$(register(sym::$name, SyntaxExtensionKind::LegacyAttr(Box::new($f)));)*
|
2019-06-16 15:58:39 +00:00
|
|
|
}
|
2019-06-20 08:52:31 +00:00
|
|
|
macro register_derive($($name:ident: $f:expr,)*) {
|
|
|
|
$(register(sym::$name, SyntaxExtensionKind::LegacyDerive(Box::new(BuiltinDerive($f))));)*
|
2015-12-10 14:23:14 +00:00
|
|
|
}
|
|
|
|
|
2019-06-20 08:52:31 +00:00
|
|
|
register_bang! {
|
|
|
|
__rust_unstable_column: source_util::expand_column,
|
|
|
|
asm: asm::expand_asm,
|
|
|
|
assert: assert::expand_assert,
|
2016-09-07 23:21:59 +00:00
|
|
|
cfg: cfg::expand_cfg,
|
2019-06-20 08:52:31 +00:00
|
|
|
column: source_util::expand_column,
|
|
|
|
compile_error: compile_error::expand_compile_error,
|
|
|
|
concat_idents: concat_idents::expand_syntax_ext,
|
2016-09-07 23:21:59 +00:00
|
|
|
concat: concat::expand_syntax_ext,
|
|
|
|
env: env::expand_env,
|
2019-06-20 08:52:31 +00:00
|
|
|
file: source_util::expand_file,
|
|
|
|
format_args_nl: format::expand_format_args_nl,
|
|
|
|
format_args: format::expand_format_args,
|
2019-06-22 13:18:05 +00:00
|
|
|
global_asm: global_asm::expand_global_asm,
|
2019-06-20 08:52:31 +00:00
|
|
|
include_bytes: source_util::expand_include_bytes,
|
|
|
|
include_str: source_util::expand_include_str,
|
|
|
|
include: source_util::expand_include,
|
|
|
|
line: source_util::expand_line,
|
2019-06-22 13:18:05 +00:00
|
|
|
log_syntax: log_syntax::expand_syntax_ext,
|
2019-06-20 08:52:31 +00:00
|
|
|
module_path: source_util::expand_mod,
|
|
|
|
option_env: env::expand_option_env,
|
|
|
|
stringify: source_util::expand_stringify,
|
2019-06-22 13:18:05 +00:00
|
|
|
trace_macros: trace_macros::expand_trace_macros,
|
2019-06-16 15:58:39 +00:00
|
|
|
}
|
2018-07-21 01:04:02 +00:00
|
|
|
|
2019-06-20 08:52:31 +00:00
|
|
|
register_attr! {
|
|
|
|
bench: test::expand_bench,
|
|
|
|
global_allocator: global_allocator::expand,
|
|
|
|
test: test::expand_test,
|
|
|
|
test_case: test_case::expand,
|
|
|
|
}
|
2016-09-07 23:21:59 +00:00
|
|
|
|
2019-06-20 08:52:31 +00:00
|
|
|
register_derive! {
|
|
|
|
Clone: clone::expand_deriving_clone,
|
|
|
|
Copy: bounds::expand_deriving_copy,
|
|
|
|
Debug: debug::expand_deriving_debug,
|
|
|
|
Decodable: decodable::expand_deriving_decodable,
|
|
|
|
Default: default::expand_deriving_default,
|
|
|
|
Encodable: encodable::expand_deriving_encodable,
|
|
|
|
Eq: eq::expand_deriving_eq,
|
|
|
|
Hash: hash::expand_deriving_hash,
|
|
|
|
Ord: ord::expand_deriving_ord,
|
|
|
|
PartialEq: partial_eq::expand_deriving_partial_eq,
|
|
|
|
PartialOrd: partial_ord::expand_deriving_partial_ord,
|
|
|
|
RustcDecodable: decodable::expand_deriving_rustc_decodable,
|
|
|
|
RustcEncodable: encodable::expand_deriving_rustc_encodable,
|
2016-09-28 22:48:55 +00:00
|
|
|
}
|
2015-12-10 14:23:14 +00:00
|
|
|
}
|