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

Idea for hashing pointers to unsized types #2

Closed
durka opened this issue Oct 25, 2017 · 1 comment
Closed

Idea for hashing pointers to unsized types #2

durka opened this issue Oct 25, 2017 · 1 comment

Comments

@durka
Copy link

durka commented Oct 25, 2017

Can this trick (essentially, compare sizeof &T::Target to sizeof usize) be used to eliminate the FIXME?

by_address/src/lib.rs

Lines 134 to 138 in 3bdda92

fn hash<H: Hasher>(&self, state: &mut H) {
// FIXME: For fat pointers to dynamically-sized types, this discards the extra data (vtable
// pointer or length), so it may have a high collision rate in certain cases.
(self.addr() as *const ()).hash(state)
}

@mbrubeck
Copy link
Owner

Yes, and I just landed that in libstd: rust-lang/rust#45483.

I'm wary about using it in this crate, since it depends on assumptions about the (implementation-defined) layout of pointers to unsized types. My current plan is to wait until the implementation in libstd is stable, and then depend on that.

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