Skip to content

Commit

Permalink
Clarify behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
novacrazy committed Sep 12, 2023
1 parent 1f4e04c commit 5f9e39b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,13 @@ impl<T, N: ArrayLength> Iterator for GenericArrayIter<T, N> {
})
};

// ensure this happens here after iteration
// The current iterator is now empty after the remaining items are
// consumed by the above folding. Dropping it is unnecessary,
// so avoid the drop codegen and forget it instead. The iterator
// will still drop on panics from `f`, of course.
//
// Furthermore, putting `forget` here at the end ensures the above
// destructuring never moves by value, so its behavior on drop remains intact.
mem::forget(self);

ret
Expand Down Expand Up @@ -206,7 +212,7 @@ impl<T, N: ArrayLength> DoubleEndedIterator for GenericArrayIter<T, N> {
})
};

// ensure this happens here after iteration
// Same as `fold`
mem::forget(self);

ret
Expand Down

0 comments on commit 5f9e39b

Please sign in to comment.