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

Bad error message when closure parameter type can't be inferred #45685

Closed
ParadoxSpiral opened this issue Nov 1, 2017 · 2 comments
Closed

Bad error message when closure parameter type can't be inferred #45685

ParadoxSpiral opened this issue Nov 1, 2017 · 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.

Comments

@ParadoxSpiral
Copy link

ParadoxSpiral commented Nov 1, 2017

The code

fn main() {
    let a = None;
    let c = |a: Option<_>| println!("{:?}", a);
    c(a)
}

errors with

error[E0282]: type annotations needed
 --> src/main.rs:3:14
  |
2 |     let a = None;
  |         - consider giving `a` a type
3 |     let c = |a: Option<_>| println!("{:?}", a);
  |              ^ consider giving this closure parameter a type

which should be something like

error[E0282]: type annotations needed
 --> src/main.rs:3:14
  |
2 |     let a = None;
  |         - consider giving `a` a type
3 |     let c = |a: Option<_>| println!("{:?}", a);
  |                        ^ cannot infer type for `_`
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. E-needs-mentor WG-diagnostics Working group: Diagnostics and removed E-needs-mentor WG-diagnostics Working group: Diagnostics labels Nov 1, 2017
@sinesc
Copy link

sinesc commented Jun 20, 2018

The suggestion "consider giving this closure parameter a type" can also be quite frustrating when the parameter would also require lifetime annotations, see #22340

@estebank
Copy link
Contributor

Current output:

error[E0282]: type annotations needed for `std::option::Option<_>`
 --> src/main.rs:4:14
  |
4 |     let c = |a: Option<_>| println!("{:?}", a);
  |              ^ consider giving this closure parameter the explicit type `std::option::Option<_>`, where the type parameter `T` is specified

and

error[E0282]: type annotations needed for `std::option::Option<T>`
 --> src/main.rs:4:14
  |
4 |     let c = |a| println!("{:?}", a);
  |              ^ consider giving this closure parameter the explicit type `std::option::Option<T>`, where the type parameter `T` is specified

I believe this can be closed as there's little improvement to be had in the medium term.

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.
Projects
None yet
Development

No branches or pull requests

3 participants