Skip to content

Point at problematic argument on mismatched Fn argument count #48099

Closed
@estebank

Description

@estebank

(After #48047's ICE fix) When a function or closure from another crate is passed as an argument and it doesn't match the expected argument count, the error points only at the method that expected the closure:

error[E0593]: function is expected to take 1 argument, but it takes 2 arguments
  --> $DIR/closure-arg-count.rs:40:41
   |
40 |     let _it = vec![1, 2, 3].into_iter().map(usize::checked_add);
   |                                         ^^^ expected function that takes 1 argument

In the case where the function or closure is local, the span for it is highlighted:

error[E0593]: function is expected to take a single 2-tuple as argument, but it takes 0 arguments
  --> $DIR/closure-arg-count.rs:32:53
   |
32 |     let _it = vec![1, 2, 3].into_iter().enumerate().map(foo);
   |                                                     ^^^ expected function that takes a single 2-tuple as argument
...
44 | fn foo() {}
   | -------- takes 0 arguments

It would be good for consistency to point at the external's function/closure span use location, as well as printing out the signature of the method:

error[E0593]: function is expected to take 1 argument, but it takes 2 arguments
  --> $DIR/closure-arg-count.rs:40:41
   |
40 |     let _it = vec![1, 2, 3].into_iter().map(usize::checked_add);
   |                                         ^^^ ------------------ takes 2 arguments: `fn(self, _: u32) -> Option<u32>`
   |                                         |
   |                                         expected function that takes 1 argument

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