Skip to content

Commit 6509db8

Browse files
committed
or_patterns: harden bindings test
1 parent c9290dc commit 6509db8

File tree

2 files changed

+245
-7
lines changed

2 files changed

+245
-7
lines changed
Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,68 @@
1-
enum Blah { A(isize, isize, usize), B(isize, isize) }
1+
// Here we test type checking of bindings when combined with or-patterns.
2+
// Specifically, we ensure that introducing bindings of different types result in type errors.
23

3-
fn main() { match Blah::A(1, 1, 2) { Blah::A(_, x, y) | Blah::B(x, y) => { } } }
4-
//~^ ERROR mismatched types
4+
#![feature(or_patterns)]
5+
6+
fn main() {
7+
enum Blah {
8+
A(isize, isize, usize),
9+
B(isize, isize),
10+
}
11+
12+
match Blah::A(1, 1, 2) {
13+
Blah::A(_, x, y) | Blah::B(x, y) => {} //~ ERROR mismatched types
14+
}
15+
16+
match Some(Blah::A(1, 1, 2)) {
17+
Some(Blah::A(_, x, y) | Blah::B(x, y)) => {} //~ ERROR mismatched types
18+
}
19+
20+
match (0u8, 1u16) {
21+
(x, y) | (y, x) => {} //~ ERROR mismatched types
22+
//~^ ERROR mismatched types
23+
}
24+
25+
match Some((0u8, Some((1u16, 2u32)))) {
26+
Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) => {}
27+
//~^ ERROR mismatched types
28+
//~| ERROR mismatched types
29+
//~| ERROR mismatched types
30+
//~| ERROR mismatched types
31+
_ => {}
32+
}
33+
34+
if let Blah::A(_, x, y) | Blah::B(x, y) = Blah::A(1, 1, 2) {
35+
//~^ ERROR mismatched types
36+
}
37+
38+
if let Some(Blah::A(_, x, y) | Blah::B(x, y)) = Some(Blah::A(1, 1, 2)) {
39+
//~^ ERROR mismatched types
40+
}
41+
42+
if let (x, y) | (y, x) = (0u8, 1u16) {
43+
//~^ ERROR mismatched types
44+
//~| ERROR mismatched types
45+
}
46+
47+
if let Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x))))
48+
//~^ ERROR mismatched types
49+
//~| ERROR mismatched types
50+
//~| ERROR mismatched types
51+
//~| ERROR mismatched types
52+
= Some((0u8, Some((1u16, 2u32))))
53+
{}
54+
55+
let Blah::A(_, x, y) | Blah::B(x, y) = Blah::A(1, 1, 2);
56+
//~^ ERROR mismatched types
57+
58+
let (x, y) | (y, x) = (0u8, 1u16);
59+
//~^ ERROR mismatched types
60+
//~| ERROR mismatched types
61+
62+
fn f1((Blah::A(_, x, y) | Blah::B(x, y)): Blah) {}
63+
//~^ ERROR mismatched types
64+
65+
fn f2(((x, y) | (y, x)): (u8, u16)) {}
66+
//~^ ERROR mismatched types
67+
//~| ERROR mismatched types
68+
}
Lines changed: 178 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,183 @@
11
error[E0308]: mismatched types
2-
--> $DIR/or-pattern-mismatch.rs:3:68
2+
--> $DIR/or-pattern-mismatch.rs:13:39
33
|
4-
LL | fn main() { match Blah::A(1, 1, 2) { Blah::A(_, x, y) | Blah::B(x, y) => { } } }
5-
| ---------------- this expression has type `Blah` ^ expected `usize`, found `isize`
4+
LL | match Blah::A(1, 1, 2) {
5+
| ---------------- this expression has type `main::Blah`
6+
LL | Blah::A(_, x, y) | Blah::B(x, y) => {}
7+
| ^ expected `usize`, found `isize`
68

7-
error: aborting due to previous error
9+
error[E0308]: mismatched types
10+
--> $DIR/or-pattern-mismatch.rs:17:44
11+
|
12+
LL | match Some(Blah::A(1, 1, 2)) {
13+
| ---------------------- this expression has type `std::option::Option<main::Blah>`
14+
LL | Some(Blah::A(_, x, y) | Blah::B(x, y)) => {}
15+
| ^ expected `usize`, found `isize`
16+
17+
error[E0308]: mismatched types
18+
--> $DIR/or-pattern-mismatch.rs:21:19
19+
|
20+
LL | match (0u8, 1u16) {
21+
| ----------- this expression has type `(u8, u16)`
22+
LL | (x, y) | (y, x) => {}
23+
| ^ expected `u16`, found `u8`
24+
25+
error[E0308]: mismatched types
26+
--> $DIR/or-pattern-mismatch.rs:21:22
27+
|
28+
LL | match (0u8, 1u16) {
29+
| ----------- this expression has type `(u8, u16)`
30+
LL | (x, y) | (y, x) => {}
31+
| ^ expected `u8`, found `u16`
32+
33+
error[E0308]: mismatched types
34+
--> $DIR/or-pattern-mismatch.rs:26:41
35+
|
36+
LL | match Some((0u8, Some((1u16, 2u32)))) {
37+
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
38+
LL | Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) => {}
39+
| ^ expected `u16`, found `u8`
40+
41+
error[E0308]: mismatched types
42+
--> $DIR/or-pattern-mismatch.rs:26:50
43+
|
44+
LL | match Some((0u8, Some((1u16, 2u32)))) {
45+
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
46+
LL | Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) => {}
47+
| ^ expected `u8`, found `u16`
48+
49+
error[E0308]: mismatched types
50+
--> $DIR/or-pattern-mismatch.rs:26:59
51+
|
52+
LL | match Some((0u8, Some((1u16, 2u32)))) {
53+
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
54+
LL | Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) => {}
55+
| ^ expected `u32`, found `u16`
56+
57+
error[E0308]: mismatched types
58+
--> $DIR/or-pattern-mismatch.rs:26:62
59+
|
60+
LL | match Some((0u8, Some((1u16, 2u32)))) {
61+
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
62+
LL | Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) => {}
63+
| ^ expected `u8`, found `u32`
64+
65+
error[E0308]: mismatched types
66+
--> $DIR/or-pattern-mismatch.rs:34:42
67+
|
68+
LL | if let Blah::A(_, x, y) | Blah::B(x, y) = Blah::A(1, 1, 2) {
69+
| ^ ---------------- this expression has type `main::Blah`
70+
| |
71+
| expected `usize`, found `isize`
72+
73+
error[E0308]: mismatched types
74+
--> $DIR/or-pattern-mismatch.rs:38:47
75+
|
76+
LL | if let Some(Blah::A(_, x, y) | Blah::B(x, y)) = Some(Blah::A(1, 1, 2)) {
77+
| ^ ---------------------- this expression has type `std::option::Option<main::Blah>`
78+
| |
79+
| expected `usize`, found `isize`
80+
81+
error[E0308]: mismatched types
82+
--> $DIR/or-pattern-mismatch.rs:42:22
83+
|
84+
LL | if let (x, y) | (y, x) = (0u8, 1u16) {
85+
| ^ ----------- this expression has type `(u8, u16)`
86+
| |
87+
| expected `u16`, found `u8`
88+
89+
error[E0308]: mismatched types
90+
--> $DIR/or-pattern-mismatch.rs:42:25
91+
|
92+
LL | if let (x, y) | (y, x) = (0u8, 1u16) {
93+
| ^ ----------- this expression has type `(u8, u16)`
94+
| |
95+
| expected `u8`, found `u16`
96+
97+
error[E0308]: mismatched types
98+
--> $DIR/or-pattern-mismatch.rs:47:44
99+
|
100+
LL | if let Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x))))
101+
| ^ expected `u16`, found `u8`
102+
...
103+
LL | = Some((0u8, Some((1u16, 2u32))))
104+
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
105+
106+
error[E0308]: mismatched types
107+
--> $DIR/or-pattern-mismatch.rs:47:53
108+
|
109+
LL | if let Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x))))
110+
| ^ expected `u8`, found `u16`
111+
...
112+
LL | = Some((0u8, Some((1u16, 2u32))))
113+
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
114+
115+
error[E0308]: mismatched types
116+
--> $DIR/or-pattern-mismatch.rs:47:62
117+
|
118+
LL | if let Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x))))
119+
| ^ expected `u32`, found `u16`
120+
...
121+
LL | = Some((0u8, Some((1u16, 2u32))))
122+
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
123+
124+
error[E0308]: mismatched types
125+
--> $DIR/or-pattern-mismatch.rs:47:65
126+
|
127+
LL | if let Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x))))
128+
| ^ expected `u8`, found `u32`
129+
...
130+
LL | = Some((0u8, Some((1u16, 2u32))))
131+
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
132+
133+
error[E0308]: mismatched types
134+
--> $DIR/or-pattern-mismatch.rs:55:39
135+
|
136+
LL | let Blah::A(_, x, y) | Blah::B(x, y) = Blah::A(1, 1, 2);
137+
| ^ ---------------- this expression has type `main::Blah`
138+
| |
139+
| expected `usize`, found `isize`
140+
141+
error[E0308]: mismatched types
142+
--> $DIR/or-pattern-mismatch.rs:58:19
143+
|
144+
LL | let (x, y) | (y, x) = (0u8, 1u16);
145+
| ^ ----------- this expression has type `(u8, u16)`
146+
| |
147+
| expected `u16`, found `u8`
148+
149+
error[E0308]: mismatched types
150+
--> $DIR/or-pattern-mismatch.rs:58:22
151+
|
152+
LL | let (x, y) | (y, x) = (0u8, 1u16);
153+
| ^ ----------- this expression has type `(u8, u16)`
154+
| |
155+
| expected `u8`, found `u16`
156+
157+
error[E0308]: mismatched types
158+
--> $DIR/or-pattern-mismatch.rs:62:42
159+
|
160+
LL | fn f1((Blah::A(_, x, y) | Blah::B(x, y)): Blah) {}
161+
| ^ ---- expected due to this
162+
| |
163+
| expected `usize`, found `isize`
164+
165+
error[E0308]: mismatched types
166+
--> $DIR/or-pattern-mismatch.rs:65:22
167+
|
168+
LL | fn f2(((x, y) | (y, x)): (u8, u16)) {}
169+
| ^ --------- expected due to this
170+
| |
171+
| expected `u16`, found `u8`
172+
173+
error[E0308]: mismatched types
174+
--> $DIR/or-pattern-mismatch.rs:65:25
175+
|
176+
LL | fn f2(((x, y) | (y, x)): (u8, u16)) {}
177+
| ^ --------- expected due to this
178+
| |
179+
| expected `u8`, found `u16`
180+
181+
error: aborting due to 22 previous errors
8182

9183
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)