diff --git a/src/libcore/mem/mod.rs b/src/libcore/mem/mod.rs index ee700c377815a..b1bbcaeab8def 100644 --- a/src/libcore/mem/mod.rs +++ b/src/libcore/mem/mod.rs @@ -916,7 +916,12 @@ pub fn drop(_x: T) {} #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub unsafe fn transmute_copy(src: &T) -> U { - ptr::read_unaligned(src as *const T as *const U) + // If U has a higher alignment requirement, src may not be suitably aligned. + if align_of::() > align_of::() { + ptr::read_unaligned(src as *const T as *const U) + } else { + ptr::read(src as *const T as *const U) + } } /// Opaque type representing the discriminant of an enum.