1 /// The compiler code necessary to support the cfg! extension, which expands to
2 /// a literal `true` or `false` based on whether the given cfg matches the
3 /// current compilation environment.
5 use errors::DiagnosticBuilder;
8 use syntax_expand::base::{self, *};
10 use syntax::tokenstream::TokenStream;
18 ) -> Box<dyn base::MacResult + 'static> {
19 let sp = cx.with_def_site_ctxt(sp);
21 match parse_cfg(cx, sp, tts) {
23 let matches_cfg = attr::cfg_matches(&cfg, cx.parse_sess, cx.ecfg.features);
24 MacEager::expr(cx.expr_bool(sp, matches_cfg))
37 ) -> Result<ast::MetaItem, DiagnosticBuilder<'a>> {
38 let mut p = cx.new_parser_from_tts(tts);
40 if p.token == token::Eof {
41 let mut err = cx.struct_span_err(sp, "macro requires a cfg-pattern as an argument");
42 err.span_label(sp, "cfg-pattern required");
46 let cfg = p.parse_meta_item()?;
48 let _ = p.eat(&token::Comma);
50 if !p.eat(&token::Eof) {
51 return Err(cx.struct_span_err(sp, "expected 1 cfg-pattern"));