]> git.lizzy.rs Git - rust.git/commit - src/tools/rustfmt
Auto merge of #48945 - clarcharr:iter_exhaust, r=Kimundi
authorbors <bors@rust-lang.org>
Mon, 16 Apr 2018 13:21:56 +0000 (13:21 +0000)
committerbors <bors@rust-lang.org>
Mon, 16 Apr 2018 13:21:56 +0000 (13:21 +0000)
commit1ef1563518d48ad9231b3ec3ac463d34d819ed28
tree1fb05811590e2701a4d1875d9326261e655cfeec
parentd6a2dd9912e762fb0029c4463002d674686c1159
parent5c58eec0bd8cee8fb2a191396d5ad5b5c9b0116a
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.
src/liballoc/btree/map.rs
src/liballoc/linked_list.rs
src/liballoc/vec.rs
src/liballoc/vec_deque.rs
src/librustc_data_structures/array_vec.rs
src/libstd/collections/hash/table.rs