Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recent change in core::any::TypeId breaks the type_id_hasher unittest #49

Open
hlopko opened this issue Aug 18, 2023 · 2 comments
Open

Comments

@hlopko
Copy link

hlopko commented Aug 18, 2023

Howdy,

The size of TypeId changed in rust-lang/rust@9e5573a, 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 hlopko changed the title https://github.com/rust-lang/rust/commit/9e5573a0d275c71dce59b715d981c6880d30703a breaks the type_id_hasher unittest Recent change in core::any::TypeId breaks the type_id_hasher unittest Aug 18, 2023
@reivilibre
Copy link

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
Copy link

This commit reivilibre@e561b1f fixes it in my fork. (Anyone should feel free to take the commit; it's under the same licence as the crate.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants