rust-lang / rust-memory-model

Collecting examples and information to help design a memory model for Rust.
Apache License 2.0
126 stars 15 forks source link

`transmute_copy` should not have alignment requirements #14

Closed arielb1 closed 5 years ago

arielb1 commented 8 years ago

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

Amanieu commented 8 years ago

cc https://github.com/rust-lang/rfcs/issues/1703

newpavlov commented 5 years ago

This issue is fixed, see the referenced issue.

RalfJung commented 5 years ago

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.

newpavlov commented 5 years ago

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