Skip to content

Commit 0d2053d

Browse files
committed
Use const_eval_select macro instead of handrolling a call to the intrinsic
1 parent 92431e2 commit 0d2053d

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
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
}

tests/ui/consts/const_transmute_type_id2.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ LL | assert!(a == b);
66
|
77
note: inside `<TypeId as PartialEq>::eq`
88
--> $SRC_DIR/core/src/any.rs:LL:COL
9-
note: inside `<TypeId as PartialEq>::eq::ct`
9+
note: inside `<TypeId as PartialEq>::eq::compiletime`
1010
--> $SRC_DIR/core/src/any.rs:LL:COL
11+
= note: this error originates in the macro `$crate::intrinsics::const_eval_select` which comes from the expansion of the macro `crate::intrinsics::const_eval_select` (in Nightly builds, run with -Z macro-backtrace for more info)
1112

1213
error: aborting due to 1 previous error
1314

tests/ui/consts/const_transmute_type_id3.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ LL | assert!(a == b);
66
|
77
note: inside `<TypeId as PartialEq>::eq`
88
--> $SRC_DIR/core/src/any.rs:LL:COL
9-
note: inside `<TypeId as PartialEq>::eq::ct`
9+
note: inside `<TypeId as PartialEq>::eq::compiletime`
1010
--> $SRC_DIR/core/src/any.rs:LL:COL
11+
= note: this error originates in the macro `$crate::intrinsics::const_eval_select` which comes from the expansion of the macro `crate::intrinsics::const_eval_select` (in Nightly builds, run with -Z macro-backtrace for more info)
1112

1213
error: aborting due to 1 previous error
1314

0 commit comments

Comments
 (0)