Skip to content

Wrong error message with closures on nightly #42143

Closed
@mcarton

Description

@mcarton

The following example

fn main() {
    let a = vec![(1, 2)];
    
    let b: Vec<_> = a.iter().map(|x: (u32, u32)| 45).collect(); 
}

gives the following error on nightly:

error[E0593]: closure takes 2 arguments but 1 argument is required
 --> src/main.rs:4:30
  |
4 |     let b: Vec<_> = a.iter().map(|x: (u32, u32)| 45).collect(); 
  |                              ^^^ ------------------ takes 2 arguments
  |                              |
  |                              expected closure that takes 1 argument

which is wrong (map is expecting a function with one argument, which is what this closure is) and the following correct message on stable/beta:

error[E0281]: type mismatch: the type `[closure@src/main.rs:4:34: 4:52]` implements the trait `std::ops::FnMut<((u32, u32),)>`, but the trait `std::ops::FnMut<(&({integer}, {integer}),)>` is required (expected reference, found tuple)
 --> src/main.rs:4:30
  |
4 |     let b: Vec<_> = a.iter().map(|x: (u32, u32)| 45).collect(); 
  |                              ^^^

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.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