Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 1eb300e

Browse files
committed
Unaligned reads are UB in Rust irrelevant on which platform we are
1 parent e5258e6 commit 1eb300e

File tree

1 file changed

+4
-4
lines changed
  • compiler/rustc_middle/src/ty/consts

1 file changed

+4
-4
lines changed

compiler/rustc_middle/src/ty/consts/int.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<CTX> crate::ty::HashStable<CTX> for ScalarInt {
133133
// Using a block `{self.data}` here to force a copy instead of using `self.data`
134134
// directly, because `hash_stable` takes `&self` and would thus borrow `self.data`.
135135
// Since `Self` is a packed struct, that would create a possibly unaligned reference,
136-
// which is UB on a lot of platforms.
136+
// which is UB.
137137
{ self.data }.hash_stable(hcx, hasher);
138138
self.size.hash_stable(hcx, hasher);
139139
}
@@ -174,7 +174,7 @@ impl ScalarInt {
174174
// directly, because `assert_eq` takes references to its arguments and formatting
175175
// arguments and would thus borrow `self.data`. Since `Self`
176176
// is a packed struct, that would create a possibly unaligned reference, which
177-
// is UB on a lot of platforms.
177+
// is UB.
178178
debug_assert_eq!(
179179
truncate(self.data, self.size()),
180180
{ self.data },
@@ -348,7 +348,7 @@ impl fmt::LowerHex for ScalarInt {
348348
// directly, because `write!` takes references to its formatting arguments and
349349
// would thus borrow `self.data`. Since `Self`
350350
// is a packed struct, that would create a possibly unaligned reference, which
351-
// is UB on a lot of platforms.
351+
// is UB.
352352
write!(f, "{:01$x}", { self.data }, self.size as usize * 2)
353353
}
354354
}
@@ -362,7 +362,7 @@ impl fmt::UpperHex for ScalarInt {
362362
// directly, because `write!` takes references to its formatting arguments and
363363
// would thus borrow `self.data`. Since `Self`
364364
// is a packed struct, that would create a possibly unaligned reference, which
365-
// is UB on a lot of platforms.
365+
// is UB.
366366
write!(f, "{:01$X}", { self.data }, self.size as usize * 2)
367367
}
368368
}

0 commit comments

Comments
 (0)