diff options
| author | Jonas Schievink <jonasschievink@gmail.com> | 2019-12-16 21:42:46 +0100 |
|---|---|---|
| committer | Jonas Schievink <jonasschievink@gmail.com> | 2020-01-19 20:28:47 +0100 |
| commit | 52d6c90488abdd12a24c66f5e3490ae3136bb295 (patch) | |
| tree | 92594831af6ae491e4535a7d9143a9cfbb19f7b4 /src/liballoc | |
| parent | 75f721df97fd7895b31a1d8c9ed05a368fc95d6d (diff) | |
| download | rust-52d6c90488abdd12a24c66f5e3490ae3136bb295.tar.gz rust-52d6c90488abdd12a24c66f5e3490ae3136bb295.zip | |
Update comments in `Drain`s `Drop` impl
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/vec.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 6589cc5b1f6..4fa60846e22 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -2702,13 +2702,14 @@ impl<T> DoubleEndedIterator for Drain<'_, T> { #[stable(feature = "drain", since = "1.6.0")] impl<T> Drop for Drain<'_, T> { fn drop(&mut self) { - /// Continues dropping the remaining elements when a destructor unwinds. + /// Continues dropping the remaining elements in the `Drain`, then moves back the + /// un-`Drain`ed elements to restore the original `Vec`. struct DropGuard<'r, 'a, T>(&'r mut Drain<'a, T>); impl<'r, 'a, T> Drop for DropGuard<'r, 'a, T> { fn drop(&mut self) { - // Continue the same loop we do below. This only runs when a destructor has - // panicked. If another one panics this will abort. + // Continue the same loop we have below. If the loop already finished, this does + // nothing. self.0.for_each(drop); if self.0.tail_len > 0 { @@ -2735,6 +2736,7 @@ impl<T> Drop for Drain<'_, T> { mem::forget(guard); } + // Drop a `DropGuard` to move back the non-drained tail of `self`. DropGuard(self); } } |
