Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VecDeque iter+collect causes an infinite loop (1.48.0) #80293

Closed
matled opened this issue Dec 22, 2020 · 2 comments · Fixed by #80898
Closed

VecDeque iter+collect causes an infinite loop (1.48.0) #80293

matled opened this issue Dec 22, 2020 · 2 comments · Fixed by #80898
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@matled
Copy link

matled commented Dec 22, 2020

I discovered that VecDeque can produce an infinite loop in an iterator when using iter+collect.

code demonstrating the issue:

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.

@matled matled changed the title VecDeque iter+collect causes in infinite loop (1.48.0) VecDeque iter+collect causes an infinite loop (1.48.0) Dec 22, 2020
@lcnr lcnr added C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 22, 2020
@lcnr
Copy link
Contributor

lcnr commented Dec 22, 2020

Yeah, this looks like the same bug to me 👍 Thanks

marking as E-needs-test.

@SmedbergM
Copy link

Very nice MWE, significantly simpler than the one in #79808.

JohnTitor added a commit to JohnTitor/rust that referenced this issue Jan 11, 2021
@bors bors closed this as completed in a9e3125 Jan 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants