Closed
Description
Calling Vec::with_capacity(N) does not give you a vector with capacity N.
fn main()
{
let v: Vec<()> = Vec::with_capacity(5);
assert_eq!(v.capacity(), 5);
}
This fails with:
thread 'main' panicked at 'assertion failed: `(left == right)` (left: `18446744073709551615`, right: `5`)', src/main.rs:4
when running in the playground on stable.
I would expect the capacity to be 5. Logically, I realize the capacity for a zero-sized type is not actually limited, but the docs do say "vec![x; n]
, vec![a, b, c, d]
, and Vec::with_capacity(n)
, will all produce a Vec with exactly the requested capacity."