@@ -5,7 +5,7 @@ use rustc_ast::token::{DelimToken, Token, TokenKind};
55use  rustc_ast:: tokenstream:: { AttrAnnotatedTokenStream ,  AttrAnnotatedTokenTree } ; 
66use  rustc_ast:: tokenstream:: { DelimSpan ,  Spacing } ; 
77use  rustc_ast:: tokenstream:: { LazyTokenStream ,  TokenTree } ; 
8- use  rustc_ast:: { self  as  ast,  AstLike ,  AttrItem ,   AttrStyle ,  Attribute ,  MetaItem } ; 
8+ use  rustc_ast:: { self  as  ast,  AstLike ,  AttrStyle ,  Attribute ,  MetaItem } ; 
99use  rustc_attr as  attr; 
1010use  rustc_data_structures:: fx:: FxHashMap ; 
1111use  rustc_data_structures:: map_in_place:: MapInPlace ; 
@@ -14,7 +14,7 @@ use rustc_feature::{Feature, Features, State as FeatureState};
1414use  rustc_feature:: { 
1515    ACCEPTED_FEATURES ,  ACTIVE_FEATURES ,  REMOVED_FEATURES ,  STABLE_REMOVED_FEATURES , 
1616} ; 
17- use  rustc_parse:: { parse_in ,   validate_attr} ; 
17+ use  rustc_parse:: validate_attr; 
1818use  rustc_session:: parse:: feature_err; 
1919use  rustc_session:: Session ; 
2020use  rustc_span:: edition:: { Edition ,  ALL_EDITIONS } ; 
@@ -75,7 +75,7 @@ fn get_features(
7575    // Process the edition umbrella feature-gates first, to ensure 
7676    // `edition_enabled_features` is completed before it's queried. 
7777    for  attr in  krate_attrs { 
78-         if  !sess . check_name ( attr ,   sym:: feature)  { 
78+         if  !attr . has_name ( sym:: feature)  { 
7979            continue ; 
8080        } 
8181
@@ -108,7 +108,7 @@ fn get_features(
108108    } 
109109
110110    for  attr in  krate_attrs { 
111-         if  !sess . check_name ( attr ,   sym:: feature)  { 
111+         if  !attr . has_name ( sym:: feature)  { 
112112            continue ; 
113113        } 
114114
@@ -237,11 +237,6 @@ macro_rules! configure {
237237    } ; 
238238} 
239239
240- const  CFG_ATTR_GRAMMAR_HELP :  & str  = "#[cfg_attr(condition, attribute, other_attribute, ...)]" ; 
241- const  CFG_ATTR_NOTE_REF :  & str  = "for more information, visit \  
242- \ 
243- ; 
244- 
245240impl < ' a >  StripUnconfigured < ' a >  { 
246241    pub  fn  configure < T :  AstLike > ( & mut  self ,  mut  node :  T )  -> Option < T >  { 
247242        self . process_cfg_attrs ( & mut  node) ; 
@@ -349,19 +344,17 @@ impl<'a> StripUnconfigured<'a> {
349344            return  vec ! [ attr] ; 
350345        } 
351346
352-         let  ( cfg_predicate,  expanded_attrs)  = match  self . parse_cfg_attr ( & attr)  { 
353-             None  => return  vec ! [ ] , 
354-             Some ( r)  => r, 
355-         } ; 
347+         let  ( cfg_predicate,  expanded_attrs)  =
348+             match  rustc_parse:: parse_cfg_attr ( & attr,  & self . sess . parse_sess )  { 
349+                 None  => return  vec ! [ ] , 
350+                 Some ( r)  => r, 
351+             } ; 
356352
357353        // Lint on zero attributes in source. 
358354        if  expanded_attrs. is_empty ( )  { 
359355            return  vec ! [ attr] ; 
360356        } 
361357
362-         // At this point we know the attribute is considered used. 
363-         self . sess . mark_attr_used ( & attr) ; 
364- 
365358        if  !attr:: cfg_matches ( & cfg_predicate,  & self . sess . parse_sess ,  self . features )  { 
366359            return  vec ! [ ] ; 
367360        } 
@@ -415,46 +408,10 @@ impl<'a> StripUnconfigured<'a> {
415408            . collect ( ) 
416409    } 
417410
418-     fn  parse_cfg_attr ( & self ,  attr :  & Attribute )  -> Option < ( MetaItem ,  Vec < ( AttrItem ,  Span ) > ) >  { 
419-         match  attr. get_normal_item ( ) . args  { 
420-             ast:: MacArgs :: Delimited ( dspan,  delim,  ref  tts)  if  !tts. is_empty ( )  => { 
421-                 let  msg = "wrong `cfg_attr` delimiters" ; 
422-                 validate_attr:: check_meta_bad_delim ( & self . sess . parse_sess ,  dspan,  delim,  msg) ; 
423-                 match  parse_in ( & self . sess . parse_sess ,  tts. clone ( ) ,  "`cfg_attr` input" ,  |p| { 
424-                     p. parse_cfg_attr ( ) 
425-                 } )  { 
426-                     Ok ( r)  => return  Some ( r) , 
427-                     Err ( mut  e)  => { 
428-                         e. help ( & format ! ( "the valid syntax is `{}`" ,  CFG_ATTR_GRAMMAR_HELP ) ) 
429-                             . note ( CFG_ATTR_NOTE_REF ) 
430-                             . emit ( ) ; 
431-                     } 
432-                 } 
433-             } 
434-             _ => self . error_malformed_cfg_attr_missing ( attr. span ) , 
435-         } 
436-         None 
437-     } 
438- 
439-     fn  error_malformed_cfg_attr_missing ( & self ,  span :  Span )  { 
440-         self . sess 
441-             . parse_sess 
442-             . span_diagnostic 
443-             . struct_span_err ( span,  "malformed `cfg_attr` attribute input" ) 
444-             . span_suggestion ( 
445-                 span, 
446-                 "missing condition and attribute" , 
447-                 CFG_ATTR_GRAMMAR_HELP . to_string ( ) , 
448-                 Applicability :: HasPlaceholders , 
449-             ) 
450-             . note ( CFG_ATTR_NOTE_REF ) 
451-             . emit ( ) ; 
452-     } 
453- 
454411    /// Determines if a node with the given attributes should be included in this configuration. 
455412fn  in_cfg ( & self ,  attrs :  & [ Attribute ] )  -> bool  { 
456413        attrs. iter ( ) . all ( |attr| { 
457-             if  !is_cfg ( self . sess ,   attr)  { 
414+             if  !is_cfg ( attr)  { 
458415                return  true ; 
459416            } 
460417            let  meta_item = match  validate_attr:: parse_meta ( & self . sess . parse_sess ,  attr)  { 
@@ -500,7 +457,7 @@ impl<'a> StripUnconfigured<'a> {
500457        // 
501458        // N.B., this is intentionally not part of the visit_expr() function 
502459        //     in order for filter_map_expr() to be able to avoid this check 
503-         if  let  Some ( attr)  = expr. attrs ( ) . iter ( ) . find ( |a| is_cfg ( self . sess ,   a) )  { 
460+         if  let  Some ( attr)  = expr. attrs ( ) . iter ( ) . find ( |a| is_cfg ( * a) )  { 
504461            let  msg = "removing an expression is not supported in this position" ; 
505462            self . sess . parse_sess . span_diagnostic . span_err ( attr. span ,  msg) ; 
506463        } 
@@ -536,6 +493,6 @@ pub fn parse_cfg<'a>(meta_item: &'a MetaItem, sess: &Session) -> Option<&'a Meta
536493    } 
537494} 
538495
539- fn  is_cfg ( sess :   & Session ,   attr :  & Attribute )  -> bool  { 
540-     sess . check_name ( attr ,   sym:: cfg) 
496+ fn  is_cfg ( attr :  & Attribute )  -> bool  { 
497+     attr . has_name ( sym:: cfg) 
541498} 
0 commit comments