@@ -223,7 +223,7 @@ pub trait Folder : Sized {
223
223
noop_fold_lifetime_def ( l, self )
224
224
}
225
225
226
- fn fold_attribute ( & mut self , at : Attribute ) -> Attribute {
226
+ fn fold_attribute ( & mut self , at : Attribute ) -> Option < Attribute > {
227
227
noop_fold_attribute ( at, self )
228
228
}
229
229
@@ -373,9 +373,13 @@ pub fn noop_fold_view_path<T: Folder>(view_path: P<ViewPath>, fld: &mut T) -> P<
373
373
} )
374
374
}
375
375
376
+ pub fn fold_attrs < T : Folder > ( attrs : Vec < Attribute > , fld : & mut T ) -> Vec < Attribute > {
377
+ attrs. into_iter ( ) . flat_map ( |x| fld. fold_attribute ( x) . into_iter ( ) ) . collect ( )
378
+ }
379
+
376
380
pub fn noop_fold_arm < T : Folder > ( Arm { attrs, pats, guard, body} : Arm , fld : & mut T ) -> Arm {
377
381
Arm {
378
- attrs : attrs . move_map ( |x| fld. fold_attribute ( x ) ) ,
382
+ attrs : fold_attrs ( attrs , fld) ,
379
383
pats : pats. move_map ( |x| fld. fold_pat ( x) ) ,
380
384
guard : guard. map ( |x| fld. fold_expr ( x) ) ,
381
385
body : fld. fold_expr ( body) ,
@@ -475,7 +479,7 @@ pub fn noop_fold_variant<T: Folder>(v: P<Variant>, fld: &mut T) -> P<Variant> {
475
479
node : Variant_ {
476
480
id : fld. new_id ( id) ,
477
481
name : name,
478
- attrs : attrs . move_map ( |x| fld. fold_attribute ( x ) ) ,
482
+ attrs : fold_attrs ( attrs , fld) ,
479
483
kind : match kind {
480
484
TupleVariantKind ( variant_args) => {
481
485
TupleVariantKind ( variant_args. move_map ( |x|
@@ -553,17 +557,17 @@ pub fn noop_fold_local<T: Folder>(l: P<Local>, fld: &mut T) -> P<Local> {
553
557
} )
554
558
}
555
559
556
- pub fn noop_fold_attribute < T : Folder > ( at : Attribute , fld : & mut T ) -> Attribute {
560
+ pub fn noop_fold_attribute < T : Folder > ( at : Attribute , fld : & mut T ) -> Option < Attribute > {
557
561
let Spanned { node : Attribute_ { id, style, value, is_sugared_doc} , span} = at;
558
- Spanned {
562
+ Some ( Spanned {
559
563
node : Attribute_ {
560
564
id : id,
561
565
style : style,
562
566
value : fld. fold_meta_item ( value) ,
563
567
is_sugared_doc : is_sugared_doc
564
568
} ,
565
569
span : fld. new_span ( span)
566
- }
570
+ } )
567
571
}
568
572
569
573
pub fn noop_fold_explicit_self_underscore < T : Folder > ( es : ExplicitSelf_ , fld : & mut T )
@@ -843,8 +847,8 @@ pub fn noop_fold_typedef<T>(t: Typedef, folder: &mut T)
843
847
where T : Folder {
844
848
let new_id = folder. new_id ( t. id ) ;
845
849
let new_span = folder. new_span ( t. span ) ;
846
- let new_attrs = t. attrs . iter ( ) . map ( |attr| {
847
- folder. fold_attribute ( ( * attr) . clone ( ) )
850
+ let new_attrs = t. attrs . iter ( ) . flat_map ( |attr| {
851
+ folder. fold_attribute ( ( * attr) . clone ( ) ) . into_iter ( )
848
852
} ) . collect ( ) ;
849
853
let new_ident = folder. fold_ident ( t. ident ) ;
850
854
let new_type = folder. fold_ty ( t. typ ) ;
@@ -864,7 +868,7 @@ pub fn noop_fold_associated_type<T>(at: AssociatedType, folder: &mut T)
864
868
{
865
869
let new_attrs = at. attrs
866
870
. iter ( )
867
- . map ( |attr| folder. fold_attribute ( ( * attr) . clone ( ) ) )
871
+ . flat_map ( |attr| folder. fold_attribute ( ( * attr) . clone ( ) ) . into_iter ( ) )
868
872
. collect ( ) ;
869
873
let new_param = folder. fold_ty_param ( at. ty_param ) ;
870
874
ast:: AssociatedType {
@@ -906,7 +910,7 @@ pub fn noop_fold_struct_field<T: Folder>(f: StructField, fld: &mut T) -> StructF
906
910
id : fld. new_id ( id) ,
907
911
kind : kind,
908
912
ty : fld. fold_ty ( ty) ,
909
- attrs : attrs . move_map ( |a| fld. fold_attribute ( a ) )
913
+ attrs : fold_attrs ( attrs , fld) ,
910
914
} ,
911
915
span : fld. new_span ( span)
912
916
}
@@ -1069,7 +1073,7 @@ pub fn noop_fold_type_method<T: Folder>(m: TypeMethod, fld: &mut T) -> TypeMetho
1069
1073
TypeMethod {
1070
1074
id : fld. new_id ( id) ,
1071
1075
ident : fld. fold_ident ( ident) ,
1072
- attrs : attrs . move_map ( |a| fld. fold_attribute ( a ) ) ,
1076
+ attrs : fold_attrs ( attrs , fld) ,
1073
1077
unsafety : unsafety,
1074
1078
abi : abi,
1075
1079
decl : fld. fold_fn_decl ( decl) ,
@@ -1151,7 +1155,7 @@ pub fn noop_fold_item_simple<T: Folder>(Item {id, ident, attrs, node, vis, span}
1151
1155
Item {
1152
1156
id : id,
1153
1157
ident : folder. fold_ident ( ident) ,
1154
- attrs : attrs . move_map ( |e| folder. fold_attribute ( e ) ) ,
1158
+ attrs : fold_attrs ( attrs , folder) ,
1155
1159
node : node,
1156
1160
vis : vis,
1157
1161
span : folder. new_span ( span)
@@ -1162,7 +1166,7 @@ pub fn noop_fold_foreign_item<T: Folder>(ni: P<ForeignItem>, folder: &mut T) ->
1162
1166
ni. map ( |ForeignItem { id, ident, attrs, node, span, vis} | ForeignItem {
1163
1167
id : folder. new_id ( id) ,
1164
1168
ident : folder. fold_ident ( ident) ,
1165
- attrs : attrs . move_map ( |x| folder. fold_attribute ( x ) ) ,
1169
+ attrs : fold_attrs ( attrs , folder) ,
1166
1170
node : match node {
1167
1171
ForeignItemFn ( fdec, generics) => {
1168
1172
ForeignItemFn ( folder. fold_fn_decl ( fdec) , folder. fold_generics ( generics) )
@@ -1181,7 +1185,7 @@ pub fn noop_fold_foreign_item<T: Folder>(ni: P<ForeignItem>, folder: &mut T) ->
1181
1185
pub fn noop_fold_method < T : Folder > ( m : P < Method > , folder : & mut T ) -> SmallVector < P < Method > > {
1182
1186
SmallVector :: one ( m. map ( |Method { id, attrs, node, span} | Method {
1183
1187
id : folder. new_id ( id) ,
1184
- attrs : attrs . move_map ( |a| folder. fold_attribute ( a ) ) ,
1188
+ attrs : fold_attrs ( attrs , folder) ,
1185
1189
node : match node {
1186
1190
MethDecl ( ident,
1187
1191
generics,
0 commit comments