Skip to content

VecDeque from Vec with ZST elements breaks internal invariants  #80167

Closed
@tmiasko

Description

@tmiasko
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.

Metadata

Metadata

Assignees

Labels

A-collectionsArea: `std::collections`C-bugCategory: This is a bug.P-highHigh priorityT-libsRelevant to the library team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions