From 1eb300ede104d8da439d308dd3193f4448ed442b Mon Sep 17 00:00:00 2001 From: oli Date: Sun, 1 Nov 2020 16:59:00 +0000 Subject: [PATCH] Unaligned reads are UB in Rust irrelevant on which platform we are --- compiler/rustc_middle/src/ty/consts/int.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_middle/src/ty/consts/int.rs b/compiler/rustc_middle/src/ty/consts/int.rs index 043dd957b74..bdb6e4e9660 100644 --- a/compiler/rustc_middle/src/ty/consts/int.rs +++ b/compiler/rustc_middle/src/ty/consts/int.rs @@ -133,7 +133,7 @@ impl crate::ty::HashStable for ScalarInt { // Using a block `{self.data}` here to force a copy instead of using `self.data` // directly, because `hash_stable` takes `&self` and would thus borrow `self.data`. // Since `Self` is a packed struct, that would create a possibly unaligned reference, - // which is UB on a lot of platforms. + // which is UB. { self.data }.hash_stable(hcx, hasher); self.size.hash_stable(hcx, hasher); } @@ -174,7 +174,7 @@ impl ScalarInt { // directly, because `assert_eq` takes references to its arguments and formatting // arguments and would thus borrow `self.data`. Since `Self` // is a packed struct, that would create a possibly unaligned reference, which - // is UB on a lot of platforms. + // is UB. debug_assert_eq!( truncate(self.data, self.size()), { self.data }, @@ -348,7 +348,7 @@ impl fmt::LowerHex for ScalarInt { // directly, because `write!` takes references to its formatting arguments and // would thus borrow `self.data`. Since `Self` // is a packed struct, that would create a possibly unaligned reference, which - // is UB on a lot of platforms. + // is UB. write!(f, "{:01$x}", { self.data }, self.size as usize * 2) } } @@ -362,7 +362,7 @@ impl fmt::UpperHex for ScalarInt { // directly, because `write!` takes references to its formatting arguments and // would thus borrow `self.data`. Since `Self` // is a packed struct, that would create a possibly unaligned reference, which - // is UB on a lot of platforms. + // is UB. write!(f, "{:01$X}", { self.data }, self.size as usize * 2) } }