-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Vec::reserve()
(etc) panic conditions don't apply to zero-sized or empty types
#119149
Comments
The docs say (emphasis mine):
A |
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. |
Might make sense to make the |
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=cuviper Italicise "bytes" in the docs of some `Vec` methods On a cursory read it's easy to miss that the limit is in terms of bytes not no. of elements. The italics should help with that. Fixes rust-lang#119149
Location
https://doc.rust-lang.org/std/vec/struct.Vec.html#method.reserve (and several other methods)
Summary
Vec::<()>::new().capacity()
isusize::MAX
, which is greater thanisize::MAX
. Callingreserve(1)
on this vector does not panic, and the capacity afterwards is still greater thanisize::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.
The text was updated successfully, but these errors were encountered: