forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrace_macros.rs
30 lines (27 loc) · 1.06 KB
/
trace_macros.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use syntax::ext::base::{self, ExtCtxt};
use syntax::feature_gate;
use syntax::symbol::{kw, sym};
use syntax_pos::Span;
use syntax::tokenstream::TokenTree;
pub fn expand_trace_macros(cx: &mut ExtCtxt<'_>,
sp: Span,
tt: &[TokenTree])
-> Box<dyn base::MacResult + 'static> {
if !cx.ecfg.enable_trace_macros() {
feature_gate::emit_feature_err(&cx.parse_sess,
sym::trace_macros,
sp,
feature_gate::GateIssue::Language,
feature_gate::EXPLAIN_TRACE_MACROS);
}
match tt {
[TokenTree::Token(token)] if token.is_keyword(kw::True) => {
cx.set_trace_macros(true);
}
[TokenTree::Token(token)] if token.is_keyword(kw::False) => {
cx.set_trace_macros(false);
}
_ => cx.span_err(sp, "trace_macros! accepts only `true` or `false`"),
}
base::DummyResult::any_valid(sp)
}