11use  rustc_ast:: token:: Delimiter ; 
22use  rustc_ast:: tokenstream:: DelimSpan ; 
3- use  rustc_ast:: { AttrItem ,  Attribute ,  LitKind ,   MetaItemInner ,  NodeId ,  ast,  token} ; 
3+ use  rustc_ast:: { AttrItem ,  Attribute ,  CRATE_NODE_ID ,   LitKind ,  NodeId ,  ast,  token} ; 
44use  rustc_errors:: PResult ; 
55use  rustc_feature:: { AttributeTemplate ,  Features ,  template} ; 
66use  rustc_hir:: RustcVersion ; 
@@ -19,7 +19,8 @@ use crate::context::{AcceptContext, ShouldEmit, Stage};
1919use  crate :: parser:: { ArgParser ,  MetaItemListParser ,  MetaItemOrLitParser ,  NameValueParser } ; 
2020use  crate :: session_diagnostics:: { CfgAttrBadDelim ,  MalformedCfgAttr ,  MetaBadDelimSugg } ; 
2121use  crate :: { 
22-     CfgMatchesLintEmitter ,  fluent_generated,  parse_version,  session_diagnostics,  try_gate_cfg, 
22+     AttributeParser ,  CfgMatchesLintEmitter ,  fluent_generated,  parse_version,  session_diagnostics, 
23+     try_gate_cfg, 
2324} ; 
2425
2526pub  const  CFG_TEMPLATE :  AttributeTemplate  = template ! ( 
@@ -309,8 +310,9 @@ impl EvalConfigResult {
309310
310311pub  fn  parse_cfg_attr ( 
311312    cfg_attr :  & Attribute , 
312-     psess :  & ParseSess , 
313- )  -> Option < ( MetaItemInner ,  Vec < ( AttrItem ,  Span ) > ) >  { 
313+     sess :  & Session , 
314+     features :  Option < & Features > , 
315+ )  -> Option < ( CfgEntry ,  Vec < ( AttrItem ,  Span ) > ) >  { 
314316    const  CFG_ATTR_GRAMMAR_HELP :  & str  = "#[cfg_attr(condition, attribute, other_attribute, ...)]" ; 
315317    const  CFG_ATTR_NOTE_REF :  & str  = "for more information, visit \  
316318         <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>"; 
@@ -319,9 +321,9 @@ pub fn parse_cfg_attr(
319321        ast:: AttrArgs :: Delimited ( ast:: DelimArgs  {  dspan,  delim,  ref  tokens } ) 
320322            if  !tokens. is_empty ( )  =>
321323        { 
322-             check_cfg_attr_bad_delim ( psess,  dspan,  delim) ; 
323-             match  parse_in ( psess,  tokens. clone ( ) ,  "`cfg_attr` input" ,  |p| { 
324-                 parse_cfg_attr_internal ( p) 
324+             check_cfg_attr_bad_delim ( & sess . psess ,  dspan,  delim) ; 
325+             match  parse_in ( & sess . psess ,  tokens. clone ( ) ,  "`cfg_attr` input" ,  |p| { 
326+                 parse_cfg_attr_internal ( p,  sess ,  features ) 
325327            } )  { 
326328                Ok ( r)  => return  Some ( r) , 
327329                Err ( e)  => { 
@@ -332,8 +334,7 @@ pub fn parse_cfg_attr(
332334            } 
333335        } 
334336        _ => { 
335-             psess
336-                 . dcx ( ) 
337+             sess. dcx ( ) 
337338                . emit_err ( MalformedCfgAttr  {  span :  cfg_attr. span ,  sugg :  CFG_ATTR_GRAMMAR_HELP  } ) ; 
338339        } 
339340    } 
@@ -353,8 +354,33 @@ fn check_cfg_attr_bad_delim(psess: &ParseSess, span: DelimSpan, delim: Delimiter
353354/// Parses `cfg_attr(pred, attr_item_list)` where `attr_item_list` is comma-delimited. 
354355fn  parse_cfg_attr_internal < ' a > ( 
355356    parser :  & mut  Parser < ' a > , 
356- )  -> PResult < ' a ,  ( ast:: MetaItemInner ,  Vec < ( ast:: AttrItem ,  Span ) > ) >  { 
357-     let  cfg_predicate = parser. parse_meta_item_inner ( ) ?; 
357+     sess :  & ' a  Session , 
358+     features :  Option < & Features > , 
359+ )  -> PResult < ' a ,  ( CfgEntry ,  Vec < ( ast:: AttrItem ,  Span ) > ) >  { 
360+     // Parse cfg predicate 
361+     let  pred_start = parser. token . span ; 
362+     let  meta = MetaItemOrLitParser :: parse_single ( parser,  ShouldEmit :: ErrorsAndLints ) ?; 
363+     let  pred_span = pred_start. with_hi ( parser. token . span . hi ( ) ) ; 
364+ 
365+     let  cfg_predicate = AttributeParser :: parse_single_sub ( 
366+         sess, 
367+         pred_span, 
368+         pred_span, 
369+         CRATE_NODE_ID , 
370+         features, 
371+         ShouldEmit :: ErrorsAndLints , 
372+         & meta, 
373+         parse_cfg_entry, 
374+         & CFG_TEMPLATE , 
375+     ) 
376+     . ok_or_else ( || { 
377+         let  mut  diag = sess. dcx ( ) . struct_err ( 
378+             "cfg_entry parsing failing with `ShouldEmit::ErrorsAndLints` should emit a error." , 
379+         ) ; 
380+         diag. downgrade_to_delayed_bug ( ) ; 
381+         diag
382+     } ) ?; 
383+ 
358384    parser. expect ( exp ! ( Comma ) ) ?; 
359385
360386    // Presumably, the majority of the time there will only be one attr. 
0 commit comments