Closed
Description
Recently the Chain
adapter has been changed to fuse the iterators it holds by destroying them, this introduces a subtle behavior change that is difficult to debug and as far as I see not documented.
For example the following:
use std::sync::mpsc;
fn main() {
let (tx,rx) = mpsc::channel();
let mut it = vec![1, 2, 3].into_iter().chain(rx.try_iter());
tx.send(4).unwrap();
tx.send(5).unwrap();
assert_eq!(it.next(), Some(1));
assert_eq!(it.next(), Some(2));
assert_eq!(it.next(), Some(3));
assert_eq!(it.next(), Some(4));
assert_eq!(it.next(), Some(5));
assert_eq!(it.next(), None);
tx.send(6).unwrap();
assert_eq!(it.next(), Some(6));
tx.send(7).unwrap();
assert_eq!(it.next(), Some(7));
}
runs correctly on current stable (1.42) but panics in nightly cause the iterator is now fused so it can't be called anymore after it returns None for the first time.
Perhaps a possible solution would be to fuse the first iterator in the chain but not the second?