2015-12-10 23:23:14 +09:00
|
|
|
use syntax::ext::base::ExtCtxt;
|
|
|
|
|
use syntax::ext::base;
|
|
|
|
|
use syntax::feature_gate;
|
2016-11-16 08:21:52 +00:00
|
|
|
use syntax::symbol::keywords;
|
2016-06-21 18:08:13 -04:00
|
|
|
use syntax_pos::Span;
|
2016-06-20 08:49:33 -07:00
|
|
|
use syntax::tokenstream::TokenTree;
|
2014-05-05 18:56:44 -07:00
|
|
|
|
2013-12-28 22:06:22 -07:00
|
|
|
pub fn expand_trace_macros(cx: &mut ExtCtxt,
|
2013-08-31 18:13:04 +02:00
|
|
|
sp: Span,
|
2015-11-06 14:52:02 +01:00
|
|
|
tt: &[TokenTree])
|
2018-07-12 11:58:16 +02:00
|
|
|
-> Box<dyn base::MacResult + 'static> {
|
2015-02-15 23:49:55 +01:00
|
|
|
if !cx.ecfg.enable_trace_macros() {
|
2016-09-24 18:42:54 +02:00
|
|
|
feature_gate::emit_feature_err(&cx.parse_sess,
|
2015-02-15 23:49:55 +01:00
|
|
|
"trace_macros",
|
|
|
|
|
sp,
|
2015-09-04 16:37:22 -07:00
|
|
|
feature_gate::GateIssue::Language,
|
2015-02-15 23:49:55 +01:00
|
|
|
feature_gate::EXPLAIN_TRACE_MACROS);
|
|
|
|
|
return base::DummyResult::any(sp);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-15 22:12:12 -07:00
|
|
|
match (tt.len(), tt.first()) {
|
2015-11-06 14:52:02 +01:00
|
|
|
(1, Some(&TokenTree::Token(_, ref tok))) if tok.is_keyword(keywords::True) => {
|
2014-03-18 23:14:08 +11:00
|
|
|
cx.set_trace_macros(true);
|
|
|
|
|
}
|
2015-11-06 14:52:02 +01:00
|
|
|
(1, Some(&TokenTree::Token(_, ref tok))) if tok.is_keyword(keywords::False) => {
|
2014-03-18 23:14:08 +11:00
|
|
|
cx.set_trace_macros(false);
|
|
|
|
|
}
|
|
|
|
|
_ => cx.span_err(sp, "trace_macros! accepts only `true` or `false`"),
|
2012-08-15 10:45:10 -07:00
|
|
|
}
|
2012-11-26 22:12:31 -05:00
|
|
|
|
2014-04-15 22:00:14 +10:00
|
|
|
base::DummyResult::any(sp)
|
2012-08-15 10:45:10 -07:00
|
|
|
}
|