Skip to content

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

Closed
@GoldsteinE

Description

@GoldsteinE

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.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.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