Skip to content
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

Suggest importable type that differs only in capitalization #72641

Open
dtolnay opened this issue May 27, 2020 · 4 comments
Open

Suggest importable type that differs only in capitalization #72641

dtolnay opened this issue May 27, 2020 · 4 comments
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

@dtolnay
Copy link
Member

dtolnay commented May 27, 2020

struct S {
    m: Hashmap<String, ()>,
}
error[E0412]: cannot find type `Hashmap` in this scope
 --> src/main.rs:2:8
  |
2 |     m: Hashmap<String, ()>,
  |        ^^^^^^^ not found in this scope

If the code had been written with HashMap instead of Hashmap, we would get the following extremely likely correct suggestion:

error[E0412]: cannot find type `HashMap` in this scope
 --> src/main.rs:2:8
  |
2 |     m: HashMap<String, ()>,
  |        ^^^^^^^ not found in this scope
  |
help: consider importing one of these items
  |
1 | use std::collections::HashMap;
  |
1 | use std::collections::hash_map::HashMap;
  |

Hashmap is a fairly common capitalization in other languages (https://grep.app/search?q=Hashmap&case=true) so it would be good to provide an appropriate suggestion in this case.

(For whatever reason this doesn't trigger #72640.)

@dtolnay dtolnay added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 27, 2020
@estebank estebank added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-papercut Diagnostics: An error or lint that needs small tweaks. labels May 28, 2020
@chrissimpkins
Copy link
Member

@rustbot claim

@chrissimpkins
Copy link
Member

chrissimpkins commented May 30, 2020

Here is where I am with the error message and suggestion in a case-insensitive match:

error[E0412]: cannot find type `Hashmap` in this scope
 --> src/lib.rs:2:8
  |
2 |     m: Hashmap<String, ()>,
  |        ^^^^^^^ not found in this scope
  |
help: did you mean `std::collections::HashMap`?
  |
2 |     m: std::collections::HashMap<String, ()>,
  |        ^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Thoughts about broadening to more libstd types? IIUC, under the conditions: (1) not explicitly brought into scope; (2) not defined in the Rust prelude; (3) not a primitive type, misspelled std lib types result in the "not found in this scope" message with no suggestion.

@chrissimpkins
Copy link
Member

#72988

@estebank
Copy link
Contributor

estebank commented Jun 13, 2020

For whatever reason this doesn't trigger #72640.

We explicitly keep track of whether we are looking at a path's generics in field currently_processing_generics and only suggest adding a new type param then that is the case. I believe my original thinking was that the likelihood of it being a reasonable suggestion increased in that case. Also, looking at the diff for the original PR introducing this there are cases like type Output = Option<Foo>;, where if we triggered for type Output = Foo; we would be suggesting type Output<Foo> = Foo; which is nonsensical. If by experience you feel we should suggest in the case of struct S(Foo);, then I can change this.

I think I've addressed this aside in a reasonable way in #73320:

Screen Shot 2020-06-13 at 11 25 24 AM

estebank added a commit to estebank/rust that referenced this issue Jun 17, 2020
Suggest new type parameter on single char uppercase ident even if it
doesn't appear in a field's type parameter.

Address comment in rust-lang#72641.
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants