-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
I discovered that VecDeque
can produce an infinite loop in an iterator when using iter+collect.
use std::collections::VecDeque;
use std::iter::FromIterator;
fn main() {
let mut v = VecDeque::from_iter(0..6);
v.pop_front();
v.pop_front();
v.push_back(6);
v.push_back(7);
v.push_back(8);
v.make_contiguous();
// `v.iter().collect()` does not terminate at this point.
// Limit `collect` to `v.len() * 3` to avoid the inifinite iteration.
let collected: Vec<_> = v.iter().copied().take(v.len() * 3).collect();
assert_eq!(v.as_slices(), (&collected[..], &[] as &[_]));
// Result on stable 1.48.0 (7eac88abb 2020-11-16)
// thread 'main' panicked at 'assertion failed: `(left == right)`
// left: `([2, 3, 4, 5, 6, 7, 8], [])`,
// right: `([2, 3, 4, 5, 6, 7, 8, 8, 2, 3, 4, 5, 6, 7, 8, 8, 2, 3, 4, 5, 6], [])`', src/main.rs:15:5
}
This happens with stable (1.48.0, 7eac88a). I could not reproduce the issue on 1.50.0-nightly 11c94a1 or 1.49.0-beta.4 877c7cb.
I think this may be related/a duplicate of #79808. Particularly 527934d looks highly related to this issue (@lcnr).
I'm filing this bug as I'm not super familiar with Rust and think it may be worth to confirm that this is caused by the same underlying issue and appropriately fixed already.
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.