diff options
| author | Clar Charr <clar@charr.xyz> | 2018-04-04 19:10:38 -0400 |
|---|---|---|
| committer | Clar Charr <clar@charr.xyz> | 2018-04-04 19:10:38 -0400 |
| commit | 5c58eec0bd8cee8fb2a191396d5ad5b5c9b0116a (patch) | |
| tree | 008deaf9de29022f5d794bbedf739049a5eca248 | |
| parent | 178becdd7c86d87b24951af18e4b7d45f3e1e7bc (diff) | |
| download | rust-5c58eec0bd8cee8fb2a191396d5ad5b5c9b0116a.tar.gz rust-5c58eec0bd8cee8fb2a191396d5ad5b5c9b0116a.zip | |
Replace manual iter exhaust with for_each(drop).
| -rw-r--r-- | src/liballoc/btree/map.rs | 3 | ||||
| -rw-r--r-- | src/liballoc/linked_list.rs | 2 | ||||
| -rw-r--r-- | src/liballoc/vec.rs | 9 | ||||
| -rw-r--r-- | src/liballoc/vec_deque.rs | 2 | ||||
| -rw-r--r-- | src/librustc_data_structures/array_vec.rs | 4 | ||||
| -rw-r--r-- | src/libstd/collections/hash/table.rs | 2 |
6 files changed, 9 insertions, 13 deletions
diff --git a/src/liballoc/btree/map.rs b/src/liballoc/btree/map.rs index ed9c8c18f0d..37274a3c3ec 100644 --- a/src/liballoc/btree/map.rs +++ b/src/liballoc/btree/map.rs @@ -1260,8 +1260,7 @@ impl<K, V> IntoIterator for BTreeMap<K, V> { #[stable(feature = "btree_drop", since = "1.7.0")] impl<K, V> Drop for IntoIter<K, V> { fn drop(&mut self) { - for _ in &mut *self { - } + self.for_each(drop); unsafe { let leaf_node = ptr::read(&self.front).into_node(); if let Some(first_parent) = leaf_node.deallocate_and_ascend() { diff --git a/src/liballoc/linked_list.rs b/src/liballoc/linked_list.rs index 097d2e414f5..b633787fadf 100644 --- a/src/liballoc/linked_list.rs +++ b/src/liballoc/linked_list.rs @@ -1076,7 +1076,7 @@ impl<'a, T, F> Drop for DrainFilter<'a, T, F> where F: FnMut(&mut T) -> bool, { fn drop(&mut self) { - for _ in self { } + self.for_each(drop); } } diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 2f57c53a6d8..635ffe08e9c 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -2354,7 +2354,7 @@ impl<'a, T> DoubleEndedIterator for Drain<'a, T> { impl<'a, T> Drop for Drain<'a, T> { fn drop(&mut self) { // exhaust self first - while let Some(_) = self.next() {} + self.for_each(drop); if self.tail_len > 0 { unsafe { @@ -2474,9 +2474,7 @@ impl<'a, I: Iterator> ExactSizeIterator for Splice<'a, I> {} #[stable(feature = "vec_splice", since = "1.21.0")] impl<'a, I: Iterator> Drop for Splice<'a, I> { fn drop(&mut self) { - // exhaust drain first - while let Some(_) = self.drain.next() {} - + self.drain.by_ref().for_each(drop); unsafe { if self.drain.tail_len == 0 { @@ -2605,8 +2603,7 @@ impl<'a, T, F> Drop for DrainFilter<'a, T, F> where F: FnMut(&mut T) -> bool, { fn drop(&mut self) { - for _ in self.by_ref() { } - + self.for_each(drop); unsafe { self.vec.set_len(self.old_len - self.del); } diff --git a/src/liballoc/vec_deque.rs b/src/liballoc/vec_deque.rs index 68add3cbd51..ee9d8e796ab 100644 --- a/src/liballoc/vec_deque.rs +++ b/src/liballoc/vec_deque.rs @@ -2177,7 +2177,7 @@ unsafe impl<'a, T: Send> Send for Drain<'a, T> {} #[stable(feature = "drain", since = "1.6.0")] impl<'a, T: 'a> Drop for Drain<'a, T> { fn drop(&mut self) { - for _ in self.by_ref() {} + self.for_each(drop); let source_deque = unsafe { self.deque.as_mut() }; diff --git a/src/librustc_data_structures/array_vec.rs b/src/librustc_data_structures/array_vec.rs index 511c407d45a..34e19bba08b 100644 --- a/src/librustc_data_structures/array_vec.rs +++ b/src/librustc_data_structures/array_vec.rs @@ -207,7 +207,7 @@ pub struct Iter<A: Array> { impl<A: Array> Drop for Iter<A> { fn drop(&mut self) { - for _ in self {} + self.for_each(drop); } } @@ -251,7 +251,7 @@ impl<'a, A: Array> Iterator for Drain<'a, A> { impl<'a, A: Array> Drop for Drain<'a, A> { fn drop(&mut self) { // exhaust self first - while let Some(_) = self.next() {} + self.for_each(drop); if self.tail_len > 0 { unsafe { diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs index 73bd5747c10..4ed1e159a0a 100644 --- a/src/libstd/collections/hash/table.rs +++ b/src/libstd/collections/hash/table.rs @@ -1129,7 +1129,7 @@ impl<'a, K, V> ExactSizeIterator for Drain<'a, K, V> { impl<'a, K: 'a, V: 'a> Drop for Drain<'a, K, V> { fn drop(&mut self) { - for _ in self {} + self.for_each(drop); } } |
