Closure argument mismatch tweaks

- use consistent phrasing for expected and found arguments
 - suggest changing arugments to tuple if possible
 - suggest changing single tuple argument to arguments if possible
This commit is contained in:
Esteban Küber 2018-01-19 01:28:20 -08:00
parent bb345a0be3
commit 7ed00caacc
3 changed files with 214 additions and 177 deletions

View file

@ -18,6 +18,8 @@ fn main() {
//~^ ERROR closure is expected to take
[1, 2, 3].sort_by(|(tuple, tuple2)| panic!());
//~^ ERROR closure is expected to take
[1, 2, 3].sort_by(|(tuple, tuple2): (usize, _)| panic!());
//~^ ERROR closure is expected to take
f(|| panic!());
//~^ ERROR closure is expected to take
@ -32,6 +34,9 @@ fn main() {
let bar = |i, x, y| i;
let _it = vec![1, 2, 3].into_iter().enumerate().map(bar);
//~^ ERROR closure is expected to take
let _it = vec![1, 2, 3].into_iter().enumerate().map(qux);
//~^ ERROR function is expected to take
}
fn foo() {}
fn qux(x: usize, y: usize) {}

View file

@ -14,64 +14,97 @@ error[E0593]: closure is expected to take 2 arguments, but it takes 1 argument
| |
| expected closure that takes 2 arguments
error[E0593]: closure is expected to take 2 arguments, but it takes 1 argument
error[E0593]: closure is expected to take 2 distinct arguments, but it takes a single 2-tuple as argument
--> $DIR/closure-arg-count.rs:19:15
|
19 | [1, 2, 3].sort_by(|(tuple, tuple2)| panic!());
| ^^^^^^^ ----------------- takes 1 argument
| ^^^^^^^ ----------------- takes a single 2-tuple as argument
| |
| expected closure that takes 2 arguments
| expected closure that takes 2 distinct arguments
help: change the closure to take multiple arguments instead of a single tuple
|
19 | [1, 2, 3].sort_by(|tuple, tuple2| panic!());
| ^^^^^^^^^^^^^^^
error[E0593]: closure is expected to take 2 distinct arguments, but it takes a single 2-tuple as argument
--> $DIR/closure-arg-count.rs:21:15
|
21 | [1, 2, 3].sort_by(|(tuple, tuple2): (usize, _)| panic!());
| ^^^^^^^ ----------------------------- takes a single 2-tuple as argument
| |
| expected closure that takes 2 distinct arguments
help: change the closure to take multiple arguments instead of a single tuple
|
21 | [1, 2, 3].sort_by(|tuple, tuple2| panic!());
| ^^^^^^^^^^^^^^^
error[E0593]: closure is expected to take 1 argument, but it takes 0 arguments
--> $DIR/closure-arg-count.rs:21:5
--> $DIR/closure-arg-count.rs:23:5
|
21 | f(|| panic!());
23 | f(|| panic!());
| ^ -- takes 0 arguments
| |
| expected closure that takes 1 argument
|
= note: required by `f`
error[E0593]: closure is expected to take a single tuple as argument, but it takes 2 distinct arguments
--> $DIR/closure-arg-count.rs:24:53
|
24 | let _it = vec![1, 2, 3].into_iter().enumerate().map(|i, x| i);
| ^^^ ------ help: consider changing the closure to accept a tuple: `|(i, x)|`
| |
| expected closure that takes a single tuple as argument
error[E0593]: closure is expected to take a single tuple as argument, but it takes 2 distinct arguments
error[E0593]: closure is expected to take a single 2-tuple as argument, but it takes 2 distinct arguments
--> $DIR/closure-arg-count.rs:26:53
|
26 | let _it = vec![1, 2, 3].into_iter().enumerate().map(|i: usize, x| i);
| ^^^ ------------- help: consider changing the closure to accept a tuple: `|(i, x): (usize, _)|`
26 | let _it = vec![1, 2, 3].into_iter().enumerate().map(|i, x| i);
| ^^^ ------ takes 2 distinct arguments
| |
| expected closure that takes a single tuple as argument
| expected closure that takes a single 2-tuple as argument
help: change the closure to accept a tuple instead of individual arguments
|
26 | let _it = vec![1, 2, 3].into_iter().enumerate().map(|(i, x)| i);
| ^^^^^^^^
error[E0593]: closure is expected to take a single 2-tuple as argument, but it takes 3 distinct arguments
error[E0593]: closure is expected to take a single 2-tuple as argument, but it takes 2 distinct arguments
--> $DIR/closure-arg-count.rs:28:53
|
28 | let _it = vec![1, 2, 3].into_iter().enumerate().map(|i, x, y| i);
28 | let _it = vec![1, 2, 3].into_iter().enumerate().map(|i: usize, x| i);
| ^^^ ------------- takes 2 distinct arguments
| |
| expected closure that takes a single 2-tuple as argument
help: change the closure to accept a tuple instead of individual arguments
|
28 | let _it = vec![1, 2, 3].into_iter().enumerate().map(|(i, x)| i);
| ^^^^^^^^
error[E0593]: closure is expected to take a single 2-tuple as argument, but it takes 3 distinct arguments
--> $DIR/closure-arg-count.rs:30:53
|
30 | let _it = vec![1, 2, 3].into_iter().enumerate().map(|i, x, y| i);
| ^^^ --------- takes 3 distinct arguments
| |
| expected closure that takes a single 2-tuple as argument
error[E0593]: function is expected to take a single 2-tuple as argument, but it takes 0 arguments
--> $DIR/closure-arg-count.rs:30:53
--> $DIR/closure-arg-count.rs:32:53
|
30 | let _it = vec![1, 2, 3].into_iter().enumerate().map(foo);
32 | let _it = vec![1, 2, 3].into_iter().enumerate().map(foo);
| ^^^ expected function that takes a single 2-tuple as argument
...
37 | fn foo() {}
41 | fn foo() {}
| -------- takes 0 arguments
error[E0593]: closure is expected to take a single 2-tuple as argument, but it takes 3 distinct arguments
--> $DIR/closure-arg-count.rs:33:53
--> $DIR/closure-arg-count.rs:35:53
|
32 | let bar = |i, x, y| i;
34 | let bar = |i, x, y| i;
| --------- takes 3 distinct arguments
33 | let _it = vec![1, 2, 3].into_iter().enumerate().map(bar);
35 | let _it = vec![1, 2, 3].into_iter().enumerate().map(bar);
| ^^^ expected closure that takes a single 2-tuple as argument
error: aborting due to 9 previous errors
error[E0593]: function is expected to take a single 2-tuple as argument, but it takes 2 distinct arguments
--> $DIR/closure-arg-count.rs:37:53
|
37 | let _it = vec![1, 2, 3].into_iter().enumerate().map(qux);
| ^^^ expected function that takes a single 2-tuple as argument
...
42 | fn qux(x: usize, y: usize) {}
| -------------------------- takes 2 distinct arguments
error: aborting due to 11 previous errors