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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use ast;
use codemap::Span;
use ext::base::*;
use ext::base;
use ext::build::AstBuilder;
use attr;
use attr::*;
use parse::token;
use config::CfgDiagReal;
pub fn expand_cfg<'cx>(cx: &mut ExtCtxt,
sp: Span,
tts: &[ast::TokenTree])
-> Box<base::MacResult+'static> {
let mut p = cx.new_parser_from_tts(tts);
let cfg = panictry!(p.parse_meta_item());
if !panictry!(p.eat(&token::Eof)){
cx.span_err(sp, "expected 1 cfg-pattern");
return DummyResult::expr(sp);
}
let matches_cfg = {
let mut diag = CfgDiagReal {
diag: &cx.parse_sess.span_diagnostic,
feature_gated_cfgs: cx.feature_gated_cfgs,
};
attr::cfg_matches(&cx.cfg, &cfg, &mut diag)
};
MacEager::expr(cx.expr_bool(sp, matches_cfg))
}