Skip to content

Commit 08ceac8

Browse files
committed
Add cross-crate tuple field count error test
1 parent 02ed23c commit 08ceac8

File tree

3 files changed

+613
-0
lines changed

3 files changed

+613
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
pub struct Z0;
2+
pub struct Z1();
3+
4+
pub struct S(pub u8, pub u8, pub u8);
5+
pub struct M(
6+
pub u8,
7+
pub u8,
8+
pub u8,
9+
);
10+
11+
pub enum E1 { Z0, Z1(), S(u8, u8, u8) }
12+
13+
pub enum E2 {
14+
S(u8, u8, u8),
15+
M(
16+
u8,
17+
u8,
18+
u8,
19+
),
20+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// aux-build:declarations-for-tuple-field-count-errors.rs
2+
3+
extern crate declarations_for_tuple_field_count_errors;
4+
5+
use declarations_for_tuple_field_count_errors::*;
6+
7+
fn main() {
8+
match Z0 {
9+
Z0() => {} //~ ERROR expected tuple struct or tuple variant, found unit struct `Z0`
10+
Z0(x) => {} //~ ERROR expected tuple struct or tuple variant, found unit struct `Z0`
11+
}
12+
match Z1() {
13+
Z1 => {} //~ ERROR match bindings cannot shadow tuple structs
14+
Z1(x) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple struct has 0 fields
15+
}
16+
17+
match S(1, 2, 3) {
18+
S() => {} //~ ERROR this pattern has 0 fields, but the corresponding tuple struct has 3 fields
19+
S(1) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple struct has 3 fields
20+
S(xyz, abc) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple struct has 3 fields
21+
S(1, 2, 3, 4) => {} //~ ERROR this pattern has 4 fields, but the corresponding tuple struct has 3 fields
22+
}
23+
match M(1, 2, 3) {
24+
M() => {} //~ ERROR this pattern has 0 fields, but the corresponding tuple struct has 3 fields
25+
M(1) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple struct has 3 fields
26+
M(xyz, abc) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple struct has 3 fields
27+
M(1, 2, 3, 4) => {} //~ ERROR this pattern has 4 fields, but the corresponding tuple struct has 3 fields
28+
}
29+
30+
match E1::Z0 {
31+
E1::Z0() => {} //~ ERROR expected tuple struct or tuple variant, found unit variant `E1::Z0`
32+
E1::Z0(x) => {} //~ ERROR expected tuple struct or tuple variant, found unit variant `E1::Z0`
33+
}
34+
match E1::Z1() {
35+
E1::Z1 => {} //~ ERROR expected unit struct, unit variant or constant, found tuple variant `E1::Z1`
36+
E1::Z1(x) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple variant has 0 fields
37+
}
38+
match E1::S(1, 2, 3) {
39+
E1::S() => {} //~ ERROR this pattern has 0 fields, but the corresponding tuple variant has 3 fields
40+
E1::S(1) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple variant has 3 fields
41+
E1::S(xyz, abc) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple variant has 3 fields
42+
E1::S(1, 2, 3, 4) => {} //~ ERROR this pattern has 4 fields, but the corresponding tuple variant has 3 fields
43+
}
44+
45+
match E2::S(1, 2, 3) {
46+
E2::S() => {} //~ ERROR this pattern has 0 fields, but the corresponding tuple variant has 3 fields
47+
E2::S(1) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple variant has 3 fields
48+
E2::S(xyz, abc) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple variant has 3 fields
49+
E2::S(1, 2, 3, 4) => {} //~ ERROR this pattern has 4 fields, but the corresponding tuple variant has 3 fields
50+
}
51+
match E2::M(1, 2, 3) {
52+
E2::M() => {} //~ ERROR this pattern has 0 fields, but the corresponding tuple variant has 3 fields
53+
E2::M(1) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple variant has 3 fields
54+
E2::M(xyz, abc) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple variant has 3 fields
55+
E2::M(1, 2, 3, 4) => {} //~ ERROR this pattern has 4 fields, but the corresponding tuple variant has 3 fields
56+
}
57+
}

0 commit comments

Comments
 (0)