@@ -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 )
@@ -845,8 +849,8 @@ pub fn noop_fold_typedef<T>(t: Typedef, folder: &mut T)
845
849
where T : Folder {
846
850
let new_id = folder. new_id ( t. id ) ;
847
851
let new_span = folder. new_span ( t. span ) ;
848
- let new_attrs = t. attrs . iter ( ) . map ( |attr| {
849
- folder. fold_attribute ( ( * attr) . clone ( ) )
852
+ let new_attrs = t. attrs . iter ( ) . flat_map ( |attr| {
853
+ folder. fold_attribute ( ( * attr) . clone ( ) ) . into_iter ( )
850
854
} ) . collect ( ) ;
851
855
let new_ident = folder. fold_ident ( t. ident ) ;
852
856
let new_type = folder. fold_ty ( t. typ ) ;
@@ -866,7 +870,7 @@ pub fn noop_fold_associated_type<T>(at: AssociatedType, folder: &mut T)
866
870
{
867
871
let new_attrs = at. attrs
868
872
. iter ( )
869
- . map ( |attr| folder. fold_attribute ( ( * attr) . clone ( ) ) )
873
+ . flat_map ( |attr| folder. fold_attribute ( ( * attr) . clone ( ) ) . into_iter ( ) )
870
874
. collect ( ) ;
871
875
let new_param = folder. fold_ty_param ( at. ty_param ) ;
872
876
ast:: AssociatedType {
@@ -909,7 +913,7 @@ pub fn noop_fold_struct_field<T: Folder>(f: StructField, fld: &mut T) -> StructF
909
913
id : fld. new_id ( id) ,
910
914
kind : kind,
911
915
ty : fld. fold_ty ( ty) ,
912
- attrs : attrs . move_map ( |a| fld. fold_attribute ( a ) )
916
+ attrs : fold_attrs ( attrs , fld) ,
913
917
} ,
914
918
span : fld. new_span ( span)
915
919
}
@@ -1072,7 +1076,7 @@ pub fn noop_fold_type_method<T: Folder>(m: TypeMethod, fld: &mut T) -> TypeMetho
1072
1076
TypeMethod {
1073
1077
id : fld. new_id ( id) ,
1074
1078
ident : fld. fold_ident ( ident) ,
1075
- attrs : attrs . move_map ( |a| fld. fold_attribute ( a ) ) ,
1079
+ attrs : fold_attrs ( attrs , fld) ,
1076
1080
unsafety : unsafety,
1077
1081
abi : abi,
1078
1082
decl : fld. fold_fn_decl ( decl) ,
@@ -1154,7 +1158,7 @@ pub fn noop_fold_item_simple<T: Folder>(Item {id, ident, attrs, node, vis, span}
1154
1158
Item {
1155
1159
id : id,
1156
1160
ident : folder. fold_ident ( ident) ,
1157
- attrs : attrs . move_map ( |e| folder. fold_attribute ( e ) ) ,
1161
+ attrs : fold_attrs ( attrs , folder) ,
1158
1162
node : node,
1159
1163
vis : vis,
1160
1164
span : folder. new_span ( span)
@@ -1165,7 +1169,7 @@ pub fn noop_fold_foreign_item<T: Folder>(ni: P<ForeignItem>, folder: &mut T) ->
1165
1169
ni. map ( |ForeignItem { id, ident, attrs, node, span, vis} | ForeignItem {
1166
1170
id : folder. new_id ( id) ,
1167
1171
ident : folder. fold_ident ( ident) ,
1168
- attrs : attrs . move_map ( |x| folder. fold_attribute ( x ) ) ,
1172
+ attrs : fold_attrs ( attrs , folder) ,
1169
1173
node : match node {
1170
1174
ForeignItemFn ( fdec, generics) => {
1171
1175
ForeignItemFn ( folder. fold_fn_decl ( fdec) , folder. fold_generics ( generics) )
@@ -1184,7 +1188,7 @@ pub fn noop_fold_foreign_item<T: Folder>(ni: P<ForeignItem>, folder: &mut T) ->
1184
1188
pub fn noop_fold_method < T : Folder > ( m : P < Method > , folder : & mut T ) -> SmallVector < P < Method > > {
1185
1189
SmallVector :: one ( m. map ( |Method { id, attrs, node, span} | Method {
1186
1190
id : folder. new_id ( id) ,
1187
- attrs : attrs . move_map ( |a| folder. fold_attribute ( a ) ) ,
1191
+ attrs : fold_attrs ( attrs , folder) ,
1188
1192
node : match node {
1189
1193
MethDecl ( ident,
1190
1194
generics,
0 commit comments