Skip to content

“consider specifying the generic arguments” is confusing when some types are unnameable #99565

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

Closed
GoldsteinE opened this issue Jul 21, 2022 · 2 comments · Fixed by #99580
Closed
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@GoldsteinE
Copy link
Contributor

GoldsteinE commented Jul 21, 2022

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=0a9a81dc70d5d9e9873ad7b65a6975d9

fn foo<T, U>(_: U) {}

fn bar() {
    foo(|| {});
}

The current output is:

error[[E0282]](https://doc.rust-lang.org/stable/error-index.html#E0282): type annotations needed
 --> src/lib.rs:4:5
  |
4 |     foo(|| {});
  |     ^^^ cannot infer type of the type parameter `T` declared on the function `foo`
  |
help: consider specifying the generic arguments
  |
4 |     foo::<T, [closure@src/lib.rs:4:9: 4:11]>(|| {});
  |        +++++++++++++++++++++++++++++++++++++

For more information about this error, try `rustc --explain E0282`.
error: could not compile `playground` due to previous error

Ideally the output should look like:

error[[E0282]](https://doc.rust-lang.org/stable/error-index.html#E0282): type annotations needed
 --> src/lib.rs:4:5
  |
4 |     foo(|| {});
  |     ^^^ cannot infer type of the type parameter `T` declared on the function `foo`
  |
help: consider specifying the generic arguments
  |
4 |     foo::<T, _>(|| {});
  |        ++++++++

For more information about this error, try `rustc --explain E0282`.
error: could not compile `playground` due to previous error

Or alternatively shouldn’t contain the suggestion at all.

@GoldsteinE GoldsteinE 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. labels Jul 21, 2022
@GoldsteinE
Copy link
Contributor Author

Oh, and cargo build doesn’t show the suggestion for some reason, but check/clippy does.

@fmease
Copy link
Member

fmease commented Jul 21, 2022

@rustbot label D-invalid-suggestion
@rustbot claim

@rustbot rustbot added the D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. label Jul 21, 2022
@bors bors closed this as completed in b6d6f10 Jul 23, 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 D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. 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