We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
u128
1 parent 5b9db69 commit dc39b35Copy full SHA for dc39b35
library/core/src/any.rs
@@ -775,8 +775,15 @@ impl TypeId {
775
}
776
777
fn as_u128(self) -> u128 {
778
- // SAFETY: we know there are 16 bytes without provenance at this location
779
- unsafe { crate::ptr::read_unaligned(&self.data as *const _ as *const u128) }
+ let mut bytes = [0; 16];
+
780
+ // This is a provenance-stripping memcpy.
781
+ for (i, chunk) in self.data.iter().copied().enumerate() {
782
+ let chunk = chunk.expose_provenance().to_ne_bytes();
783
+ let start = i * chunk.len();
784
+ bytes[start..(start + chunk.len())].copy_from_slice(&chunk);
785
+ }
786
+ u128::from_ne_bytes(bytes)
787
788
789
0 commit comments