Skip to content

Commit c4371c8

Browse files
committed
Auto merge of rust-lang#55052 - newpavlov:patch-2, r=alexcrichton
Use read_unaligned instead of read in transmute_copy Closes: rust-lang#55044 This change could result in performance regression on non-x86 platforms. (but it also can fix some of UB which lurks in existing programs) An alternative would be to update `transmute_copy` documentation with alignment requirements.
2 parents 65204a9 + 4210cca commit c4371c8

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/libcore/mem.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ pub fn drop<T>(_x: T) { }
809809
#[inline]
810810
#[stable(feature = "rust1", since = "1.0.0")]
811811
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
812-
ptr::read(src as *const T as *const U)
812+
ptr::read_unaligned(src as *const T as *const U)
813813
}
814814

815815
/// Opaque type representing the discriminant of an enum.

0 commit comments

Comments
 (0)