Skip to content

VecDeque from Vec with ZST elements breaks internal invariants #80167

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

Closed
tmiasko opened this issue Dec 18, 2020 · 5 comments · Fixed by #83244
Closed

VecDeque from Vec with ZST elements breaks internal invariants #80167

tmiasko opened this issue Dec 18, 2020 · 5 comments · Fixed by #83244
Assignees
Labels
A-collections Area: `std::collections` C-bug Category: This is a bug. P-high High priority T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@tmiasko
Copy link
Contributor

tmiasko commented Dec 18, 2020

fn main() {
    let n = 1 << (core::mem::size_of::<usize>() * 8 - 1);

    let mut v = Vec::<()>::new();
    assert!(v.capacity() >= n);
    unsafe { v.set_len(n) };

    let d = std::collections::VecDeque::from(v);
    assert_eq!(d.len(), n, "unexpected len");
}

I expected VecDeque constructed from Vec to either work correctly or construction to panic if it is not possible. Instead:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `0`,
 right: `2147483648`: unexpected len', a.rs:9:5

Introduced by #80003.

@tmiasko tmiasko added the C-bug Category: This is a bug. label Dec 18, 2020
@jonas-schievink jonas-schievink added A-collections Area: `std::collections` T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 18, 2020
@tmiasko tmiasko changed the title VecDeque from Vec construction breaks internal invariants VecDeque from Vec with ZST elements, breaks internal invariants Dec 18, 2020
@camelid
Copy link
Member

camelid commented Dec 18, 2020

cc #78532

@camelid camelid changed the title VecDeque from Vec with ZST elements, breaks internal invariants VecDeque from Vec with ZST elements breaks internal invariants Dec 18, 2020
@camelid camelid added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Dec 20, 2020
@camelid
Copy link
Member

camelid commented Dec 20, 2020

Not sure how severe this is, but figured that it's worth prioritizing.

@Stupremee
Copy link
Member

@rustbot claim

@camelid camelid added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 20, 2020
@camelid
Copy link
Member

camelid commented Dec 20, 2020

Assigning P-high and removing I-prioritize as discussed in the prioritization working group.

@cuviper
Copy link
Member

cuviper commented Mar 17, 2021

#83244 should fix this -- written before I saw this issue and @Stupremee's claim, so I'm sorry if you were still working on it.

@bors bors closed this as completed in 1a0e32f Mar 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-collections Area: `std::collections` C-bug Category: This is a bug. P-high High priority 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.

5 participants