anymap icon indicating copy to clipboard operation
anymap copied to clipboard

Recent change in core::any::TypeId breaks the `type_id_hasher` unittest

Open hlopko opened this issue 1 year ago • 2 comments

Howdy,

The size of TypeId changed in https://github.com/rust-lang/rust/commit/9e5573a0d275c71dce59b715d981c6880d30703a, and the unittest type_id_hasher no longer builds:

cannot transmute between types of different sizes, or dependently-sized types
    |
638 |         assert_eq!(hasher.finish(), unsafe { core::mem::transmute::<TypeId, u64>(type_id) });
    |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: source type: `TypeId` (128 bits)
    = note: target type: `u64` (64 bits)

It seems to me that the commit doesn't affect the behavior of the anymap crate, it only affects the unittest. Could you please confirm that that is the case?

hlopko avatar Aug 18 '23 13:08 hlopko

Seems right to me: the implementation of TypeId still only hashes the lower 64 bits (the u64) of its internal 128 bit number: https://doc.rust-lang.org/src/core/any.rs.html#655

So the unit test needs fixing, but otherwise I don't think anything is wrong here.

However relying on TypeId's hashing characteristics is perhaps a little bit unfortunate, but understandable.

reivilibre avatar Jan 01 '24 12:01 reivilibre

This commit https://github.com/reivilibre/anymap3/commit/e561b1fe67bb262a067ffa9bccc19f8588175367 fixes it in my fork. (Anyone should feel free to take the commit; it's under the same licence as the crate.)

reivilibre avatar Jan 01 '24 12:01 reivilibre