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

Do not suggest adding a type parameter on multi-letter types #70572

Closed
Mark-Simulacrum opened this issue Mar 30, 2020 · 2 comments
Closed

Do not suggest adding a type parameter on multi-letter types #70572

Mark-Simulacrum opened this issue Mar 30, 2020 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Mark-Simulacrum
Copy link
Member

In the process of writing some code, I didn't import an enum, resulting in

error[E0412]: cannot find type `AssignCommand` in this scope
  --> parser/src/command.rs:61:48
   |
61 |     fn maybe_parse_review(&mut self) -> Option<AssignCommand<'a>> {
   |                                                ^^^^^^^^^^^^^ not found in this scope
   |
help: possible candidate is found in another module, you can import it into scope
   |
1  | use crate::command::assign::AssignCommand;
   |
help: you might be missing a type parameter
   |
51 | impl<'a, AssignCommand> Input<'a> {
   |        ^^^^^^^^^^^^^^^

The import suggestion is great, but suggesting the type parameter seems likely to be confusing (and IMO, is almost certainly wrong). My suggested heuristic is to avoid suggesting the type parameter if we suggest a candidate in another module, at least, and possibly even avoid suggesting it always if there's more than on letter. It also seems suprising to suggest the type parameter on the impl and not the (more local) function?

I can try to come up with a MCVE, but I suspect it's pretty simple and I wanted to just not forget about this.

@Mark-Simulacrum Mark-Simulacrum added 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. D-confusing Diagnostics: Confusing error or lint that should be reworked. labels Mar 30, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Apr 8, 2020
…bosity, r=davidtwco

Do not suggest adding type param when `use` is already suggested

Fix rust-lang#70365, cc rust-lang#70572.
@JohnTitor JohnTitor added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Apr 12, 2020
@estebank
Copy link
Contributor

estebank commented Jun 13, 2020

I do not know if only triggering for short idents is the best course of action: type params are stylistically one upper-case letter in many languages, but not in all. If you come from Java or TypeScript only triggering on one uppercase letter will be fine, but if you come from Scala, C++ or C# you would expect Foo to be a stylistically valid type param. It doesn't matter what Rust's naming convention is, the people that need these suggestions the most are not familiar with the language yet.

We no longer emit this suggestion when the type is found somewhere and we suggest importing it. I feel it might be enough to close this ticket, but don't know for sure.

@Mark-Simulacrum
Copy link
Member Author

I think that's enough, in particular given #72640 as well. I don't think I've hit this since the import change landed, too, which makes it less of a concern for me.

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 C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants