Skip to content

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

Closed
@ParadoxSpiral

Description

@ParadoxSpiral

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 `_`

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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions