Skip to content

Commit 5b9db69

Browse files
committed
Use const_eval_select macro instead of handrolling a call to the intrinsic
1 parent cd23810 commit 5b9db69

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

library/core/src/any.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -733,22 +733,21 @@ impl const PartialEq for TypeId {
733733
return crate::intrinsics::type_id_eq(*self, *other);
734734
#[cfg(not(miri))]
735735
{
736-
const fn ct(a: &TypeId, b: &TypeId) -> bool {
737-
crate::intrinsics::type_id_eq(*a, *b)
738-
}
739-
740-
#[inline]
741-
fn rt(a: &TypeId, b: &TypeId) -> bool {
742-
a.data == b.data
743-
}
744-
745-
// Ideally we would just invoke `type_id_eq` unconditionally here,
746-
// but since we do not MIR inline intrinsics, because backends
747-
// may want to override them (and miri does!), MIR opts do not
748-
// clean up this call sufficiently for LLVM to turn repeated calls
749-
// of `TypeId` comparisons against one specific `TypeId` into
750-
// a lookup table.
751-
core::intrinsics::const_eval_select((self, other), ct, rt)
736+
let this = self;
737+
crate::intrinsics::const_eval_select!(
738+
@capture { this: &TypeId, other: &TypeId } -> bool:
739+
if const {
740+
crate::intrinsics::type_id_eq(*this, *other)
741+
} else {
742+
// Ideally we would just invoke `type_id_eq` unconditionally here,
743+
// but since we do not MIR inline intrinsics, because backends
744+
// may want to override them (and miri does!), MIR opts do not
745+
// clean up this call sufficiently for LLVM to turn repeated calls
746+
// of `TypeId` comparisons against one specific `TypeId` into
747+
// a lookup table.
748+
this.data == other.data
749+
}
750+
)
752751
}
753752
}
754753
}

0 commit comments

Comments
 (0)