Open
Description
I have a few questions regarding usize
and raw pointers for sized T
:
- Is
usize
guaranteed to have the same layout as one of theuN
? - Is
usize
guaranteed to have no padding bits? - Is
usize as *mut T as usize
the identity function onusize
? - Is
usize as *mut T
guaranteed to be the same astransmute::<usize, *mut T>
? - Is
ptr::read_unaligned::<*mut T>
safe for all arguments for whichptr::read_unaligned::<[u8; sizeof(*mut T)]>
is safe? - Is
usize-literal as *mut T
guaranteed to have no special behavior? (e.g. for0usize
)
The current documentation
- https://rust-lang.github.io/unsafe-code-guidelines/layout/scalars.html
- https://rust-lang.github.io/unsafe-code-guidelines/layout/pointers.html
does not answer these questions afaict.