Skip to content

Commit 8b64feb

Browse files
committed
refactor(core): remove the TypeId: const PartialEq wrapper
`core::any::TypeId` implements `const PartialEq` as of [rust-lang/rust#101698][1]. [1]: rust-lang/rust#101698
1 parent ab05db4 commit 8b64feb

File tree

2 files changed

+1
-55
lines changed

2 files changed

+1
-55
lines changed

doc/toolchain_limitations.md

-17
Original file line numberDiff line numberDiff line change
@@ -430,23 +430,6 @@ const _: () = assert!(PartialEq::eq(&(A..A), &(A..A)));
430430
```
431431

432432

433-
### `[tag:type_id_partial_eq]` `TypeId: !const PartialEq`
434-
435-
The standard library doesn't provide a `const` trait implementation of `PartialEq` for `core::any::TypeId`.
436-
437-
```rust
438-
use core::any::TypeId;
439-
assert!(TypeId::of::<()>() == TypeId::of::<()>());
440-
```
441-
442-
```rust,compile_fail,E0277
443-
#![feature(const_type_id)]
444-
use core::any::TypeId;
445-
// error[E0277]: can't compare `TypeId` with `_` in const contexts
446-
const _: () = assert!(TypeId::of::<()>() == TypeId::of::<()>());
447-
```
448-
449-
450433
### `[tag:range_const_iterator]` `Range<T>: !~const Iterator`
451434

452435
The standard library doesn't provide a `const` trait implementation of `Range<T>: Iterator`.

src/r3_core/src/bag.rs

+1-38
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! A heterogeneous collection to store property values.
2-
use core::mem::transmute;
2+
use core::{any::TypeId, mem::transmute};
33

44
/// A heterogeneous collection to store property values.
55
#[const_trait]
@@ -88,40 +88,3 @@ mod private {
8888
impl<Head: 'static, Tail: ~const Bag> const Sealed for super::List<Head, Tail> {}
8989
impl<Left: ~const Bag, Right: ~const Bag> const Sealed for super::Either<Left, Right> {}
9090
}
91-
92-
// `TypeId` doesn't implement `const PartialEq` [ref:type_id_partial_eq]
93-
/// A wrapper of [`core::any::TypeId`] that is usable in a constant context.
94-
struct TypeId {
95-
inner: core::any::TypeId,
96-
}
97-
98-
impl TypeId {
99-
#[inline]
100-
const fn of<T: 'static>() -> Self {
101-
Self {
102-
inner: core::any::TypeId::of::<T>(),
103-
}
104-
}
105-
106-
#[inline]
107-
const fn eq(&self, other: &Self) -> bool {
108-
// This relies on the implementation details of `TypeId`, but I think
109-
// we're are okay judging by the fact that WebRender is doing the same
110-
// <https://github.com/rust-lang/rust/pull/75923#issuecomment-683090745>
111-
unsafe {
112-
type TypeIdBytes = [u8; core::mem::size_of::<core::any::TypeId>()];
113-
let x: TypeIdBytes = transmute(self.inner);
114-
let y: TypeIdBytes = transmute(other.inner);
115-
// Can't just do `x == y` due to [ref:array_const_partial_eq].
116-
// A non-idiomatic loop must be used due to [ref:const_for].
117-
let mut i = 0;
118-
while i < x.len() {
119-
if x[i] != y[i] {
120-
return false;
121-
}
122-
i += 1;
123-
}
124-
true
125-
}
126-
}
127-
}

0 commit comments

Comments
 (0)