Skip to content

Commit 8fa032a

Browse files
committed
Perhaps improve the documentation of drain members further
1 parent f1b48b9 commit 8fa032a

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

library/alloc/src/collections/binary_heap.rs

+14
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,12 @@ impl<T: Ord> BinaryHeap<T> {
754754
/// * `.drain_sorted()` is *O*(*n* \* log(*n*)); much slower than `.drain()`.
755755
/// You should use the latter for most cases.
756756
///
757+
/// # Leaking
758+
///
759+
/// In case the iterator disappears without getting dropped (using
760+
/// [`mem::forget`], for example), it is unspecified whether the
761+
/// remaining elements are still in the heap or leaked.
762+
///
757763
/// # Examples
758764
///
759765
/// Basic usage:
@@ -1162,6 +1168,14 @@ impl<T> BinaryHeap<T> {
11621168
///
11631169
/// The elements are removed in arbitrary order.
11641170
///
1171+
/// # Leaking
1172+
///
1173+
/// When the iterator **is** dropped, it drops any elements that it has not
1174+
/// yet yielded (none if the iterator was fully consumed).
1175+
/// If the iterator **is not** dropped (with [`mem::forget`], for example),
1176+
/// it is unspecified whether the elements not yet yielded are still in the
1177+
/// heap or leaked.
1178+
///
11651179
/// # Examples
11661180
///
11671181
/// Basic usage:

library/alloc/src/collections/linked_list.rs

+8
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,14 @@ impl<T> LinkedList<T> {
970970
/// Note that `drain_filter` lets you mutate every element in the filter closure, regardless of
971971
/// whether you choose to keep or remove it.
972972
///
973+
/// # Leaking
974+
///
975+
/// When the iterator **is** dropped, it drops any elements that it has not
976+
/// yet yielded and for which the closure returns true.
977+
/// If the iterator **is not** dropped (with [`mem::forget`], for example),
978+
/// it is unspecified whether the elements not yet yielded are still in the
979+
/// list or leaked.
980+
///
973981
/// # Examples
974982
///
975983
/// Splitting a list into evens and odds, reusing the original list:

library/alloc/src/collections/vec_deque/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
12181218
/// Removes the specified range from the `VecDeque`, returning all removed
12191219
/// elements as an iterator.
12201220
///
1221+
/// # Leaking
1222+
///
12211223
/// When the iterator **is** dropped, it drops any elements that it has not
12221224
/// yet yielded (none if the iterator was fully consumed).
12231225
/// If the iterator **is not** dropped (with [`mem::forget`], for example),

library/alloc/src/string.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,11 @@ impl String {
16311631
/// Removes the specified range from the string, returning all removed
16321632
/// characters as an iterator.
16331633
///
1634+
/// # Leaking
1635+
///
1636+
/// In case the iterator disappears without getting dropped (using
1637+
/// [`core::mem::forget`], for example), the range remains in the string.
1638+
///
16341639
/// # Panics
16351640
///
16361641
/// Panics if the starting point or end point do not lie on a [`char`]

library/alloc/src/vec/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,8 @@ impl<T, A: Allocator> Vec<T, A> {
18021802
/// Removes the specified range from the vector, returning all removed
18031803
/// elements as an iterator.
18041804
///
1805+
/// # Leaking
1806+
///
18051807
/// When the iterator **is** dropped, it drops any elements that it has not
18061808
/// yet yielded (none if the iterator was fully consumed).
18071809
/// If the iterator **is not** dropped (with [`mem::forget`], for example),
@@ -2732,6 +2734,14 @@ impl<T, A: Allocator> Vec<T, A> {
27322734
/// Note that `drain_filter` also lets you mutate every element in the filter closure,
27332735
/// regardless of whether you choose to keep or remove it.
27342736
///
2737+
/// # Leaking
2738+
///
2739+
/// When the iterator **is** dropped, it drops any elements that it has not
2740+
/// yet yielded and for which the closure returns true.
2741+
/// If the iterator **is not** dropped (with [`mem::forget`], for example),
2742+
/// it is unspecified which elements remain in the vector; even elements
2743+
/// outside the range may have been removed and leaked.
2744+
///
27352745
/// # Examples
27362746
///
27372747
/// Splitting an array into evens and odds, reusing the original allocation:

0 commit comments

Comments
 (0)