@@ -266,7 +266,7 @@ fn process_mod(mod_info: ModInfo, force: bool) -> std::io::Result<()> {
266
266
267
267
let mut con_items: Vec < Item > = ast. items . clone ( ) ;
268
268
let mut spec_items: Vec < Item > = Default :: default ( ) ;
269
- transform_macro_items ( & mut con_items, & mut spec_items) ;
269
+ transform_ast ( & mut con_items, & mut spec_items) ;
270
270
271
271
let duration = start. elapsed ( ) ;
272
272
@@ -522,42 +522,75 @@ impl InterfaceType {
522
522
}
523
523
}
524
524
525
- fn transform_macro_items ( items : & mut Vec < Item > , added_items : & mut Vec < Item > ) {
526
- items. retain ( |item| {
525
+ fn transform_ast ( items : & mut Vec < Item > , added_items : & mut Vec < Item > ) {
526
+ items. retain_mut ( |item| {
527
527
let mut keep = true ;
528
- if let Item :: Impl ( imp) = item {
529
- for attr in & imp. attrs {
530
- if attr. path ( ) . segments . len ( ) == 2
531
- && attr. path ( ) . segments [ 0 ] . ident == "dylo"
532
- && attr. path ( ) . segments [ 1 ] . ident == "export"
533
- {
534
- let iface_typ = if let Ok ( _meta) = attr. meta . require_path_only ( ) {
535
- Some ( InterfaceType :: Sync )
536
- } else if let Ok ( list) = attr. meta . require_list ( ) {
537
- if list. tokens . to_string ( ) . contains ( "nonsync" ) {
538
- Some ( InterfaceType :: NonSync )
528
+
529
+ match item {
530
+ Item :: Impl ( imp) => {
531
+ for attr in & imp. attrs {
532
+ if attr. path ( ) . segments . len ( ) == 2
533
+ && attr. path ( ) . segments [ 0 ] . ident == "dylo"
534
+ && attr. path ( ) . segments [ 1 ] . ident == "export"
535
+ {
536
+ let iface_typ = if let Ok ( _meta) = attr. meta . require_path_only ( ) {
537
+ Some ( InterfaceType :: Sync )
538
+ } else if let Ok ( list) = attr. meta . require_list ( ) {
539
+ if list. tokens . to_string ( ) . contains ( "nonsync" ) {
540
+ Some ( InterfaceType :: NonSync )
541
+ } else {
542
+ None
543
+ }
539
544
} else {
540
545
None
541
- }
542
- } else {
543
- None
544
- } ;
546
+ } ;
545
547
546
- if let Some ( iface_typ) = iface_typ {
547
- let tokens = ( & imp) . into_token_stream ( ) ;
548
- added_items. push ( declare_trait ( & tokens, & iface_typ) [ 0 ] . clone ( ) ) ;
548
+ if let Some ( iface_typ) = iface_typ {
549
+ let tokens = ( & imp) . into_token_stream ( ) ;
550
+ added_items. push ( declare_trait ( & tokens, & iface_typ) [ 0 ] . clone ( ) ) ;
551
+ }
552
+ keep = false
549
553
}
550
- keep = false
551
554
}
552
555
}
556
+ Item :: Enum ( enm) => {
557
+ filter_out_cfg_attr_impl ( & mut enm. attrs ) ;
558
+ }
559
+ Item :: Struct ( stru) => {
560
+ filter_out_cfg_attr_impl ( & mut stru. attrs ) ;
561
+ for f in stru. fields . iter_mut ( ) {
562
+ filter_out_cfg_attr_impl ( & mut f. attrs ) ;
563
+ }
564
+ }
565
+ _ => {
566
+ // ignore
567
+ }
553
568
}
569
+
554
570
if should_remove_item ( item) {
555
571
keep = false
556
572
}
557
573
keep
558
574
} ) ;
559
575
}
560
576
577
+ fn filter_out_cfg_attr_impl ( attrs : & mut Vec < Attribute > ) {
578
+ attrs. retain_mut ( |attr| {
579
+ if let syn:: Meta :: List ( list) = & attr. meta {
580
+ if let Some ( path_segment) = list. path . segments . first ( ) {
581
+ if path_segment. ident == "cfg_attr" {
582
+ if let Some ( nested) = list. tokens . to_string ( ) . split ( "," ) . next ( ) {
583
+ if nested. contains ( "feature" ) && nested. contains ( "\" impl\" " ) {
584
+ return false ;
585
+ }
586
+ }
587
+ }
588
+ }
589
+ }
590
+ true
591
+ } )
592
+ }
593
+
561
594
fn declare_trait ( tokens : & proc_macro2:: TokenStream , iface_typ : & InterfaceType ) -> Vec < Item > {
562
595
let mut added_items = Vec :: new ( ) ;
563
596
let file = syn:: parse2 :: < syn:: File > ( tokens. clone ( ) ) . unwrap ( ) ;
0 commit comments