Skip to content

Commit 30c02f1

Browse files
committed
Explain mad type_id_of_val
1 parent d7bdd38 commit 30c02f1

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

tests/mir-opt/gvn_type_id_polymorphic.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
fn generic<T>() {}
77

8+
// Since `type_id` contains provenance, we cannot turn it into an integer,
9+
// but for the purposes of this test, it is sufficient to use the length of the
10+
// type name as the first 8 bytes of the `u128` and the first 8 bytes of the type name
11+
// as the rest of the bytes of the `u128`. The main thing being tested is the result of
12+
// calling this function being simple enough that comparisons of it are turned into
13+
// a direct MIR `Eq` bin op.
814
const fn type_id_of_val<T: 'static>(_: &T) -> u128 {
915
let name = std::intrinsics::type_name::<T>();
1016
let len = name.len() as u64;

0 commit comments

Comments
 (0)