diff --git a/library/core/src/any.rs b/library/core/src/any.rs index e8f00e8760e13..a4252d0c9e03c 100644 --- a/library/core/src/any.rs +++ b/library/core/src/any.rs @@ -605,7 +605,9 @@ impl dyn Any + Send + Sync { #[derive(Clone, Copy, Debug, Eq, PartialOrd, Ord)] #[stable(feature = "rust1", since = "1.0.0")] pub struct TypeId { - t: u128, + // We avoid using `u128` because that imposes higher alignment requirements on many platforms. + // See issue #115620 for more information. + t: (u64, u64), } #[stable(feature = "rust1", since = "1.0.0")] @@ -637,7 +639,10 @@ impl TypeId { #[rustc_const_unstable(feature = "const_type_id", issue = "77125")] pub const fn of() -> TypeId { let t: u128 = intrinsics::type_id::(); - TypeId { t } + + let t1 = (t >> 64) as u64; + let t2 = t as u64; + TypeId { t: (t1, t2) } } } @@ -657,7 +662,7 @@ impl hash::Hash for TypeId { // - It is correct to do so -- only hashing a subset of `self` is still // with an `Eq` implementation that considers the entire value, as // ours does. - (self.t as u64).hash(state); + self.t.1.hash(state); } }