We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 82e90d6 commit 99de372Copy full SHA for 99de372
src/libcore/mem/mod.rs
@@ -923,7 +923,12 @@ pub fn drop<T>(_x: T) {}
923
#[inline]
924
#[stable(feature = "rust1", since = "1.0.0")]
925
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
926
- ptr::read_unaligned(src as *const T as *const U)
+ // If U has a higher alignment requirement, src may not be suitably aligned.
927
+ if align_of::<U>() > align_of::<T>() {
928
+ ptr::read_unaligned(src as *const T as *const U)
929
+ } else {
930
+ ptr::read(src as *const T as *const U)
931
+ }
932
}
933
934
/// Opaque type representing the discriminant of an enum.
0 commit comments