@@ -223,7 +223,7 @@ pub trait Folder : Sized {
223223 noop_fold_lifetime_def ( l, self )
224224 }
225225
226- fn fold_attribute ( & mut self , at : Attribute ) -> Attribute {
226+ fn fold_attribute ( & mut self , at : Attribute ) -> Option < Attribute > {
227227 noop_fold_attribute ( at, self )
228228 }
229229
@@ -373,9 +373,13 @@ pub fn noop_fold_view_path<T: Folder>(view_path: P<ViewPath>, fld: &mut T) -> P<
373373 } )
374374}
375375
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+
376380pub fn noop_fold_arm < T : Folder > ( Arm { attrs, pats, guard, body} : Arm , fld : & mut T ) -> Arm {
377381 Arm {
378- attrs : attrs . move_map ( |x| fld. fold_attribute ( x ) ) ,
382+ attrs : fold_attrs ( attrs , fld) ,
379383 pats : pats. move_map ( |x| fld. fold_pat ( x) ) ,
380384 guard : guard. map ( |x| fld. fold_expr ( x) ) ,
381385 body : fld. fold_expr ( body) ,
@@ -475,7 +479,7 @@ pub fn noop_fold_variant<T: Folder>(v: P<Variant>, fld: &mut T) -> P<Variant> {
475479 node : Variant_ {
476480 id : fld. new_id ( id) ,
477481 name : name,
478- attrs : attrs . move_map ( |x| fld. fold_attribute ( x ) ) ,
482+ attrs : fold_attrs ( attrs , fld) ,
479483 kind : match kind {
480484 TupleVariantKind ( variant_args) => {
481485 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> {
553557 } )
554558}
555559
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 > {
557561 let Spanned { node : Attribute_ { id, style, value, is_sugared_doc} , span} = at;
558- Spanned {
562+ Some ( Spanned {
559563 node : Attribute_ {
560564 id : id,
561565 style : style,
562566 value : fld. fold_meta_item ( value) ,
563567 is_sugared_doc : is_sugared_doc
564568 } ,
565569 span : fld. new_span ( span)
566- }
570+ } )
567571}
568572
569573pub 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)
845849 where T : Folder {
846850 let new_id = folder. new_id ( t. id ) ;
847851 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 ( )
850854 } ) . collect ( ) ;
851855 let new_ident = folder. fold_ident ( t. ident ) ;
852856 let new_type = folder. fold_ty ( t. typ ) ;
@@ -866,7 +870,7 @@ pub fn noop_fold_associated_type<T>(at: AssociatedType, folder: &mut T)
866870{
867871 let new_attrs = at. attrs
868872 . iter ( )
869- . map ( |attr| folder. fold_attribute ( ( * attr) . clone ( ) ) )
873+ . flat_map ( |attr| folder. fold_attribute ( ( * attr) . clone ( ) ) . into_iter ( ) )
870874 . collect ( ) ;
871875 let new_param = folder. fold_ty_param ( at. ty_param ) ;
872876 ast:: AssociatedType {
@@ -909,7 +913,7 @@ pub fn noop_fold_struct_field<T: Folder>(f: StructField, fld: &mut T) -> StructF
909913 id : fld. new_id ( id) ,
910914 kind : kind,
911915 ty : fld. fold_ty ( ty) ,
912- attrs : attrs . move_map ( |a| fld. fold_attribute ( a ) )
916+ attrs : fold_attrs ( attrs , fld) ,
913917 } ,
914918 span : fld. new_span ( span)
915919 }
@@ -1072,7 +1076,7 @@ pub fn noop_fold_type_method<T: Folder>(m: TypeMethod, fld: &mut T) -> TypeMetho
10721076 TypeMethod {
10731077 id : fld. new_id ( id) ,
10741078 ident : fld. fold_ident ( ident) ,
1075- attrs : attrs . move_map ( |a| fld. fold_attribute ( a ) ) ,
1079+ attrs : fold_attrs ( attrs , fld) ,
10761080 unsafety : unsafety,
10771081 abi : abi,
10781082 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}
11541158 Item {
11551159 id : id,
11561160 ident : folder. fold_ident ( ident) ,
1157- attrs : attrs . move_map ( |e| folder. fold_attribute ( e ) ) ,
1161+ attrs : fold_attrs ( attrs , folder) ,
11581162 node : node,
11591163 vis : vis,
11601164 span : folder. new_span ( span)
@@ -1165,7 +1169,7 @@ pub fn noop_fold_foreign_item<T: Folder>(ni: P<ForeignItem>, folder: &mut T) ->
11651169 ni. map ( |ForeignItem { id, ident, attrs, node, span, vis} | ForeignItem {
11661170 id : folder. new_id ( id) ,
11671171 ident : folder. fold_ident ( ident) ,
1168- attrs : attrs . move_map ( |x| folder. fold_attribute ( x ) ) ,
1172+ attrs : fold_attrs ( attrs , folder) ,
11691173 node : match node {
11701174 ForeignItemFn ( fdec, generics) => {
11711175 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) ->
11841188pub fn noop_fold_method < T : Folder > ( m : P < Method > , folder : & mut T ) -> SmallVector < P < Method > > {
11851189 SmallVector :: one ( m. map ( |Method { id, attrs, node, span} | Method {
11861190 id : folder. new_id ( id) ,
1187- attrs : attrs . move_map ( |a| folder. fold_attribute ( a ) ) ,
1191+ attrs : fold_attrs ( attrs , folder) ,
11881192 node : match node {
11891193 MethDecl ( ident,
11901194 generics,
0 commit comments