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
Valid raw pointers as defined above are not necessarily properly aligned (where "proper" alignment is defined by the pointee type, i.e., *const T must be aligned to mem::align_of::<T>()). However, most functions require their arguments to be properly aligned, and will explicitly state this requirement in their documentation. Notable exceptions to this are read_unaligned and write_unaligned.
This is clearly banking on the fact that every function is documented, but raw pointer dereference is a built-in operation and therefore has no documentation aside from the (previously mentioned) pointer primitive page.
Alignment is definitely required for raw pointer reads and writes.
I think the reason why it is not said anywhere is because * on a reference and a raw pointer are the same operation. That operation requires alignment, as is mentioned (I hope) when talking about references. Since it is the same operation, "of course" it also requires alignment when working on a raw pointer.
But you are right, this should probably be documented better. While at it, the drop behavior of writing to a raw pointer should also be called out.
csmoe
added
the
A-docs
Area: Documentation for any part of the project, including the compiler, standard library, and tools
label
Jul 9, 2019
I am referring to the following operation, built into the language:
I checked all over:
The pointer primitive docs don't mention alignment.
The
std::ptr
module states:This is clearly banking on the fact that every function is documented, but raw pointer dereference is a built-in operation and therefore has no documentation aside from the (previously mentioned) pointer primitive page.
I checked The Rust Programming Language, Second Edition, one of the top google results (note: the google result is actually for 1.30.0). The string "align" does not appear.
I checked The Rust Reference. Nothing.
With no mention of alignment literally anywhere, you would think: Surely it must not be required, then, right?
Well, I checked the issue tracker, and according to this issue it sounds like alignment is required.
The text was updated successfully, but these errors were encountered: