@@ -13,6 +13,7 @@ use edition::Edition;
13
13
use parse:: { token, ParseSess } ;
14
14
use smallvec:: SmallVec ;
15
15
use errors:: Applicability ;
16
+ use util:: move_map:: MoveMap ;
16
17
17
18
use ptr:: P ;
18
19
@@ -220,19 +221,19 @@ impl<'a> StripUnconfigured<'a> {
220
221
pub fn configure_foreign_mod ( & mut self , foreign_mod : ast:: ForeignMod ) -> ast:: ForeignMod {
221
222
ast:: ForeignMod {
222
223
abi : foreign_mod. abi ,
223
- items : foreign_mod. items . into_iter ( ) . filter_map ( |item| self . configure ( item) ) . collect ( ) ,
224
+ items : foreign_mod. items . move_flat_map ( |item| self . configure ( item) ) ,
224
225
}
225
226
}
226
227
227
228
fn configure_variant_data ( & mut self , vdata : ast:: VariantData ) -> ast:: VariantData {
228
229
match vdata {
229
230
ast:: VariantData :: Struct ( fields, id) => {
230
- let fields = fields. into_iter ( ) . filter_map ( |field| self . configure ( field) ) ;
231
- ast:: VariantData :: Struct ( fields. collect ( ) , id)
231
+ let fields = fields. move_flat_map ( |field| self . configure ( field) ) ;
232
+ ast:: VariantData :: Struct ( fields, id)
232
233
}
233
234
ast:: VariantData :: Tuple ( fields, id) => {
234
- let fields = fields. into_iter ( ) . filter_map ( |field| self . configure ( field) ) ;
235
- ast:: VariantData :: Tuple ( fields. collect ( ) , id)
235
+ let fields = fields. move_flat_map ( |field| self . configure ( field) ) ;
236
+ ast:: VariantData :: Tuple ( fields, id)
236
237
}
237
238
ast:: VariantData :: Unit ( id) => ast:: VariantData :: Unit ( id)
238
239
}
@@ -247,7 +248,7 @@ impl<'a> StripUnconfigured<'a> {
247
248
ast:: ItemKind :: Union ( self . configure_variant_data ( def) , generics)
248
249
}
249
250
ast:: ItemKind :: Enum ( def, generics) => {
250
- let variants = def. variants . into_iter ( ) . filter_map ( |v| {
251
+ let variants = def. variants . move_flat_map ( |v| {
251
252
self . configure ( v) . map ( |v| {
252
253
Spanned {
253
254
node : ast:: Variant_ {
@@ -260,9 +261,7 @@ impl<'a> StripUnconfigured<'a> {
260
261
}
261
262
} )
262
263
} ) ;
263
- ast:: ItemKind :: Enum ( ast:: EnumDef {
264
- variants : variants. collect ( ) ,
265
- } , generics)
264
+ ast:: ItemKind :: Enum ( ast:: EnumDef { variants } , generics)
266
265
}
267
266
item => item,
268
267
}
@@ -271,15 +270,11 @@ impl<'a> StripUnconfigured<'a> {
271
270
pub fn configure_expr_kind ( & mut self , expr_kind : ast:: ExprKind ) -> ast:: ExprKind {
272
271
match expr_kind {
273
272
ast:: ExprKind :: Match ( m, arms) => {
274
- let arms = arms. into_iter ( ) . filter_map ( |a| self . configure ( a) ) . collect ( ) ;
273
+ let arms = arms. move_flat_map ( |a| self . configure ( a) ) ;
275
274
ast:: ExprKind :: Match ( m, arms)
276
275
}
277
276
ast:: ExprKind :: Struct ( path, fields, base) => {
278
- let fields = fields. into_iter ( )
279
- . filter_map ( |field| {
280
- self . configure ( field)
281
- } )
282
- . collect ( ) ;
277
+ let fields = fields. move_flat_map ( |field| self . configure ( field) ) ;
283
278
ast:: ExprKind :: Struct ( path, fields, base)
284
279
}
285
280
_ => expr_kind,
@@ -304,22 +299,10 @@ impl<'a> StripUnconfigured<'a> {
304
299
self . process_cfg_attrs ( expr)
305
300
}
306
301
307
- pub fn configure_stmt ( & mut self , stmt : ast:: Stmt ) -> Option < ast:: Stmt > {
308
- self . configure ( stmt)
309
- }
310
-
311
- pub fn configure_struct_expr_field ( & mut self , field : ast:: Field ) -> Option < ast:: Field > {
312
- self . configure ( field)
313
- }
314
-
315
302
pub fn configure_pat ( & mut self , pattern : P < ast:: Pat > ) -> P < ast:: Pat > {
316
303
pattern. map ( |mut pattern| {
317
304
if let ast:: PatKind :: Struct ( path, fields, etc) = pattern. node {
318
- let fields = fields. into_iter ( )
319
- . filter_map ( |field| {
320
- self . configure ( field)
321
- } )
322
- . collect ( ) ;
305
+ let fields = fields. move_flat_map ( |field| self . configure ( field) ) ;
323
306
pattern. node = ast:: PatKind :: Struct ( path, fields, etc) ;
324
307
}
325
308
pattern
@@ -367,10 +350,7 @@ impl<'a> fold::Folder for StripUnconfigured<'a> {
367
350
}
368
351
369
352
fn fold_stmt ( & mut self , stmt : ast:: Stmt ) -> SmallVec < [ ast:: Stmt ; 1 ] > {
370
- match self . configure_stmt ( stmt) {
371
- Some ( stmt) => fold:: noop_fold_stmt ( stmt, self ) ,
372
- None => return SmallVec :: new ( ) ,
373
- }
353
+ fold:: noop_fold_stmt ( configure ! ( self , stmt) , self )
374
354
}
375
355
376
356
fn fold_item ( & mut self , item : P < ast:: Item > ) -> SmallVec < [ P < ast:: Item > ; 1 ] > {
0 commit comments