Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Point at problematic argument on mismatched Fn argument count #48099

Closed
estebank opened this issue Feb 9, 2018 · 0 comments · Fixed by #64498
Closed

Point at problematic argument on mismatched Fn argument count #48099

estebank opened this issue Feb 9, 2018 · 0 comments · Fixed by #64498
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@estebank
Copy link
Contributor

estebank commented Feb 9, 2018

(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
@estebank estebank added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints labels Feb 9, 2018
Centril added a commit to Centril/rust that referenced this issue Sep 20, 2019
When possible point at argument causing item obligation failure

Fix rust-lang#41781, fix rust-lang#42855, fix rust-lang#46658, fix rust-lang#48099, fix rust-lang#63143.
@bors bors closed this as completed in 7225264 Sep 20, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant