Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Point at problematic argument on mismatched Fn argument count #48099

Closed

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

Activity

  1. added
    C-enhancement
    A-diagnostics
    on Feb 9, 2018
  2. added a commit that references this issue on Sep 20, 2019
  3. added a commit that references this issue on Sep 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsC-enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions