Skip to content

Commit 0ac98b1

Browse files
committed
Simplify loop in visit_items_with_reordering
1 parent ca02573 commit 0ac98b1

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/reorder.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -305,25 +305,21 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
305305
/// Visits and format the given items. Items are reordered If they are
306306
/// consecutive and reorderable.
307307
pub(crate) fn visit_items_with_reordering(&mut self, mut items: &[&ast::Item]) {
308-
while !items.is_empty() {
308+
while let [head, tail @ ..] = items {
309309
// If the next item is a `use`, `extern crate` or `mod`, then extract it and any
310310
// subsequent items that have the same item kind to be reordered within
311311
// `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);
313313
if item_kind.is_reorderable(self.config) || item_kind.is_regroupable(self.config) {
314314
let visited_items_num = self.walk_reorderable_or_regroupable_items(
315315
items,
316316
item_kind,
317317
item_kind.in_group(self.config),
318318
);
319-
let (_, rest) = items.split_at(visited_items_num);
320-
items = rest;
319+
(_, items) = items.split_at(visited_items_num);
321320
} 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;
327323
}
328324
}
329325
}

0 commit comments

Comments
 (0)