Skip to content

Commit 52d6c90

Browse files
Update comments in Drains Drop impl
1 parent 75f721d commit 52d6c90

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/liballoc/vec.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,13 +2702,14 @@ impl<T> DoubleEndedIterator for Drain<'_, T> {
27022702
#[stable(feature = "drain", since = "1.6.0")]
27032703
impl<T> Drop for Drain<'_, T> {
27042704
fn drop(&mut self) {
2705-
/// Continues dropping the remaining elements when a destructor unwinds.
2705+
/// Continues dropping the remaining elements in the `Drain`, then moves back the
2706+
/// un-`Drain`ed elements to restore the original `Vec`.
27062707
struct DropGuard<'r, 'a, T>(&'r mut Drain<'a, T>);
27072708

27082709
impl<'r, 'a, T> Drop for DropGuard<'r, 'a, T> {
27092710
fn drop(&mut self) {
2710-
// Continue the same loop we do below. This only runs when a destructor has
2711-
// panicked. If another one panics this will abort.
2711+
// Continue the same loop we have below. If the loop already finished, this does
2712+
// nothing.
27122713
self.0.for_each(drop);
27132714

27142715
if self.0.tail_len > 0 {
@@ -2735,6 +2736,7 @@ impl<T> Drop for Drain<'_, T> {
27352736
mem::forget(guard);
27362737
}
27372738

2739+
// Drop a `DropGuard` to move back the non-drained tail of `self`.
27382740
DropGuard(self);
27392741
}
27402742
}

0 commit comments

Comments
 (0)