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

Hash consistency for Borrow + Hash traits for Utf8Bytes #484

Merged

Conversation

yhx-12243
Copy link
Contributor

@yhx-12243 yhx-12243 commented Feb 18, 2025

As mentioned in documentation of rust standard library, if a type implements both Borrow and Hash, they should be consistent: hash(x) == hash(x.borrow()), (cf. https://rust-lang.github.io/rust-clippy/master/index.html#impl_hash_borrow_with_str_and_bytes)

However, the current implementation is not consistent. It may cause unexpected behaviors when using HashMap for these.

Copy link
Member

@daniel-abramov daniel-abramov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks!

(cf. https://rust-lang.github.io/rust-clippy/master/index.html#impl_hash_borrow_with_str_and_bytes)

NB: Note that the particular lint covers a similar, but different case.


@sdroege, mentioning you just in case you rely on the current Hash implementation somewhere in other crates 🙂

@sdroege
Copy link
Contributor

sdroege commented Feb 20, 2025

I don't, thanks for catching this :)

@daniel-abramov daniel-abramov merged commit 56d758b into snapview:master Feb 20, 2025
7 checks passed
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

Successfully merging this pull request may close these issues.

3 participants