-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.Diagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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.
yoshuawuyts
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.Diagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.