`alloc`-only `HashMap`?
Rust Internals [Unofficial]
March 11, 2026
There have been times when I wanted HashMap/HashSet in some code which only has alloc to work with, but the default BuildHasher implementation being std-only prevents that from working.
What stops us from just moving the type definition to alloc and removing the default type parameter there, and providing the default again via a type alias in std? I think it's just methods/trait implementations which explicitly call out the RandomState argument (which only exists in std). These are:
new/with_capacity: I see no reason why we can't allow that for anyS: Defaultinstead, and this would allownewto be const once const traits happen (this also works for the with-allocator equivalents).- I think this shouldn't break existing code type inference since the existing (soon to be re-export)
stdname for it still has the default argument.
- I think this shouldn't break existing code type inference since the existing (soon to be re-export)
From<[(K, V); N]>: This can again be made to useDefaultlike above, but the possibility of.into()into a place which might be generic and relying on it for type inference could cause type inference failures. Definitely at least worth a crater run before committing anything.
So I think it might be possible? I'm not an expert on how type inference works so there might be wider fallout than I'm thinking of.
Discussion in the ATmosphere