diff options
| author | bors <bors@rust-lang.org> | 2020-03-18 03:08:52 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-03-18 03:08:52 +0000 |
| commit | d939f708d960161d23b964309ba68ff207fc0ead (patch) | |
| tree | 3d74426fb6f269a3de59ca76a4b1560423b3e265 /src/test/codegen/src-hash-algorithm | |
| parent | ae5b641e9ef3fc5ed2b9944121f75902f639cb0a (diff) | |
| parent | 8cf33b0d9d0d4948790ce2ea7f7bf786fb7759f1 (diff) | |
| download | rust-d939f708d960161d23b964309ba68ff207fc0ead.tar.gz rust-d939f708d960161d23b964309ba68ff207fc0ead.zip | |
Auto merge of #68915 - timvermeulen:non_fused_iter, r=Amanieu
Fix bugs in Peekable and Flatten when using non-fused iterators I fixed a couple of bugs with regard to the `Peekable` and `Flatten`/`FlatMap` iterators when the underlying iterator isn't fused. For testing, I also added a `NonFused` iterator wrapper that panics when `next` or `next_back` is called on an iterator that has returned `None` before, which will hopefully make it easier to spot these mistakes in the future. ### Peekable `Peekable::next_back` was implemented as ```rust self.iter.next_back().or_else(|| self.peeked.take().and_then(|x| x)) ``` which is incorrect because when the `peeked` field is `Some(None)`, then `None` has already been returned from the inner iterator and what it returns from `next_back` can no longer be relied upon. `test_peekable_non_fused` tests this. ### Flatten When a `FlattenCompat` instance only has a `backiter` remaining (i.e. `self.frontiter` is `None` and `self.iter` is empty), then `next` will call `self.iter.next()` every time, so the `iter` field needs to be fused. I fixed it by giving it the type `Fuse<I>` instead of `I`, I think this is the only way to fix it. `test_flatten_non_fused_outer` tests this. Furthermore, previously `FlattenCompat::next` did not set `self.frontiter` to `None` after it returned `None`, which is incorrect when the inner iterator type isn't fused. I just delegated it to `try_fold` because that already handles it correctly. `test_flatten_non_fused_inner` tests this. r? @scottmcm
Diffstat (limited to 'src/test/codegen/src-hash-algorithm')
0 files changed, 0 insertions, 0 deletions
