Open
Description
let a = std::collections::HashMap::<String,String>::new();
let s = "hello";
let _b = a[&s];
^ & not needed, this is already a reference
But the error we currently get is:
error[E0277]: the trait bound `std::string::String: std::borrow::Borrow<&str>` is not satisfied
--> src/main.rs:4:14
|
4 | let _b = a[&s];
| ^^^^^ the trait `std::borrow::Borrow<&str>` is not implemented for `std::string::String`
|
= help: the following implementations were found:
<std::string::String as std::borrow::Borrow<str>>
= note: required because of the requirements on the impl of `std::ops::Index<&&str>` for `std::collections::HashMap<std::string::String, std::string::String>`
Adding one too many layers of indirection is fairly common in rust especially with String / &str so it would be excellent if Rust could hint to the user how to fix this.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Suggestions generated by the compiler applied by `cargo fix`Category: An issue proposing an enhancement or a PR with one.Diagnostics: An error or lint that needs small tweaks.Relevant to the compiler team, which will review and decide on the PR/issue.