Skip to content

Commit 5c58eec

Browse files
author
Clar Charr
committed
Replace manual iter exhaust with for_each(drop).
1 parent 178becd commit 5c58eec

File tree

6 files changed

+9
-13
lines changed

6 files changed

+9
-13
lines changed

src/liballoc/btree/map.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1260,8 +1260,7 @@ impl<K, V> IntoIterator for BTreeMap<K, V> {
12601260
#[stable(feature = "btree_drop", since = "1.7.0")]
12611261
impl<K, V> Drop for IntoIter<K, V> {
12621262
fn drop(&mut self) {
1263-
for _ in &mut *self {
1264-
}
1263+
self.for_each(drop);
12651264
unsafe {
12661265
let leaf_node = ptr::read(&self.front).into_node();
12671266
if let Some(first_parent) = leaf_node.deallocate_and_ascend() {

src/liballoc/linked_list.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ impl<'a, T, F> Drop for DrainFilter<'a, T, F>
10761076
where F: FnMut(&mut T) -> bool,
10771077
{
10781078
fn drop(&mut self) {
1079-
for _ in self { }
1079+
self.for_each(drop);
10801080
}
10811081
}
10821082

src/liballoc/vec.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -2354,7 +2354,7 @@ impl<'a, T> DoubleEndedIterator for Drain<'a, T> {
23542354
impl<'a, T> Drop for Drain<'a, T> {
23552355
fn drop(&mut self) {
23562356
// exhaust self first
2357-
while let Some(_) = self.next() {}
2357+
self.for_each(drop);
23582358

23592359
if self.tail_len > 0 {
23602360
unsafe {
@@ -2474,9 +2474,7 @@ impl<'a, I: Iterator> ExactSizeIterator for Splice<'a, I> {}
24742474
#[stable(feature = "vec_splice", since = "1.21.0")]
24752475
impl<'a, I: Iterator> Drop for Splice<'a, I> {
24762476
fn drop(&mut self) {
2477-
// exhaust drain first
2478-
while let Some(_) = self.drain.next() {}
2479-
2477+
self.drain.by_ref().for_each(drop);
24802478

24812479
unsafe {
24822480
if self.drain.tail_len == 0 {
@@ -2605,8 +2603,7 @@ impl<'a, T, F> Drop for DrainFilter<'a, T, F>
26052603
where F: FnMut(&mut T) -> bool,
26062604
{
26072605
fn drop(&mut self) {
2608-
for _ in self.by_ref() { }
2609-
2606+
self.for_each(drop);
26102607
unsafe {
26112608
self.vec.set_len(self.old_len - self.del);
26122609
}

src/liballoc/vec_deque.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2177,7 +2177,7 @@ unsafe impl<'a, T: Send> Send for Drain<'a, T> {}
21772177
#[stable(feature = "drain", since = "1.6.0")]
21782178
impl<'a, T: 'a> Drop for Drain<'a, T> {
21792179
fn drop(&mut self) {
2180-
for _ in self.by_ref() {}
2180+
self.for_each(drop);
21812181

21822182
let source_deque = unsafe { self.deque.as_mut() };
21832183

src/librustc_data_structures/array_vec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ pub struct Iter<A: Array> {
207207

208208
impl<A: Array> Drop for Iter<A> {
209209
fn drop(&mut self) {
210-
for _ in self {}
210+
self.for_each(drop);
211211
}
212212
}
213213

@@ -251,7 +251,7 @@ impl<'a, A: Array> Iterator for Drain<'a, A> {
251251
impl<'a, A: Array> Drop for Drain<'a, A> {
252252
fn drop(&mut self) {
253253
// exhaust self first
254-
while let Some(_) = self.next() {}
254+
self.for_each(drop);
255255

256256
if self.tail_len > 0 {
257257
unsafe {

src/libstd/collections/hash/table.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ impl<'a, K, V> ExactSizeIterator for Drain<'a, K, V> {
11291129

11301130
impl<'a, K: 'a, V: 'a> Drop for Drain<'a, K, V> {
11311131
fn drop(&mut self) {
1132-
for _ in self {}
1132+
self.for_each(drop);
11331133
}
11341134
}
11351135

0 commit comments

Comments
 (0)