Uh oh!
There was an error while loading. Please reload this page.
Implement Hash for raw pointers to unsized types - #45483
Conversation
rust-highfive
commented
Oct 23, 2017
(rust_highfive has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Doesn't this end up interpreting T itself as the usize pair? i.e. self is &*const T, then *self as *const T is a redundant cast, then the final cast changes it to a pointer the fat pointer pieces.
I think you want *(self as *const *const T as *const (usize, usize))
There was a problem hiding this comment.
Oops, you are right, of course. Fixed this and added a test.
7b24872 to
f4b4631CompareThere was a problem hiding this comment.
I thought impl are insta-stable?
Also, please change the TODO to FIXME to pass tidy check.
[00:03:26] tidy error: /checkout/src/libcore/hash/mod.rs:667: TODO is deprecated; use FIXME
[00:03:26] tidy error: /checkout/src/libcore/hash/mod.rs:687: TODO is deprecated; use FIXME
alexcrichton
commented
Oct 25, 2017
Is this something that's possible to implement without specialization? We've been hesitant to stabilize any API surface area that requires specialization to exist up to this point unfortunately |
Yes, it could be done in a single |
alexcrichton
commented
Oct 25, 2017
In that case, could this PR be updated to that implementation? |
mbrubeck
commented
Oct 25, 2017
Updated to not use specialization. |
alexcrichton
commented
Oct 25, 2017
@bors: r+ Awesome, thanks! cc @rust-lang/libs I'm going ahead an approving this as this seems like the natural extension of |
bors
commented
Oct 25, 2017
📌 Commit c2c1910 has been approved by |
Implement Hash for raw pointers to unsized types This is useful for some niche cases, like a hash table of slices or trait objects where the key is the raw pointer. Example use case: https://docs.rs/by_address
dtolnay
left a comment
There was a problem hiding this comment.
Seems good to me. This implementation is not necessarily correct if we ever add extra-fat pointers, but we can sort that out at the time.
This fixes the problem where only the "data" part of a fat pointer could be hashed. Depends on rust-lang/rust#45483. Fixes#2.
Allow ptr::hash to accept fat pointers Fat pointers implement Hash since rust-lang#45483. This is a follow-up to rust-lang#56250.
Allow ptr::hash to accept fat pointers Fat pointers implement Hash since rust-lang#45483. This is a follow-up to rust-lang#56250.
Allow ptr::hash to accept fat pointers Fat pointers implement Hash since rust-lang#45483. This is a follow-up to rust-lang#56250.
Allow ptr::hash to accept fat pointers Fat pointers implement Hash since rust-lang#45483. This is a follow-up to rust-lang#56250.
This is useful for some niche cases, like a hash table of slices or trait objects where the key is the raw pointer. Example use case: https://docs.rs/by_address