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

Allow creating an AHashMap without an Eq or Hash bound on the keys #52

Closed
jyn514 opened this issue Oct 16, 2020 · 5 comments
Closed

Allow creating an AHashMap without an Eq or Hash bound on the keys #52

jyn514 opened this issue Oct 16, 2020 · 5 comments

Comments

@jyn514
Copy link

jyn514 commented Oct 16, 2020

with_capacity_and_hasher requires K to implement Eq:

error[E0277]: the trait bound `K: Hash` is not satisfied
  --> compiler/rustc_data_structures/src/sso/map.rs:89:29
   |
89 |             SsoHashMap::Map(FxHashMap::with_capacity_and_hasher(cap, Default::default()))
   |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Hash` is not implemented for `K`
   |
   = note: required by `AHashMap::<K, V, S>::with_capacity_and_hasher`

Consider relaxing that bound, I think you shouldn't need it for constructing the hashmap, only for operations involving the elements (get/set/entry). Same request for various other functions, new(), capacity(), len(), etc.

Note the error is misleading here - FxHashMap is an alias for AHashMap that I renamed because it was simpler than changing a hundred imports.

Originally posted by @jyn514 in rust-lang/rust#77996 (comment)

@jyn514 jyn514 changed the title Allow creating an AHashMap with out an Eq bound on the keys Allow creating an AHashMap without an Eq bound on the keys Oct 16, 2020
tkaitchuck added a commit that referenced this issue Oct 16, 2020
Signed-off-by: Tom Kaitchuck <Tom.Kaitchuck@gmail.com>
@tkaitchuck
Copy link
Owner

Done 00d7e74

@jyn514
Copy link
Author

jyn514 commented Oct 16, 2020

Sorry, my request wasn't clear: I said 'Eq' but I meant 'neither Eq not Hash'. Both aren't necessary for these functions.

@tkaitchuck
Copy link
Owner

@jyn514 What are you doing with these hashmaps that don't contain any items?!

@tkaitchuck tkaitchuck reopened this Oct 16, 2020
@jyn514
Copy link
Author

jyn514 commented Oct 16, 2020

Don't ask me, ask rustc 😆 Small set optimizations! https://doc.rust-lang.org/nightly/nightly-rustc/rustc_data_structures/sso/enum.SsoHashMap.html

@jyn514 jyn514 changed the title Allow creating an AHashMap without an Eq bound on the keys Allow creating an AHashMap without an Eq or Hash bound on the keys Oct 16, 2020
tkaitchuck added a commit that referenced this issue Oct 16, 2020
@tkaitchuck
Copy link
Owner

Ok. Done 23af182
Released as 0.5.3

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