Skip to content

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

@jyn514

Description

@jyn514

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions