about summary refs log tree commit diff
path: root/src/librustc_data_structures/array_vec.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-04-16 13:21:56 +0000
committerbors <bors@rust-lang.org>2018-04-16 13:21:56 +0000
commit1ef1563518d48ad9231b3ec3ac463d34d819ed28 (patch)
tree1fb05811590e2701a4d1875d9326261e655cfeec /src/librustc_data_structures/array_vec.rs
parentd6a2dd9912e762fb0029c4463002d674686c1159 (diff)
parent5c58eec0bd8cee8fb2a191396d5ad5b5c9b0116a (diff)
downloadrust-1ef1563518d48ad9231b3ec3ac463d34d819ed28.tar.gz
rust-1ef1563518d48ad9231b3ec3ac463d34d819ed28.zip
Auto merge of #48945 - clarcharr:iter_exhaust, r=Kimundi
Replace manual iterator exhaust with for_each(drop)

This originally added a dedicated method, `Iterator::exhaust`, and has since been replaced with `for_each(drop)`, which is more idiomatic.

<del>This is just shorthand for `for _ in &mut self {}` or `while let Some(_) = self.next() {}`. This states the intent a lot more clearly than the identical code: run the iterator to completion.

<del>At least personally, my eyes tend to gloss over `for _ in &mut self {}` without fully paying attention to what it does; having a `Drop` implementation akin to:

<del>`for _ in &mut self {}; unsafe { free(self.ptr); }`</del>

<del>Is not as clear as:

<del>`self.exhaust(); unsafe { free(self.ptr); }`

<del>Additionally, I've seen debate over whether `while let Some(_) = self.next() {}` or `for _ in &mut self {}` is more clear, whereas `self.exhaust()` is clearer than both.
Diffstat (limited to 'src/librustc_data_structures/array_vec.rs')
-rw-r--r--src/librustc_data_structures/array_vec.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/librustc_data_structures/array_vec.rs b/src/librustc_data_structures/array_vec.rs
index db1cfb5c767..7b33ee40d8c 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 {