Skip to content

Commit

Permalink
Implement Drop for IntoIter
Browse files Browse the repository at this point in the history
Both Vec and Drain drop leftover elements when they are dropped.
It would be inconsistent for IntoIter to just leak them.
  • Loading branch information
main-- committed Oct 14, 2022
1 parent 6e10b0f commit 8e45f75
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/collections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2345,6 +2345,13 @@ impl<'bump, T: 'bump> ExactSizeIterator for IntoIter<'bump, T> {}

impl<'bump, T: 'bump> FusedIterator for IntoIter<'bump, T> {}

impl<'bump, T> Drop for IntoIter<'bump, T> {
fn drop(&mut self) {
// drop all remaining elements
self.for_each(drop);
}
}

/// A draining iterator for `Vec<'bump, T>`.
///
/// This `struct` is created by the [`Vec::drain`] method.
Expand Down

0 comments on commit 8e45f75

Please sign in to comment.