Skip to content

Better error for missing tuple pattern in args #44150

Closed
@Xion

Description

@Xion

Playground link

fn main() {
    let v = vec![1, 2, 3];
    let v2: Vec<_> = v.into_iter().enumerate().map(|i, x| i).collect();
    println!("{:?}", v2);
}

Currently, this produces a somewhat confusing error:

error[E0593]: closure takes 2 arguments but 1 argument is required
 --> src/main.rs:3:48
  |
3 |     let v2: Vec<_> = v.into_iter().enumerate().map(|i, x| i).collect();
  |                                                ^^^ -------- takes 2 arguments
  |                                                |
  |                                                expected closure that takes 1 argument

which could potentially be improved for this common case (an N-tuple was expected, but the closure takes N arguments instead). This could extend to other cases where there is a tuple : multiple arguments mismatch.

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.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions