Description
I am referring to the following operation, built into the language:
let x: *const u32 = unimplemented!();
unsafe { *x }
I checked all over:
The pointer primitive docs don't mention alignment.
The std::ptr
module states:
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 tomem::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 areread_unaligned
andwrite_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.
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.