Skip to content

Closure argument type ambiguity errors when the outer call has wrong number of arguments #142790

Open
@camsteffen

Description

@camsteffen

Code

fn test() {
    takes_two_args(|s| {
        s.to_string();
    });
}

fn takes_two_args(thing: u32, f: impl Fn(&str)) {
    todo!();
}

Current output

error[E0282]: type annotations needed
 --> src/lib.rs:3:21
  |
3 |     takes_two_args(|s| {
  |                     ^
4 |         s.to_string();
  |         - type must be known at this point
  |
help: consider giving this closure parameter an explicit type
  |
3 |     takes_two_args(|s: /* Type */| {
  |                      ++++++++++++

Desired output

Wrong number of arguments.

Rationale and extra context

In addition to wrong number of arguments, maybe we could also detect when the argument type is not a function. (Both are true in this example)

Other cases

Rust Version

1.87.0

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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