Skip to content

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

Closed
@Mark-Simulacrum

Description

@Mark-Simulacrum

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions