rust-lang / rust-lang/rust-clippy
clippy::implicit_hasher shouldn't warn on From<Thing> for HashMap<K, V>
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
And probably others too. AFAICT fixing this is impossible.
For example, if I have
struct MyThing(Vec<(String, String)>);
impl From<MyThing> for HashMap<String, String> {
fn from(t: MyThing) -> HashMap<String, String> {
t.0.into_iter().collect()
}
}
then I get clippy::implicit hasher with the suggestion
|
5 | impl From<MyThing> for HashMap<String, String> {
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[warn(clippy::implicit_hasher)] on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#implicit_hasher
help: consider adding a type parameter
|
5 | impl<S: ::std::hash::BuildHasher> From<MyThing> for HashMap<String, String, S> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
But I can't use that suggestion, I get E210.
error[E0210]: type parameter `S` must be used as the type parameter for some local type (e.g., `MyStruct<S>`)
--> src/main.rs:12:1
|
12 | impl<S: std::hash::BuildHasher> From<MyThing> for HashMap<String, String, S> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `S` must be used as the type parameter for some local type
|
= note: only traits defined in the current crate can be implemented for a type parameter
Link to repro in playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=eeb25dc899a8ac4d201740279be2744b
> cargo clippy -V
clippy 0.0.212 (1b89724b 2019-01-15)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked Rust Playground reproduction and the clippy::implicit_hasher lint behavior shown in the issue. Confirm whether the lint can avoid this warning or provide a valid suggestion for the From for HashMap<String, String> case, then verify the result with cargo clippy.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100