rust-lang/rust-memory-model

`transmute_copy` should not have alignment requirements

Closed this issue · 4 comments

std::mem::transmute_copy should work on unaligned pointers, unlike dereferences and ptr::read.

This issue is fixed, see the referenced issue.

It turns out indeed that transmute_copy uses read_unaligned. I had no idea. That might be worth calling out in its documentation?

Note that the reference still needs to be T-aligned, as all references do. But it does not have to be U-aligned.

It was changed in rust-lang/rust#55052.