You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Vec::reserve() (etc) panic conditions don't apply to zero-sized or empty types #119149
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.
Oh you're right, I read that many times and never processed the last word. That's the only place I see which talks about "capacity" as a number of bytes instead of a number of elements, which is easy to miss IMHO.
Activity
Jules-Bertholet commentedon Dec 20, 2023
The docs say (emphasis mine):
A
Vec::<()>will never have more than 0 bytes of capacity, and thereforereservewill never panic. The documentation is correct.bsilver8192 commentedon Dec 20, 2023
Oh you're right, I read that many times and never processed the last word. That's the only place I see which talks about "capacity" as a number of bytes instead of a number of elements, which is easy to miss IMHO.
Noratrieb commentedon Dec 20, 2023
Might make sense to make the
bytesbold.gurry commentedon Dec 28, 2023
I have raised PR #119374 doing just that (except italicising it instead making it bold)
Rollup merge of rust-lang#119374 - gurry:119149-improve-vec-docs, r=c…
Unrolled build for rust-lang#119374