From e601e2ac48a217fafb5962a43680d60c574d35ef Mon Sep 17 00:00:00 2001 From: Alexis Bourget Date: Wed, 22 Jul 2020 21:50:16 +0200 Subject: [PATCH 1/3] Improve the documentation for Vec::drain --- src/liballoc/vec.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 5db96a504a6..269eeed3ccf 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -1274,11 +1274,12 @@ impl Vec { /// Creates a draining iterator that removes the specified range in the vector /// and yields the removed items. /// - /// Note 1: The element range is removed even if the iterator is only - /// partially consumed or not consumed at all. + /// The element range is removed even if the iterator is only partially + /// consumed or not consumed at all. /// - /// Note 2: It is unspecified how many elements are removed from the vector - /// if the `Drain` value is leaked. + /// Note: Be aware that if the iterator is leaked (eg: [`mem::forget`]), it + /// cancels this property so it is unspecified how many elements are removed + /// from the vector in this case. /// /// # Panics /// @@ -1297,6 +1298,8 @@ impl Vec { /// v.drain(..); /// assert_eq!(v, &[]); /// ``` + /// + /// [`mem::forget`]: mem::forget #[stable(feature = "drain", since = "1.6.0")] pub fn drain(&mut self, range: R) -> Drain<'_, T> where From 771ec216bc87932e341cf1f4d887988228d429b5 Mon Sep 17 00:00:00 2001 From: Alexis Bourget Date: Thu, 23 Jul 2020 22:35:22 +0200 Subject: [PATCH 2/3] Remove unecessary link --- src/liballoc/vec.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 269eeed3ccf..30ff28f3fdb 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -1298,8 +1298,6 @@ impl Vec { /// v.drain(..); /// assert_eq!(v, &[]); /// ``` - /// - /// [`mem::forget`]: mem::forget #[stable(feature = "drain", since = "1.6.0")] pub fn drain(&mut self, range: R) -> Drain<'_, T> where From 654c180d05fedc8a9a3c793cfc747ad542d3a4f2 Mon Sep 17 00:00:00 2001 From: Alexis Bourget Date: Fri, 24 Jul 2020 19:55:08 +0200 Subject: [PATCH 3/3] Apply suggestion from review --- src/liballoc/vec.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 30ff28f3fdb..2f56898f4e9 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -1274,12 +1274,10 @@ impl Vec { /// Creates a draining iterator that removes the specified range in the vector /// and yields the removed items. /// - /// The element range is removed even if the iterator is only partially - /// consumed or not consumed at all. - /// - /// Note: Be aware that if the iterator is leaked (eg: [`mem::forget`]), it - /// cancels this property so it is unspecified how many elements are removed - /// from the vector in this case. + /// When the iterator **is** dropped, all elements in the range are removed + /// from the vector, even if the iterator was not fully consumed. If the + /// iterator **is not** dropped (with [`mem::forget`] for example), it is + /// unspecified how many elements are removed. /// /// # Panics ///