diff --git a/doc/toolchain_limitations.md b/doc/toolchain_limitations.md index 7fca80b49b..a1657d75ee 100644 --- a/doc/toolchain_limitations.md +++ b/doc/toolchain_limitations.md @@ -430,23 +430,6 @@ const _: () = assert!(PartialEq::eq(&(A..A), &(A..A))); ``` -### `[tag:type_id_partial_eq]` `TypeId: !const PartialEq` - -The standard library doesn't provide a `const` trait implementation of `PartialEq` for `core::any::TypeId`. - -```rust -use core::any::TypeId; -assert!(TypeId::of::<()>() == TypeId::of::<()>()); -``` - -```rust,compile_fail,E0277 -#![feature(const_type_id)] -use core::any::TypeId; -// error[E0277]: can't compare `TypeId` with `_` in const contexts -const _: () = assert!(TypeId::of::<()>() == TypeId::of::<()>()); -``` - - ### `[tag:range_const_iterator]` `Range: !~const Iterator` The standard library doesn't provide a `const` trait implementation of `Range: Iterator`. diff --git a/src/r3_core/src/bag.rs b/src/r3_core/src/bag.rs index 01261efb61..9c56e6d512 100644 --- a/src/r3_core/src/bag.rs +++ b/src/r3_core/src/bag.rs @@ -1,5 +1,5 @@ //! A heterogeneous collection to store property values. -use core::mem::transmute; +use core::{any::TypeId, mem::transmute}; /// A heterogeneous collection to store property values. #[const_trait] @@ -88,40 +88,3 @@ mod private { impl const Sealed for super::List {} impl const Sealed for super::Either {} } - -// `TypeId` doesn't implement `const PartialEq` [ref:type_id_partial_eq] -/// A wrapper of [`core::any::TypeId`] that is usable in a constant context. -struct TypeId { - inner: core::any::TypeId, -} - -impl TypeId { - #[inline] - const fn of() -> Self { - Self { - inner: core::any::TypeId::of::(), - } - } - - #[inline] - const fn eq(&self, other: &Self) -> bool { - // This relies on the implementation details of `TypeId`, but I think - // we're are okay judging by the fact that WebRender is doing the same - // - unsafe { - type TypeIdBytes = [u8; core::mem::size_of::()]; - let x: TypeIdBytes = transmute(self.inner); - let y: TypeIdBytes = transmute(other.inner); - // Can't just do `x == y` due to [ref:array_const_partial_eq]. - // A non-idiomatic loop must be used due to [ref:const_for]. - let mut i = 0; - while i < x.len() { - if x[i] != y[i] { - return false; - } - i += 1; - } - true - } - } -}