Add more tuple pattern too many fields test cases

This commit is contained in:
Noah Lev 2021-08-18 16:13:25 -07:00
parent da25af2940
commit d0b482a27c
2 changed files with 258 additions and 6 deletions

View File

@ -1,4 +1,18 @@
struct S(u8, u8, u8);
struct M(
u8,
u8,
u8,
u8,
u8,
);
struct Z0;
struct Z1();
enum E1 {
Z0,
Z1(),
}
fn main() {
match (1, 2, 3) {
@ -13,4 +27,32 @@ fn main() {
//~^ ERROR this pattern has 4 fields, but the corresponding tuple struct has 3 fields
_ => {}
}
match M(1, 2, 3, 4, 5) {
M(1, 2, 3, 4, 5, 6) => {}
//~^ ERROR this pattern has 6 fields, but the corresponding tuple struct has 5 fields
}
match Z0 {
Z0 => {}
Z0() => {} //~ ERROR expected tuple struct or tuple variant, found unit struct `Z0`
Z0(_) => {} //~ ERROR expected tuple struct or tuple variant, found unit struct `Z0`
Z0(_, _) => {} //~ ERROR expected tuple struct or tuple variant, found unit struct `Z0`
}
match Z1() {
Z1 => {} //~ ERROR match bindings cannot shadow tuple structs
Z1() => {}
Z1(_) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple struct has 0 fields
Z1(_, _) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple struct has 0 fields
}
match E1::Z0 {
E1::Z0 => {}
E1::Z0() => {} //~ ERROR expected tuple struct or tuple variant, found unit variant `E1::Z0`
E1::Z0(_) => {} //~ ERROR expected tuple struct or tuple variant, found unit variant `E1::Z0`
E1::Z0(_, _) => {} //~ ERROR expected tuple struct or tuple variant, found unit variant `E1::Z0`
}
match E1::Z1() {
E1::Z1 => {} //~ ERROR expected unit struct, unit variant or constant, found tuple variant `E1::Z1`
E1::Z1() => {}
E1::Z1(_) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple variant has 0 fields
E1::Z1(_, _) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple variant has 0 fields
}
}

View File

@ -1,5 +1,154 @@
error[E0530]: match bindings cannot shadow tuple structs
--> $DIR/pat-tuple-overfield.rs:43:9
|
LL | struct Z1();
| ------------ the tuple struct `Z1` is defined here
...
LL | Z1 => {}
| ^^ cannot be named the same as a tuple struct
error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0`
--> $DIR/pat-tuple-overfield.rs:38:9
|
LL | struct Z0;
| ---------- `Z0` defined here
LL | struct Z1();
| ------------ similarly named tuple struct `Z1` defined here
...
LL | Z0() => {}
| ^^^^
|
help: use this syntax instead
|
LL | Z0 => {}
| ~~
help: a tuple struct with a similar name exists
|
LL | Z1() => {}
| ~~
error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0`
--> $DIR/pat-tuple-overfield.rs:39:9
|
LL | struct Z0;
| ---------- `Z0` defined here
LL | struct Z1();
| ------------ similarly named tuple struct `Z1` defined here
...
LL | Z0(_) => {}
| ^^^^^
|
help: use this syntax instead
|
LL | Z0 => {}
| ~~
help: a tuple struct with a similar name exists
|
LL | Z1(_) => {}
| ~~
error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0`
--> $DIR/pat-tuple-overfield.rs:40:9
|
LL | struct Z0;
| ---------- `Z0` defined here
LL | struct Z1();
| ------------ similarly named tuple struct `Z1` defined here
...
LL | Z0(_, _) => {}
| ^^^^^^^^
|
help: use this syntax instead
|
LL | Z0 => {}
| ~~
help: a tuple struct with a similar name exists
|
LL | Z1(_, _) => {}
| ~~
error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0`
--> $DIR/pat-tuple-overfield.rs:50:9
|
LL | Z0,
| -- `E1::Z0` defined here
LL | Z1(),
| ---- similarly named tuple variant `Z1` defined here
...
LL | E1::Z0() => {}
| ^^^^^^^^
|
help: use this syntax instead
|
LL | E1::Z0 => {}
| ~~~~~~
help: a tuple variant with a similar name exists
|
LL | E1::Z1() => {}
| ~~
error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0`
--> $DIR/pat-tuple-overfield.rs:51:9
|
LL | Z0,
| -- `E1::Z0` defined here
LL | Z1(),
| ---- similarly named tuple variant `Z1` defined here
...
LL | E1::Z0(_) => {}
| ^^^^^^^^^
|
help: use this syntax instead
|
LL | E1::Z0 => {}
| ~~~~~~
help: a tuple variant with a similar name exists
|
LL | E1::Z1(_) => {}
| ~~
error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0`
--> $DIR/pat-tuple-overfield.rs:52:9
|
LL | Z0,
| -- `E1::Z0` defined here
LL | Z1(),
| ---- similarly named tuple variant `Z1` defined here
...
LL | E1::Z0(_, _) => {}
| ^^^^^^^^^^^^
|
help: use this syntax instead
|
LL | E1::Z0 => {}
| ~~~~~~
help: a tuple variant with a similar name exists
|
LL | E1::Z1(_, _) => {}
| ~~
error[E0532]: expected unit struct, unit variant or constant, found tuple variant `E1::Z1`
--> $DIR/pat-tuple-overfield.rs:55:9
|
LL | Z0,
| -- similarly named unit variant `Z0` defined here
LL | Z1(),
| ---- `E1::Z1` defined here
...
LL | E1::Z1 => {}
| ^^^^^^
|
help: use the tuple variant pattern syntax instead
|
LL | E1::Z1() => {}
| ~~~~~~~~
help: a unit variant with a similar name exists
|
LL | E1::Z0 => {}
| ~~
error[E0308]: mismatched types
--> $DIR/pat-tuple-overfield.rs:5:9
--> $DIR/pat-tuple-overfield.rs:21:9
|
LL | match (1, 2, 3) {
| --------- this expression has type `({integer}, {integer}, {integer})`
@ -10,7 +159,7 @@ LL | (1, 2, 3, 4) => {}
found tuple `(_, _, _, _)`
error[E0308]: mismatched types
--> $DIR/pat-tuple-overfield.rs:6:9
--> $DIR/pat-tuple-overfield.rs:22:9
|
LL | match (1, 2, 3) {
| --------- this expression has type `({integer}, {integer}, {integer})`
@ -22,7 +171,7 @@ LL | (1, 2, .., 3, 4) => {}
found tuple `(_, _, _, _)`
error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields
--> $DIR/pat-tuple-overfield.rs:10:10
--> $DIR/pat-tuple-overfield.rs:26:10
|
LL | struct S(u8, u8, u8);
| --------------------- tuple struct defined here
@ -33,7 +182,7 @@ LL | S(1, 2, 3, 4) => {}
| this tuple struct
error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields
--> $DIR/pat-tuple-overfield.rs:12:10
--> $DIR/pat-tuple-overfield.rs:28:10
|
LL | struct S(u8, u8, u8);
| --------------------- tuple struct defined here
@ -43,7 +192,68 @@ LL | S(1, 2, .., 3, 4) => {}
| |
| this tuple struct
error: aborting due to 4 previous errors
error[E0023]: this pattern has 6 fields, but the corresponding tuple struct has 5 fields
--> $DIR/pat-tuple-overfield.rs:33:10
|
LL | / struct M(
LL | | u8,
LL | | u8,
LL | | u8,
LL | | u8,
LL | | u8,
LL | | );
| |__- tuple struct defined here
...
LL | M(1, 2, 3, 4, 5, 6) => {}
| -^^^^^^^^^^^^^^^^^^ expected 5 fields, found 6
| |
| this tuple struct
Some errors have detailed explanations: E0023, E0308.
error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 0 fields
--> $DIR/pat-tuple-overfield.rs:45:11
|
LL | struct Z1();
| ------------ tuple struct defined here
...
LL | Z1(_) => {}
| --^^^ expected 0 fields, found 1
| |
| this tuple struct
error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 0 fields
--> $DIR/pat-tuple-overfield.rs:46:11
|
LL | struct Z1();
| ------------ tuple struct defined here
...
LL | Z1(_, _) => {}
| --^^^^^^ expected 0 fields, found 2
| |
| this tuple struct
error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 0 fields
--> $DIR/pat-tuple-overfield.rs:57:15
|
LL | Z1(),
| ---- tuple variant defined here
...
LL | E1::Z1(_) => {}
| ------^^^ expected 0 fields, found 1
| |
| this tuple variant
error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 0 fields
--> $DIR/pat-tuple-overfield.rs:58:15
|
LL | Z1(),
| ---- tuple variant defined here
...
LL | E1::Z1(_, _) => {}
| ------^^^^^^ expected 0 fields, found 2
| |
| this tuple variant
error: aborting due to 17 previous errors
Some errors have detailed explanations: E0023, E0308, E0530, E0532.
For more information about an error, try `rustc --explain E0023`.