-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Vec::with_capacity does not work correctly for zero-sized types #43490
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
Comments
This is a consequence of
IMO the behavior is fine, but the docs could clarify this situation. |
I'm happy to modify the docs but would like to know what the libs team thinks. |
IIRC |
There is reserve_exact, though. Does that handle ZST capacity differently? |
Even reserve_exact doesn't guarantee exactly:
This is essentially that situation -- the "nop allocator" said we can hold lots -- so it feels to me like |
The behavior is fine. The docs need to indicate that the capacity will be at least what you requested, with the caveat from reserve_exact. |
I'm not sure when this was fixed, but it was:
|
Calling Vec::with_capacity(N) does not give you a vector with capacity N.
This fails with:
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]
, andVec::with_capacity(n)
, will all produce a Vec with exactly the requested capacity."The text was updated successfully, but these errors were encountered: