-
Couldn't load subscription status.
- Fork 13.9k
Closed
Labels
A-iteratorsArea: IteratorsArea: IteratorsT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.Performance or correctness regression from stable to beta.
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?
Metadata
Metadata
Assignees
Labels
A-iteratorsArea: IteratorsArea: IteratorsT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.Performance or correctness regression from stable to beta.