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

Vague error message when using generics #71924

Closed
Suibeom opened this issue May 5, 2020 · 4 comments
Closed

Vague error message when using generics #71924

Suibeom opened this issue May 5, 2020 · 4 comments
Assignees
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-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. 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

@Suibeom
Copy link

Suibeom commented May 5, 2020

I received the following error while working on an Amethyst project;

error[E0107]: wrong number of type arguments: expected at least 1, found 0
  --> src/main.rs:67:26
   |
67 |         WriteStorage<'a, TileMap>,
   |                          ^^^^^^^ expected at least 1 type argument

After scratching my head for a while and searching the Amethyst Discord, and finally StackOverflow, I realized I was having a brainfart and the type I was using was a generic and I wasn't fully defining it. I had been having some trouble getting an import to work successfully, so I was unsure if the type was even successfully being added to my namespace in the first place, which left me completely confused as to how to interpret this error. Was the compiler telling me 'TileMap' is not a type..??

This error does not seem in line with the level of explicitness of most of the first-pass compiler errors, and does not contain any resolution suggestions. At least one past issue exists about this particular type of error and several stackoverflow threads exist asking, essentially, 'What does this error mean?' (with successful resolutions of the form, 'That's a generic type with missing type parameters') which seems like a good indicator that the error could be more helpful and explicit. (e.g. 'This generic type is expecting _ type parameters but only found _')

This issue has been assigned to @Patryk27 via this comment.

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. 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. labels May 5, 2020
@JohnTitor JohnTitor added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label May 6, 2020
@moxian
Copy link
Contributor

moxian commented May 8, 2020

The OP issue seems to be inside a type declaration, but this also often happens in expression context, e.g.

let v = vec![1i32].into_iter().collect::<Vec>();

and in these cases it would be a good compiler suggest to add an anonymous type, i.e. "Consider changing this to Vec<_>"

@Patryk27
Copy link
Contributor

Patryk27 commented Jun 6, 2020

@rustbot claim

@Alexendoo
Copy link
Member

Triage: Hi, are you still working on this issue (and/or #66228) @Patryk27?

@Patryk27
Copy link
Contributor

Hi! Thanks for pinging - though I've been busy lately, I'm generally still working on this feature; I've got a simple PoC more-or-less working and I'll try to submit a pull request as soon as I've got more time on my hands :-)

bors added a commit to rust-lang-ci/rust that referenced this issue Jan 13, 2021
Rework diagnostics for wrong number of generic args (fixes rust-lang#66228 and rust-lang#71924)

This PR reworks the `wrong number of {} arguments` message, so that it provides more details and contextual hints.
flip1995 pushed a commit to flip1995/rust that referenced this issue Jan 15, 2021
Rework diagnostics for wrong number of generic args (fixes rust-lang#66228 and rust-lang#71924)

This PR reworks the `wrong number of {} arguments` message, so that it provides more details and contextual hints.
@dtolnay dtolnay closed this as completed Jan 27, 2022
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-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. 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

No branches or pull requests

8 participants