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 rustc_errors::DiagnosticBuilder;
6 use rustc_expand::base::{self, *};
11 use syntax::tokenstream::TokenStream;
17 ) -> Box<dyn base::MacResult + 'static> {
18 let sp = cx.with_def_site_ctxt(sp);
20 match parse_cfg(cx, sp, tts) {
22 let matches_cfg = attr::cfg_matches(&cfg, cx.parse_sess, cx.ecfg.features);
23 MacEager::expr(cx.expr_bool(sp, matches_cfg))
36 ) -> Result<ast::MetaItem, DiagnosticBuilder<'a>> {
37 let mut p = cx.new_parser_from_tts(tts);
39 if p.token == token::Eof {
40 let mut err = cx.struct_span_err(sp, "macro requires a cfg-pattern as an argument");
41 err.span_label(sp, "cfg-pattern required");
45 let cfg = p.parse_meta_item()?;
47 let _ = p.eat(&token::Comma);
49 if !p.eat(&token::Eof) {
50 return Err(cx.struct_span_err(sp, "expected 1 cfg-pattern"));