@@ -197,11 +197,11 @@ fn introspect_features(attrs: &[Attribute]) -> types::Features {
197
197
let mut ret = types:: Features :: default ( ) ;
198
198
199
199
for attr in attrs {
200
- if !attr. path . is_ident ( "cfg" ) {
200
+ if !attr. path ( ) . is_ident ( "cfg" ) {
201
201
continue ;
202
202
}
203
203
204
- let features = parsing:: parse_features. parse2 ( attr . tokens . clone ( ) ) . unwrap ( ) ;
204
+ let features = attr . parse_args_with ( parsing:: parse_features) . unwrap ( ) ;
205
205
206
206
if ret. any . is_empty ( ) {
207
207
ret = features;
@@ -225,7 +225,7 @@ fn is_pub(vis: &Visibility) -> bool {
225
225
226
226
fn is_non_exhaustive ( attrs : & [ Attribute ] ) -> bool {
227
227
for attr in attrs {
228
- if attr. path . is_ident ( "non_exhaustive" ) {
228
+ if attr. path ( ) . is_ident ( "non_exhaustive" ) {
229
229
return true ;
230
230
}
231
231
}
@@ -234,11 +234,7 @@ fn is_non_exhaustive(attrs: &[Attribute]) -> bool {
234
234
235
235
fn is_doc_hidden ( attrs : & [ Attribute ] ) -> bool {
236
236
for attr in attrs {
237
- if attr. path . is_ident ( "doc" )
238
- && parsing:: parse_doc_hidden_attr
239
- . parse2 ( attr. tokens . clone ( ) )
240
- . is_ok ( )
241
- {
237
+ if attr. path ( ) . is_ident ( "doc" ) && attr. parse_args :: < parsing:: kw:: hidden > ( ) . is_ok ( ) {
242
238
return true ;
243
239
}
244
240
}
@@ -282,9 +278,10 @@ mod parsing {
282
278
use proc_macro2:: TokenStream ;
283
279
use quote:: quote;
284
280
use std:: collections:: { BTreeMap , BTreeSet } ;
285
- use syn:: parse:: { ParseStream , Parser , Result } ;
281
+ use syn:: parse:: { ParseStream , Result } ;
286
282
use syn:: {
287
- braced, bracketed, parenthesized, parse_quote, token, Attribute , Ident , LitStr , Path , Token ,
283
+ braced, bracketed, parenthesized, parse_quote, token, Attribute , Expr , Ident , Lit , LitStr ,
284
+ Path , Token ,
288
285
} ;
289
286
use syn_codegen as types;
290
287
@@ -421,7 +418,7 @@ mod parsing {
421
418
} )
422
419
}
423
420
424
- mod kw {
421
+ pub mod kw {
425
422
syn:: custom_keyword!( hidden) ;
426
423
syn:: custom_keyword!( macro_rules) ;
427
424
syn:: custom_keyword!( Token ) ;
@@ -458,56 +455,43 @@ mod parsing {
458
455
pub fn parse_features ( input : ParseStream ) -> Result < types:: Features > {
459
456
let mut features = BTreeSet :: new ( ) ;
460
457
461
- let level_1;
462
- parenthesized ! ( level_1 in input) ;
463
-
464
- let i: Ident = level_1. fork ( ) . parse ( ) ?;
458
+ let i: Ident = input. fork ( ) . parse ( ) ?;
465
459
466
460
if i == "any" {
467
- level_1 . parse :: < Ident > ( ) ?;
461
+ input . parse :: < Ident > ( ) ?;
468
462
469
- let level_2 ;
470
- parenthesized ! ( level_2 in level_1 ) ;
463
+ let nested ;
464
+ parenthesized ! ( nested in input ) ;
471
465
472
- while !level_2 . is_empty ( ) {
473
- features. insert ( parse_feature ( & level_2 ) ?) ;
466
+ while !nested . is_empty ( ) {
467
+ features. insert ( parse_feature ( & nested ) ?) ;
474
468
475
- if !level_2 . is_empty ( ) {
476
- level_2 . parse :: < Token ! [ , ] > ( ) ?;
469
+ if !nested . is_empty ( ) {
470
+ nested . parse :: < Token ! [ , ] > ( ) ?;
477
471
}
478
472
}
479
473
} else if i == "feature" {
480
- features. insert ( parse_feature ( & level_1 ) ?) ;
481
- assert ! ( level_1 . is_empty( ) ) ;
474
+ features. insert ( parse_feature ( input ) ?) ;
475
+ assert ! ( input . is_empty( ) ) ;
482
476
} else {
483
477
panic ! ( "{:?}" , i) ;
484
478
}
485
479
486
- assert ! ( input. is_empty( ) ) ;
487
-
488
480
Ok ( types:: Features { any : features } )
489
481
}
490
482
491
- pub fn path_attr ( attrs : & [ Attribute ] ) -> Result < Option < LitStr > > {
483
+ pub fn path_attr ( attrs : & [ Attribute ] ) -> Result < Option < & LitStr > > {
492
484
for attr in attrs {
493
- if attr. path . is_ident ( "path" ) {
494
- fn parser ( input : ParseStream ) -> Result < LitStr > {
495
- input. parse :: < Token ! [ =] > ( ) ?;
496
- input. parse ( )
485
+ if attr. path ( ) . is_ident ( "path" ) {
486
+ if let Expr :: Lit ( expr) = & attr. meta . require_name_value ( ) ?. value {
487
+ if let Lit :: Str ( lit) = & expr. lit {
488
+ return Ok ( Some ( lit) ) ;
489
+ }
497
490
}
498
- let filename = parser. parse2 ( attr. tokens . clone ( ) ) ?;
499
- return Ok ( Some ( filename) ) ;
500
491
}
501
492
}
502
493
Ok ( None )
503
494
}
504
-
505
- pub fn parse_doc_hidden_attr ( input : ParseStream ) -> Result < ( ) > {
506
- let content;
507
- parenthesized ! ( content in input) ;
508
- content. parse :: < kw:: hidden > ( ) ?;
509
- Ok ( ( ) )
510
- }
511
495
}
512
496
513
497
fn clone_features ( features : & [ Attribute ] ) -> Vec < Attribute > {
@@ -518,7 +502,7 @@ fn get_features(attrs: &[Attribute], base: &[Attribute]) -> Vec<Attribute> {
518
502
let mut ret = clone_features ( base) ;
519
503
520
504
for attr in attrs {
521
- if attr. path . is_ident ( "cfg" ) {
505
+ if attr. path ( ) . is_ident ( "cfg" ) {
522
506
ret. push ( parse_quote ! ( #attr) ) ;
523
507
}
524
508
}
0 commit comments