Skip to content

Commit 80059f9

Browse files
committed
Test tuple suggestions, including tuple-as-function-argument
1 parent 94c300a commit 80059f9

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Test suggesting tuples where bare arguments may have been passed
2+
// See issue #86481 for details.
3+
4+
// run-rustfix
5+
6+
fn main() {
7+
let _: Result<(i32, i8), ()> = Ok((1, 2));
8+
//~^ ERROR this enum variant takes 1 argument but 2 arguments were supplied
9+
let _: Option<(i32, i8, &'static str)> = Some((1, 2, "hi"));
10+
//~^ ERROR this enum variant takes 1 argument but 3 arguments were supplied
11+
let _: Option<()> = Some(());
12+
//~^ ERROR this enum variant takes 1 argument but 0 arguments were supplied
13+
14+
f((1, 2)); //~ ERROR this function takes 1 argument
15+
}
16+
17+
fn f(_: (i32, i32)) {
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Test suggesting tuples where bare arguments may have been passed
2+
// See issue #86481 for details.
3+
4+
// run-rustfix
5+
6+
fn main() {
7+
let _: Result<(i32, i8), ()> = Ok(1, 2);
8+
//~^ ERROR this enum variant takes 1 argument but 2 arguments were supplied
9+
let _: Option<(i32, i8, &'static str)> = Some(1, 2, "hi");
10+
//~^ ERROR this enum variant takes 1 argument but 3 arguments were supplied
11+
let _: Option<()> = Some();
12+
//~^ ERROR this enum variant takes 1 argument but 0 arguments were supplied
13+
14+
f(1, 2); //~ ERROR this function takes 1 argument
15+
}
16+
17+
fn f(_: (i32, i32)) {
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
error[E0061]: this enum variant takes 1 argument but 2 arguments were supplied
2+
--> $DIR/args-instead-of-tuple.rs:7:36
3+
|
4+
LL | let _: Result<(i32, i8), ()> = Ok(1, 2);
5+
| ^^ - - supplied 2 arguments
6+
|
7+
help: use parentheses to construct a tuple
8+
|
9+
LL | let _: Result<(i32, i8), ()> = Ok((1, 2));
10+
| + +
11+
12+
error[E0061]: this enum variant takes 1 argument but 3 arguments were supplied
13+
--> $DIR/args-instead-of-tuple.rs:9:46
14+
|
15+
LL | let _: Option<(i32, i8, &'static str)> = Some(1, 2, "hi");
16+
| ^^^^ - - ---- supplied 3 arguments
17+
|
18+
help: use parentheses to construct a tuple
19+
|
20+
LL | let _: Option<(i32, i8, &'static str)> = Some((1, 2, "hi"));
21+
| + +
22+
23+
error[E0061]: this enum variant takes 1 argument but 0 arguments were supplied
24+
--> $DIR/args-instead-of-tuple.rs:11:25
25+
|
26+
LL | let _: Option<()> = Some();
27+
| ^^^^-- supplied 0 arguments
28+
|
29+
help: expected the unit value `()`; create it with empty parentheses
30+
|
31+
LL | let _: Option<()> = Some(());
32+
| ++
33+
34+
error[E0061]: this function takes 1 argument but 2 arguments were supplied
35+
--> $DIR/args-instead-of-tuple.rs:14:5
36+
|
37+
LL | f(1, 2);
38+
| ^ - - supplied 2 arguments
39+
|
40+
note: function defined here
41+
--> $DIR/args-instead-of-tuple.rs:17:4
42+
|
43+
LL | fn f(_: (i32, i32)) {
44+
| ^ -------------
45+
help: use parentheses to construct a tuple
46+
|
47+
LL | f((1, 2));
48+
| + +
49+
50+
error: aborting due to 4 previous errors
51+
52+
For more information about this error, try `rustc --explain E0061`.

0 commit comments

Comments
 (0)