]> git.lizzy.rs Git - rust.git/blob - src/libsyntax_ext/trace_macros.rs
Auto merge of #31077 - nagisa:mir-temp-promotion, r=dotdash
[rust.git] / src / libsyntax_ext / trace_macros.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use syntax::ast::TokenTree;
12 use syntax::codemap::Span;
13 use syntax::ext::base::ExtCtxt;
14 use syntax::ext::base;
15 use syntax::feature_gate;
16 use syntax::parse::token::keywords;
17
18
19 pub fn expand_trace_macros(cx: &mut ExtCtxt,
20                            sp: Span,
21                            tt: &[TokenTree])
22                            -> Box<base::MacResult+'static> {
23     if !cx.ecfg.enable_trace_macros() {
24         feature_gate::emit_feature_err(&cx.parse_sess.span_diagnostic,
25                                        "trace_macros",
26                                        sp,
27                                        feature_gate::GateIssue::Language,
28                                        feature_gate::EXPLAIN_TRACE_MACROS);
29         return base::DummyResult::any(sp);
30     }
31
32     match (tt.len(), tt.first()) {
33         (1, Some(&TokenTree::Token(_, ref tok))) if tok.is_keyword(keywords::True) => {
34             cx.set_trace_macros(true);
35         }
36         (1, Some(&TokenTree::Token(_, ref tok))) if tok.is_keyword(keywords::False) => {
37             cx.set_trace_macros(false);
38         }
39         _ => cx.span_err(sp, "trace_macros! accepts only `true` or `false`"),
40     }
41
42     base::DummyResult::any(sp)
43 }