Use read_unaligned instead of read in transmute_copy

Closes: #55044

This change could result in performance regression on non-x86 platforms. Alternative would be to update `transmute_copy` with alignment requirements.
This commit is contained in:
Artyom Pavlov 2018-10-13 22:01:59 +00:00 committed by GitHub
parent 8f19cadf95
commit 4210ccad14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -818,7 +818,7 @@ pub fn drop<T>(_x: T) { }
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
ptr::read(src as *const T as *const U)
ptr::read_unaligned(src as *const T as *const U)
}
/// Opaque type representing the discriminant of an enum.