Skip to content

Vec::reserve() (etc) panic conditions don't apply to zero-sized or empty types #119149

Closed
@bsilver8192

Description

@bsilver8192

Location

https://doc.rust-lang.org/std/vec/struct.Vec.html#method.reserve (and several other methods)

Summary

Vec::<()>::new().capacity() is usize::MAX, which is greater than isize::MAX. Calling reserve(1) on this vector does not panic, and the capacity afterwards is still greater than isize::MAX. The docs say this should unconditionally panic.

I would find it reasonable to rely on this documentation as part of ensuring soundness of some unsafe code interacting with Vec, without duplicating the assertion in my code.

This same comment is repeated on several other Vec methods, and the same thing applies.

For reference, #117437 and #99790 are another issue and a PR touching on this same sentence of the documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions