-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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::from_raw_parts docs incorrectly suggest the pointer is legal to be null #19269
Comments
The documentation is misleading. The pointer is not allowed to be null. |
How do you make an empty slice if the pointer is not allowed to be null? |
@mitsuhiko: The underlying representation is an implementation detail and shouldn't be documented beyond the ability to convert the raw parts obtained from a vector back into a vector. |
The language and library documentation has a love affair with making far too many promises about the implementation. In the vector module, there are numerous errors when it comes to information about the vector's capacity too. It tends to guarantee that the capacity is exactly what was asked for rather than at least that much. It is allowed to set the capacity to a value provided by the allocator. |
Does that mean you are required to special case the empty case and then use a different way to make an empty vector? |
No, it means you can't use this method outside of the standard library beyond converting from an existing vector. |
If what you're asking is how it does this internally, the answer is that empty vectors along with zero-size allocations in general are allowed to be entirely arbitrary pointers. They will never be dereferenced and the compiler / library code will never attempt to deallocate them. |
The documentation is not supposed to cover these implementation details. It would make sense to cover it in comments (which it is) or internal design documentation. |
In that case I suppose the docs should say: can only be constructed from components of an already existing vector. |
minor: sync from downstream
http://doc.rust-lang.org/nightly/collections/vec/struct.Vec.html#method.from_raw_parts
The text was updated successfully, but these errors were encountered: