@@ -5,7 +5,7 @@ use rustc_ast::token::{DelimToken, Token, TokenKind};
5
5
use rustc_ast:: tokenstream:: { AttrAnnotatedTokenStream , AttrAnnotatedTokenTree } ;
6
6
use rustc_ast:: tokenstream:: { DelimSpan , Spacing } ;
7
7
use 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 } ;
9
9
use rustc_attr as attr;
10
10
use rustc_data_structures:: fx:: FxHashMap ;
11
11
use rustc_data_structures:: map_in_place:: MapInPlace ;
@@ -14,7 +14,7 @@ use rustc_feature::{Feature, Features, State as FeatureState};
14
14
use rustc_feature:: {
15
15
ACCEPTED_FEATURES , ACTIVE_FEATURES , REMOVED_FEATURES , STABLE_REMOVED_FEATURES ,
16
16
} ;
17
- use rustc_parse:: { parse_in , validate_attr} ;
17
+ use rustc_parse:: validate_attr;
18
18
use rustc_session:: parse:: feature_err;
19
19
use rustc_session:: Session ;
20
20
use rustc_span:: edition:: { Edition , ALL_EDITIONS } ;
@@ -75,7 +75,7 @@ fn get_features(
75
75
// Process the edition umbrella feature-gates first, to ensure
76
76
// `edition_enabled_features` is completed before it's queried.
77
77
for attr in krate_attrs {
78
- if !sess . check_name ( attr , sym:: feature) {
78
+ if !attr . has_name ( sym:: feature) {
79
79
continue ;
80
80
}
81
81
@@ -108,7 +108,7 @@ fn get_features(
108
108
}
109
109
110
110
for attr in krate_attrs {
111
- if !sess . check_name ( attr , sym:: feature) {
111
+ if !attr . has_name ( sym:: feature) {
112
112
continue ;
113
113
}
114
114
@@ -237,11 +237,6 @@ macro_rules! configure {
237
237
} ;
238
238
}
239
239
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
- <https://doc.rust-lang.org/reference/conditional-compilation.html\
243
- #the-cfg_attr-attribute>";
244
-
245
240
impl < ' a > StripUnconfigured < ' a > {
246
241
pub fn configure < T : AstLike > ( & mut self , mut node : T ) -> Option < T > {
247
242
self . process_cfg_attrs ( & mut node) ;
@@ -349,19 +344,17 @@ impl<'a> StripUnconfigured<'a> {
349
344
return vec ! [ attr] ;
350
345
}
351
346
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
+ } ;
356
352
357
353
// Lint on zero attributes in source.
358
354
if expanded_attrs. is_empty ( ) {
359
355
return vec ! [ attr] ;
360
356
}
361
357
362
- // At this point we know the attribute is considered used.
363
- self . sess . mark_attr_used ( & attr) ;
364
-
365
358
if !attr:: cfg_matches ( & cfg_predicate, & self . sess . parse_sess , self . features ) {
366
359
return vec ! [ ] ;
367
360
}
@@ -415,46 +408,10 @@ impl<'a> StripUnconfigured<'a> {
415
408
. collect ( )
416
409
}
417
410
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
-
454
411
/// Determines if a node with the given attributes should be included in this configuration.
455
412
fn in_cfg ( & self , attrs : & [ Attribute ] ) -> bool {
456
413
attrs. iter ( ) . all ( |attr| {
457
- if !is_cfg ( self . sess , attr) {
414
+ if !is_cfg ( attr) {
458
415
return true ;
459
416
}
460
417
let meta_item = match validate_attr:: parse_meta ( & self . sess . parse_sess , attr) {
@@ -500,7 +457,7 @@ impl<'a> StripUnconfigured<'a> {
500
457
//
501
458
// N.B., this is intentionally not part of the visit_expr() function
502
459
// 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) ) {
504
461
let msg = "removing an expression is not supported in this position" ;
505
462
self . sess . parse_sess . span_diagnostic . span_err ( attr. span , msg) ;
506
463
}
@@ -536,6 +493,6 @@ pub fn parse_cfg<'a>(meta_item: &'a MetaItem, sess: &Session) -> Option<&'a Meta
536
493
}
537
494
}
538
495
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)
541
498
}
0 commit comments