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-04-15 11:35:08 +00:00
|
|
|
#![deny(internal)]
|
2019-02-04 12:49:54 +00:00
|
|
|
|
2018-03-20 14:41:14 +00:00
|
|
|
#![feature(in_band_lifetimes)]
|
|
|
|
#![feature(proc_macro_diagnostic)]
|
2016-10-03 16:49:39 +00:00
|
|
|
#![feature(proc_macro_internals)]
|
2018-03-20 14:41:14 +00:00
|
|
|
#![feature(proc_macro_span)]
|
2017-12-06 18:50:55 +00:00
|
|
|
#![feature(decl_macro)]
|
2019-02-10 07:13:30 +00:00
|
|
|
#![feature(nll)]
|
2018-05-10 18:02:19 +00:00
|
|
|
#![feature(rustc_diagnostic_macros)]
|
2018-02-12 22:21:20 +00:00
|
|
|
|
2018-12-13 15:57:25 +00:00
|
|
|
#![recursion_limit="256"]
|
|
|
|
|
2016-10-03 16:49:39 +00:00
|
|
|
extern crate proc_macro;
|
2019-02-04 12:49:54 +00:00
|
|
|
|
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;
|
|
|
|
mod env;
|
|
|
|
mod format;
|
2016-11-11 04:23:15 +00:00
|
|
|
mod format_foreign;
|
2017-03-16 02:27:40 +00:00
|
|
|
mod global_asm;
|
2015-12-10 14:23:14 +00:00
|
|
|
mod log_syntax;
|
2018-09-16 09:20:47 +00:00
|
|
|
mod proc_macro_server;
|
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
|
|
|
|
2018-09-16 09:20:47 +00:00
|
|
|
pub mod deriving;
|
2018-03-15 23:09:22 +00:00
|
|
|
pub mod proc_macro_decls;
|
2017-01-09 09:31:14 +00:00
|
|
|
pub mod proc_macro_impl;
|
|
|
|
|
2018-02-27 16:11:14 +00:00
|
|
|
use rustc_data_structures::sync::Lrc;
|
2016-09-07 23:21:59 +00:00
|
|
|
use syntax::ast;
|
2018-07-21 01:04:02 +00:00
|
|
|
use syntax::ext::base::{MacroExpanderFn, NormalTT, NamedSyntaxExtension, MultiModifier};
|
2016-11-16 08:21:52 +00:00
|
|
|
use syntax::symbol::Symbol;
|
2019-04-05 22:15:49 +00:00
|
|
|
use syntax::edition::Edition;
|
2016-09-07 23:21:59 +00:00
|
|
|
|
2018-07-12 09:58:16 +00:00
|
|
|
pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver,
|
2019-04-05 22:15:49 +00:00
|
|
|
user_exts: Vec<NamedSyntaxExtension>,
|
|
|
|
edition: Edition) {
|
2017-01-23 15:01:49 +00:00
|
|
|
deriving::register_builtin_derives(resolver);
|
|
|
|
|
2016-09-07 23:21:59 +00:00
|
|
|
let mut register = |name, ext| {
|
2018-02-27 16:11:14 +00:00
|
|
|
resolver.add_builtin(ast::Ident::with_empty_ctxt(name), Lrc::new(ext));
|
2016-09-07 23:21:59 +00:00
|
|
|
};
|
|
|
|
macro_rules! register {
|
|
|
|
($( $name:ident: $f:expr, )*) => { $(
|
2016-11-16 08:21:52 +00:00
|
|
|
register(Symbol::intern(stringify!($name)),
|
2017-08-08 15:21:20 +00:00
|
|
|
NormalTT {
|
|
|
|
expander: Box::new($f as MacroExpanderFn),
|
|
|
|
def_info: None,
|
2019-02-07 13:19:06 +00:00
|
|
|
allow_internal_unstable: None,
|
2017-08-08 15:21:20 +00:00
|
|
|
allow_internal_unsafe: false,
|
2018-06-11 11:21:36 +00:00
|
|
|
local_inner_macros: false,
|
2018-02-25 03:11:06 +00:00
|
|
|
unstable_feature: None,
|
2019-04-05 22:15:49 +00:00
|
|
|
edition,
|
2017-08-08 15:21:20 +00:00
|
|
|
});
|
2016-09-07 23:21:59 +00:00
|
|
|
)* }
|
2015-12-10 14:23:14 +00:00
|
|
|
}
|
|
|
|
|
2016-09-07 23:21:59 +00:00
|
|
|
use syntax::ext::source_util::*;
|
|
|
|
register! {
|
|
|
|
line: expand_line,
|
2017-08-09 23:42:36 +00:00
|
|
|
__rust_unstable_column: expand_column_gated,
|
2016-09-07 23:21:59 +00:00
|
|
|
column: expand_column,
|
|
|
|
file: expand_file,
|
|
|
|
stringify: expand_stringify,
|
|
|
|
include: expand_include,
|
|
|
|
include_str: expand_include_str,
|
|
|
|
include_bytes: expand_include_bytes,
|
|
|
|
module_path: expand_mod,
|
|
|
|
|
|
|
|
asm: asm::expand_asm,
|
2017-03-16 02:27:40 +00:00
|
|
|
global_asm: global_asm::expand_global_asm,
|
2016-09-07 23:21:59 +00:00
|
|
|
cfg: cfg::expand_cfg,
|
|
|
|
concat: concat::expand_syntax_ext,
|
|
|
|
concat_idents: concat_idents::expand_syntax_ext,
|
|
|
|
env: env::expand_env,
|
|
|
|
option_env: env::expand_option_env,
|
|
|
|
log_syntax: log_syntax::expand_syntax_ext,
|
|
|
|
trace_macros: trace_macros::expand_trace_macros,
|
2017-05-07 03:26:45 +00:00
|
|
|
compile_error: compile_error::expand_compile_error,
|
2018-03-07 07:13:15 +00:00
|
|
|
assert: assert::expand_assert,
|
2016-09-07 23:21:59 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 16:03:24 +00:00
|
|
|
register(Symbol::intern("test_case"), MultiModifier(Box::new(test_case::expand)));
|
2018-09-05 19:43:11 +00:00
|
|
|
register(Symbol::intern("test"), MultiModifier(Box::new(test::expand_test)));
|
|
|
|
register(Symbol::intern("bench"), MultiModifier(Box::new(test::expand_bench)));
|
2018-07-21 01:04:02 +00:00
|
|
|
|
2016-09-07 23:21:59 +00:00
|
|
|
// format_args uses `unstable` things internally.
|
2016-11-16 08:21:52 +00:00
|
|
|
register(Symbol::intern("format_args"),
|
2017-08-08 15:21:20 +00:00
|
|
|
NormalTT {
|
|
|
|
expander: Box::new(format::expand_format_args),
|
|
|
|
def_info: None,
|
2019-02-07 13:19:06 +00:00
|
|
|
allow_internal_unstable: Some(vec![
|
2019-02-03 11:55:00 +00:00
|
|
|
Symbol::intern("fmt_internals"),
|
2019-02-07 13:19:06 +00:00
|
|
|
].into()),
|
2017-08-08 15:21:20 +00:00
|
|
|
allow_internal_unsafe: false,
|
2018-06-11 11:21:36 +00:00
|
|
|
local_inner_macros: false,
|
2018-05-13 00:51:46 +00:00
|
|
|
unstable_feature: None,
|
2019-04-05 22:15:49 +00:00
|
|
|
edition,
|
2017-08-08 15:21:20 +00:00
|
|
|
});
|
2018-07-20 01:53:26 +00:00
|
|
|
register(Symbol::intern("format_args_nl"),
|
|
|
|
NormalTT {
|
|
|
|
expander: Box::new(format::expand_format_args_nl),
|
|
|
|
def_info: None,
|
2019-02-07 13:19:06 +00:00
|
|
|
allow_internal_unstable: Some(vec![
|
2019-02-03 11:55:00 +00:00
|
|
|
Symbol::intern("fmt_internals"),
|
2019-02-07 13:19:06 +00:00
|
|
|
].into()),
|
2018-07-20 01:53:26 +00:00
|
|
|
allow_internal_unsafe: false,
|
|
|
|
local_inner_macros: false,
|
|
|
|
unstable_feature: None,
|
2019-04-05 22:15:49 +00:00
|
|
|
edition,
|
2018-07-20 01:53:26 +00:00
|
|
|
});
|
2016-09-07 23:21:59 +00:00
|
|
|
|
2016-09-28 22:48:55 +00:00
|
|
|
for (name, ext) in user_exts {
|
|
|
|
register(name, ext);
|
|
|
|
}
|
2015-12-10 14:23:14 +00:00
|
|
|
}
|