Skip to content

VecDeque from Vec fails with ZST #78532

Closed
@alecmocatta

Description

@alecmocatta

This code panics under Miri, and also when I compile to WASM, though not when running normally.

use std::collections::VecDeque;

fn main() {
    let _: VecDeque<()> = vec![()].into();
}

Playground

thread 'main' panicked at 'attempt to add with overflow', /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/collections/vec_deque.rs:3236:36

The overflow is here:

let cap = cmp::max(buf.capacity() + 1, MINIMUM_CAPACITY + 1).next_power_of_two();

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-collectionsArea: `std::collections`A-zstArea: Zero-sized types (ZSTs).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