-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Supplying an &&str when an &str is expected missing a suggestion #66023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
D-papercut
Diagnostics: An error or lint that needs small tweaks.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
If the index was just a normal method, the below code compiles with no errors:
I'm assuming that's because the compiler will dereference any number of times till it gets a type match. Rather than improve the error message, should we be dereferencing indexes as many times as necessary for consistency? |
estebank
added a commit
to estebank/rust
that referenced
this issue
Nov 13, 2023
Use more targetted span for index obligation failures by rewriting the obligation cause span. CC rust-lang#66023
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Nov 14, 2023
…rrors Always point at index span on index obligation failure Use more targetted span for index obligation failures by rewriting the obligation cause span. CC rust-lang#66023
bors
added a commit
to rust-lang-ci/rust
that referenced
this issue
Nov 14, 2023
Always point at index span on index obligation failure Use more targetted span for index obligation failures by rewriting the obligation cause span. CC rust-lang#66023
estebank
added a commit
to estebank/rust
that referenced
this issue
Nov 14, 2023
When encountering ```rust let a = std::collections::HashMap::<String,String>::new(); let s = "hello"; let _b = &a[&s]; ``` suggest `let _b = &a[s];`. Fix rust-lang#66023.
estebank
added a commit
to estebank/rust
that referenced
this issue
Nov 14, 2023
When encountering ```rust let a = std::collections::HashMap::<String,String>::new(); let s = "hello"; let _b = &a[&s]; ``` suggest `let _b = &a[s];`. Fix rust-lang#66023.
estebank
added a commit
to estebank/rust
that referenced
this issue
Nov 14, 2023
When encountering ```rust let a = std::collections::HashMap::<String,String>::new(); let s = "hello"; let _b = &a[&s]; ``` suggest `let _b = &a[s];`. Fix rust-lang#66023.
estebank
added a commit
to estebank/rust
that referenced
this issue
Dec 2, 2023
When encountering ```rust let a = std::collections::HashMap::<String,String>::new(); let s = "hello"; let _b = &a[&s]; ``` suggest `let _b = &a[s];`. Fix rust-lang#66023.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
D-papercut
Diagnostics: An error or lint that needs small tweaks.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
playground
But the error we currently get is:
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.
The text was updated successfully, but these errors were encountered: