@@ -1030,6 +1030,10 @@ impl<T, A: Allocator> LinkedList<T, A> {
1030
1030
/// If the closure returns false, the element will remain in the list and will not be yielded
1031
1031
/// by the iterator.
1032
1032
///
1033
+ /// If the returned `DrainFilter` is not exhausted, e.g. because it is dropped without iterating
1034
+ /// or the iteration short-circuits, then the remaining elements will be retained.
1035
+ /// Use `drain_filter().for_each(drop)` if you do not need the returned iterator.
1036
+ ///
1033
1037
/// Note that `drain_filter` lets you mutate every element in the filter closure, regardless of
1034
1038
/// whether you choose to keep or remove it.
1035
1039
///
@@ -1805,6 +1809,7 @@ impl<'a, T, A: Allocator> CursorMut<'a, T, A> {
1805
1809
1806
1810
/// An iterator produced by calling `drain_filter` on LinkedList.
1807
1811
#[ unstable( feature = "drain_filter" , reason = "recently added" , issue = "43244" ) ]
1812
+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
1808
1813
pub struct DrainFilter <
1809
1814
' a ,
1810
1815
T : ' a ,
@@ -1849,33 +1854,6 @@ where
1849
1854
}
1850
1855
}
1851
1856
1852
- #[ unstable( feature = "drain_filter" , reason = "recently added" , issue = "43244" ) ]
1853
- impl < T , F , A : Allocator > Drop for DrainFilter < ' _ , T , F , A >
1854
- where
1855
- F : FnMut ( & mut T ) -> bool ,
1856
- {
1857
- fn drop ( & mut self ) {
1858
- struct DropGuard < ' r , ' a , T , F , A : Allocator > ( & ' r mut DrainFilter < ' a , T , F , A > )
1859
- where
1860
- F : FnMut ( & mut T ) -> bool ;
1861
-
1862
- impl < ' r , ' a , T , F , A : Allocator > Drop for DropGuard < ' r , ' a , T , F , A >
1863
- where
1864
- F : FnMut ( & mut T ) -> bool ,
1865
- {
1866
- fn drop ( & mut self ) {
1867
- self . 0 . for_each ( drop) ;
1868
- }
1869
- }
1870
-
1871
- while let Some ( item) = self . next ( ) {
1872
- let guard = DropGuard ( self ) ;
1873
- drop ( item) ;
1874
- mem:: forget ( guard) ;
1875
- }
1876
- }
1877
- }
1878
-
1879
1857
#[ unstable( feature = "drain_filter" , reason = "recently added" , issue = "43244" ) ]
1880
1858
impl < T : fmt:: Debug , F > fmt:: Debug for DrainFilter < ' _ , T , F >
1881
1859
where
0 commit comments