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