| //! The compiler code necessary to support the cfg! extension, which expands to |
| //! a literal `true` or `false` based on whether the given cfg matches the |
| //! current compilation environment. |
| use rustc_ast::tokenstream::TokenStream; |
| use rustc_errors::DiagnosticBuilder; |
| use rustc_expand::base::{self, *}; |
| ) -> Box<dyn base::MacResult + 'static> { |
| let sp = cx.with_def_site_ctxt(sp); |
| match parse_cfg(cx, sp, tts) { |
| let matches_cfg = attr::cfg_matches(&cfg, &cx.sess.parse_sess, cx.ecfg.features); |
| MacEager::expr(cx.expr_bool(sp, matches_cfg)) |
| ) -> Result<ast::MetaItem, DiagnosticBuilder<'a>> { |
| let mut p = cx.new_parser_from_tts(tts); |
| if p.token == token::Eof { |
| let mut err = cx.struct_span_err(sp, "macro requires a cfg-pattern as an argument"); |
| err.span_label(sp, "cfg-pattern required"); |
| let cfg = p.parse_meta_item()?; |
| let _ = p.eat(&token::Comma); |
| return Err(cx.struct_span_err(sp, "expected 1 cfg-pattern")); |