@@ -305,25 +305,21 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
305
305
/// Visits and format the given items. Items are reordered If they are
306
306
/// consecutive and reorderable.
307
307
pub ( crate ) fn visit_items_with_reordering ( & mut self , mut items : & [ & ast:: Item ] ) {
308
- while !items . is_empty ( ) {
308
+ while let [ head , tail @ .. ] = items {
309
309
// If the next item is a `use`, `extern crate` or `mod`, then extract it and any
310
310
// subsequent items that have the same item kind to be reordered within
311
311
// `walk_reorderable_items`. Otherwise, just format the next item for output.
312
- let item_kind = ReorderableItemKind :: from ( items [ 0 ] ) ;
312
+ let item_kind = ReorderableItemKind :: from ( head ) ;
313
313
if item_kind. is_reorderable ( self . config ) || item_kind. is_regroupable ( self . config ) {
314
314
let visited_items_num = self . walk_reorderable_or_regroupable_items (
315
315
items,
316
316
item_kind,
317
317
item_kind. in_group ( self . config ) ,
318
318
) ;
319
- let ( _, rest) = items. split_at ( visited_items_num) ;
320
- items = rest;
319
+ ( _, items) = items. split_at ( visited_items_num) ;
321
320
} else {
322
- // Reaching here means items were not reordered. There must be at least
323
- // one item left in `items`, so calling `unwrap()` here is safe.
324
- let ( item, rest) = items. split_first ( ) . unwrap ( ) ;
325
- self . visit_item ( item) ;
326
- items = rest;
321
+ self . visit_item ( head) ;
322
+ items = tail;
327
323
}
328
324
}
329
325
}
0 commit comments