aHash: `AHashMap::default()` gives a type inferrence error

(again, please ignore FxHashMap - it’s really an AHashMap)

error[E0282]: type annotations needed for `FxHashMap<usize, snippet::Style, S>`
    --> compiler/rustc_errors/src/emitter.rs:1356:38
     |
1356 |                 let mut multilines = FxHashMap::default();
     |                     --------------   ^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `S` declared on the struct `AHashMap`
     |                     |
     |                     consider giving `multilines` the explicit type `FxHashMap<usize, snippet::Style, S>`, where the type parameter `S` is specified

The way FxHashMap deals with this is by making FxHashMap a straight type alias for using BuildHasherDefault: https://docs.rs/rustc-hash/1.1.0/rustc_hash/type.FxHashMap.html. Maybe AHashMap could do something similar?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (9 by maintainers)

Commits related to this issue

Most upvoted comments

error[E0502]: cannot borrow n as immutable because it is also borrowed as mutable –> sqlx-core/src/sqlite/connection/explain.rs:139:34

I wonder if it’s because of the deref trait, and if it would work better if the class directly implemented insert and get. I’ll try it out.

That looks like it is related to this https://docs.rs/rustc-serialize/0.3.24/rustc_serialize/trait.Encodable.html You may need to add a .into() to get the hashmap in/out.