@@ -1030,6 +1030,10 @@ impl<T, A: Allocator> LinkedList<T, A> {
10301030 /// If the closure returns false, the element will remain in the list and will not be yielded
10311031 /// by the iterator.
10321032 ///
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+ ///
10331037 /// Note that `drain_filter` lets you mutate every element in the filter closure, regardless of
10341038 /// whether you choose to keep or remove it.
10351039 ///
@@ -1805,6 +1809,7 @@ impl<'a, T, A: Allocator> CursorMut<'a, T, A> {
18051809
18061810/// An iterator produced by calling `drain_filter` on LinkedList.
18071811#[ unstable( feature = "drain_filter" , reason = "recently added" , issue = "43244" ) ]
1812+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
18081813pub struct DrainFilter <
18091814 ' a ,
18101815 T : ' a ,
@@ -1849,33 +1854,6 @@ where
18491854 }
18501855}
18511856
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-
18791857#[ unstable( feature = "drain_filter" , reason = "recently added" , issue = "43244" ) ]
18801858impl < T : fmt:: Debug , F > fmt:: Debug for DrainFilter < ' _ , T , F >
18811859where
0 commit comments