rust/src/libcore
bors d939f708d9 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
2020-03-18 03:08:52 +00:00
..
array
benches
char
convert Correct version that relaxed orphan rules 2020-03-07 08:21:27 +00:00
fmt Rollup merge of #69011 - foeb:document-unsafe-core-fmt, r=Mark-Simulacrum 2020-03-12 16:32:11 +01:00
future
hash Rollup merge of #69471 - nnethercote:rm-sip-Hasher-short_write, r=dtolnay 2020-03-15 02:44:15 +01:00
iter Auto merge of #68915 - timvermeulen:non_fused_iter, r=Amanieu 2020-03-18 03:08:52 +00:00
macros Rollup merge of #69870 - petrochenkov:cfgacc, r=matthewjasper 2020-03-17 03:05:12 +01:00
mem Rollup merge of #69922 - RalfJung:less-intrinsic, r=oli-obk 2020-03-17 12:16:16 +01:00
num update stable-since version for const_int_conversion 2020-03-13 14:25:35 +01:00
ops Bump the bootstrap compiler 2020-03-15 19:43:25 +01:00
prelude builtin_macros: Add attribute macro #[cfg_accessible(path)] 2020-03-10 01:02:13 +03:00
ptr fix various typos 2020-03-06 15:19:31 +01:00
slice Use subslice patterns in slice methods 2020-03-04 10:34:24 -08:00
str Use ?-operator in more places (clippy::question_mark, had some false negatives fixed recently) 2020-03-07 21:46:47 +01:00
sync
task
tests Auto merge of #68915 - timvermeulen:non_fused_iter, r=Amanieu 2020-03-18 03:08:52 +00:00
unicode
alloc.rs Allow ZSTs in AllocRef 2020-03-08 11:01:12 +01:00
any.rs
ascii.rs
bool.rs
borrow.rs
Cargo.toml
cell.rs Rollup merge of #70029 - jonas-schievink:bootstrap, r=Centril 2020-03-17 03:05:17 +01:00
clone.rs
cmp.rs
default.rs
ffi.rs
hint.rs
internal_macros.rs
intrinsics.rs Rollup merge of #69922 - RalfJung:less-intrinsic, r=oli-obk 2020-03-17 12:16:16 +01:00
lib.rs Bump the bootstrap compiler 2020-03-15 19:43:25 +01:00
marker.rs Add attributes to allow specializing on traits 2020-03-15 12:44:25 +00:00
option.rs
panic.rs
panicking.rs also make panic_fmt track_caller 2020-03-10 10:31:03 +01:00
pin.rs fix various typos 2020-03-06 15:19:31 +01:00
primitive.rs
raw.rs
result.rs
time.rs
tuple.rs
unit.rs