HashMap::from_iter doesn't compile without explicitly supplying the hasher #90879
Labels
A-inference
Area: Type inference
A-iterators
Area: Iterators
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Now that
FromIterator
is in the prelude, I expected to be able to create aHashMap
like usingHashMap::from_iter()
:However, that doesn't compile, saying "type annotations needed for
HashMap<&str, i32, S>
":Playground
I would expect
<HashMap as FromIterator>::from_iter()
to pick the default hasher in absence of an explicit request for a different one requested, likeVec::from_iter()
compiles and defaults to the global allocator. (HashMap::from()
also compiles, but it seems to be limited to the default hasher.)Note that this is different from #69123 which is about a confusing diagnostic. This issue is about the error itself, in particular as compared to
Vec::from_iter()
.Tested with Rust 1.56.1 stable.
The text was updated successfully, but these errors were encountered: