Skip to content

Commit 33317c7

Browse files
committed
resolve: add test for missing bindings in or-patterns.
1 parent 896a1c7 commit 33317c7

File tree

2 files changed

+324
-0
lines changed

2 files changed

+324
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// This test ensures that or patterns do not allow missing bindings in any of the arms.
2+
3+
// edition:2018
4+
5+
#![feature(or_patterns)]
6+
#![allow(incomplete_features, non_camel_case_types)]
7+
8+
fn main() {}
9+
10+
fn check_handling_of_paths() {
11+
mod bar {
12+
pub enum foo {
13+
alpha,
14+
beta,
15+
charlie
16+
}
17+
}
18+
19+
use bar::foo::{alpha, charlie};
20+
let alpha | beta | charlie = alpha; //~ ERROR variable `beta` is not bound in all patterns
21+
match Some(alpha) {
22+
Some(alpha | beta) => {} //~ ERROR variable `beta` is not bound in all patterns
23+
}
24+
}
25+
26+
fn check_misc_nesting() {
27+
enum E<T> { A(T, T), B(T) }
28+
use E::*;
29+
enum Vars3<S, T, U> { V1(S), V2(T), V3(U) }
30+
use Vars3::*;
31+
32+
// One level:
33+
const X: E<u8> = B(0);
34+
let A(a, _) | _ = X; //~ ERROR variable `a` is not bound in all patterns
35+
let _ | B(a) = X; //~ ERROR variable `a` is not bound in all patterns
36+
let A(..) | B(a) = X; //~ ERROR variable `a` is not bound in all patterns
37+
let A(a, _) | B(_) = X; //~ ERROR variable `a` is not bound in all patterns
38+
let A(_, a) | B(_) = X; //~ ERROR variable `a` is not bound in all patterns
39+
let A(a, b) | B(a) = X; //~ ERROR variable `b` is not bound in all patterns
40+
41+
// Two levels:
42+
const Y: E<E<u8>> = B(B(0));
43+
let A(A(..) | B(_), _) | B(a) = Y; //~ ERROR variable `a` is not bound in all patterns
44+
let A(A(..) | B(a), _) | B(A(a, _) | B(a)) = Y;
45+
//~^ ERROR variable `a` is not bound in all patterns
46+
let A(A(a, b) | B(c), d) | B(e) = Y;
47+
//~^ ERROR variable `a` is not bound in all patterns
48+
//~| ERROR variable `a` is not bound in all patterns
49+
//~| ERROR variable `b` is not bound in all patterns
50+
//~| ERROR variable `b` is not bound in all patterns
51+
//~| ERROR variable `c` is not bound in all patterns
52+
//~| ERROR variable `c` is not bound in all patterns
53+
//~| ERROR variable `d` is not bound in all patterns
54+
//~| ERROR variable `e` is not bound in all patterns
55+
56+
// Three levels:
57+
let (
58+
V1(
59+
//~^ ERROR variable `b` is not bound in all patterns
60+
//~| ERROR variable `c` is not bound in all patterns
61+
A(
62+
Ok(a) | Err(_), //~ ERROR variable `a` is not bound in all patterns
63+
_
64+
) |
65+
B(Ok(a) | Err(a))
66+
) |
67+
V2(
68+
A(
69+
A(_, a) | //~ ERROR variable `b` is not bound in all patterns
70+
B(b), //~ ERROR variable `a` is not bound in all patterns
71+
_
72+
) |
73+
B(_)
74+
//~^ ERROR variable `a` is not bound in all patterns
75+
//~| ERROR variable `b` is not bound in all patterns
76+
) |
77+
V3(c),
78+
//~^ ERROR variable `a` is not bound in all patterns
79+
)
80+
: (Vars3<E<Result<u8, u8>>, E<E<u8>>, u8>,)
81+
= (V3(0),);
82+
}
Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
error[E0408]: variable `beta` is not bound in all patterns
2+
--> $DIR/missing-bindings.rs:20:9
3+
|
4+
LL | let alpha | beta | charlie = alpha;
5+
| ^^^^^ ---- ^^^^^^^ pattern doesn't bind `beta`
6+
| | |
7+
| | variable not in all patterns
8+
| pattern doesn't bind `beta`
9+
10+
error[E0408]: variable `beta` is not bound in all patterns
11+
--> $DIR/missing-bindings.rs:22:14
12+
|
13+
LL | Some(alpha | beta) => {}
14+
| ^^^^^ ---- variable not in all patterns
15+
| |
16+
| pattern doesn't bind `beta`
17+
18+
error[E0408]: variable `a` is not bound in all patterns
19+
--> $DIR/missing-bindings.rs:34:19
20+
|
21+
LL | let A(a, _) | _ = X;
22+
| - ^ pattern doesn't bind `a`
23+
| |
24+
| variable not in all patterns
25+
26+
error[E0408]: variable `a` is not bound in all patterns
27+
--> $DIR/missing-bindings.rs:35:9
28+
|
29+
LL | let _ | B(a) = X;
30+
| ^ - variable not in all patterns
31+
| |
32+
| pattern doesn't bind `a`
33+
34+
error[E0408]: variable `a` is not bound in all patterns
35+
--> $DIR/missing-bindings.rs:36:9
36+
|
37+
LL | let A(..) | B(a) = X;
38+
| ^^^^^ - variable not in all patterns
39+
| |
40+
| pattern doesn't bind `a`
41+
42+
error[E0408]: variable `a` is not bound in all patterns
43+
--> $DIR/missing-bindings.rs:37:19
44+
|
45+
LL | let A(a, _) | B(_) = X;
46+
| - ^^^^ pattern doesn't bind `a`
47+
| |
48+
| variable not in all patterns
49+
50+
error[E0408]: variable `a` is not bound in all patterns
51+
--> $DIR/missing-bindings.rs:38:19
52+
|
53+
LL | let A(_, a) | B(_) = X;
54+
| - ^^^^ pattern doesn't bind `a`
55+
| |
56+
| variable not in all patterns
57+
58+
error[E0408]: variable `b` is not bound in all patterns
59+
--> $DIR/missing-bindings.rs:39:19
60+
|
61+
LL | let A(a, b) | B(a) = X;
62+
| - ^^^^ pattern doesn't bind `b`
63+
| |
64+
| variable not in all patterns
65+
66+
error[E0408]: variable `a` is not bound in all patterns
67+
--> $DIR/missing-bindings.rs:43:9
68+
|
69+
LL | let A(A(..) | B(_), _) | B(a) = Y;
70+
| ^^^^^^^^^^^^^^^^^^ - variable not in all patterns
71+
| |
72+
| pattern doesn't bind `a`
73+
74+
error[E0408]: variable `a` is not bound in all patterns
75+
--> $DIR/missing-bindings.rs:44:11
76+
|
77+
LL | let A(A(..) | B(a), _) | B(A(a, _) | B(a)) = Y;
78+
| ^^^^^ - variable not in all patterns
79+
| |
80+
| pattern doesn't bind `a`
81+
82+
error[E0408]: variable `a` is not bound in all patterns
83+
--> $DIR/missing-bindings.rs:46:21
84+
|
85+
LL | let A(A(a, b) | B(c), d) | B(e) = Y;
86+
| - ^^^^ pattern doesn't bind `a`
87+
| |
88+
| variable not in all patterns
89+
90+
error[E0408]: variable `b` is not bound in all patterns
91+
--> $DIR/missing-bindings.rs:46:21
92+
|
93+
LL | let A(A(a, b) | B(c), d) | B(e) = Y;
94+
| - ^^^^ pattern doesn't bind `b`
95+
| |
96+
| variable not in all patterns
97+
98+
error[E0408]: variable `c` is not bound in all patterns
99+
--> $DIR/missing-bindings.rs:46:11
100+
|
101+
LL | let A(A(a, b) | B(c), d) | B(e) = Y;
102+
| ^^^^^^^ - variable not in all patterns
103+
| |
104+
| pattern doesn't bind `c`
105+
106+
error[E0408]: variable `a` is not bound in all patterns
107+
--> $DIR/missing-bindings.rs:46:32
108+
|
109+
LL | let A(A(a, b) | B(c), d) | B(e) = Y;
110+
| - ^^^^ pattern doesn't bind `a`
111+
| |
112+
| variable not in all patterns
113+
114+
error[E0408]: variable `b` is not bound in all patterns
115+
--> $DIR/missing-bindings.rs:46:32
116+
|
117+
LL | let A(A(a, b) | B(c), d) | B(e) = Y;
118+
| - ^^^^ pattern doesn't bind `b`
119+
| |
120+
| variable not in all patterns
121+
122+
error[E0408]: variable `c` is not bound in all patterns
123+
--> $DIR/missing-bindings.rs:46:32
124+
|
125+
LL | let A(A(a, b) | B(c), d) | B(e) = Y;
126+
| - ^^^^ pattern doesn't bind `c`
127+
| |
128+
| variable not in all patterns
129+
130+
error[E0408]: variable `d` is not bound in all patterns
131+
--> $DIR/missing-bindings.rs:46:32
132+
|
133+
LL | let A(A(a, b) | B(c), d) | B(e) = Y;
134+
| - ^^^^ pattern doesn't bind `d`
135+
| |
136+
| variable not in all patterns
137+
138+
error[E0408]: variable `e` is not bound in all patterns
139+
--> $DIR/missing-bindings.rs:46:9
140+
|
141+
LL | let A(A(a, b) | B(c), d) | B(e) = Y;
142+
| ^^^^^^^^^^^^^^^^^^^^ - variable not in all patterns
143+
| |
144+
| pattern doesn't bind `e`
145+
146+
error[E0408]: variable `a` is not bound in all patterns
147+
--> $DIR/missing-bindings.rs:62:29
148+
|
149+
LL | Ok(a) | Err(_),
150+
| - ^^^^^^ pattern doesn't bind `a`
151+
| |
152+
| variable not in all patterns
153+
154+
error[E0408]: variable `a` is not bound in all patterns
155+
--> $DIR/missing-bindings.rs:70:21
156+
|
157+
LL | A(_, a) |
158+
| - variable not in all patterns
159+
LL | B(b),
160+
| ^^^^ pattern doesn't bind `a`
161+
162+
error[E0408]: variable `b` is not bound in all patterns
163+
--> $DIR/missing-bindings.rs:69:21
164+
|
165+
LL | A(_, a) |
166+
| ^^^^^^^ pattern doesn't bind `b`
167+
LL | B(b),
168+
| - variable not in all patterns
169+
170+
error[E0408]: variable `a` is not bound in all patterns
171+
--> $DIR/missing-bindings.rs:73:17
172+
|
173+
LL | A(_, a) |
174+
| - variable not in all patterns
175+
...
176+
LL | B(_)
177+
| ^^^^ pattern doesn't bind `a`
178+
179+
error[E0408]: variable `b` is not bound in all patterns
180+
--> $DIR/missing-bindings.rs:73:17
181+
|
182+
LL | B(b),
183+
| - variable not in all patterns
184+
...
185+
LL | B(_)
186+
| ^^^^ pattern doesn't bind `b`
187+
188+
error[E0408]: variable `a` is not bound in all patterns
189+
--> $DIR/missing-bindings.rs:77:13
190+
|
191+
LL | B(Ok(a) | Err(a))
192+
| - variable not in all patterns
193+
...
194+
LL | A(_, a) |
195+
| - variable not in all patterns
196+
...
197+
LL | V3(c),
198+
| ^^^^^ pattern doesn't bind `a`
199+
200+
error[E0408]: variable `b` is not bound in all patterns
201+
--> $DIR/missing-bindings.rs:58:13
202+
|
203+
LL | / V1(
204+
LL | |
205+
LL | |
206+
LL | | A(
207+
... |
208+
LL | | B(Ok(a) | Err(a))
209+
LL | | ) |
210+
| |_____________^ pattern doesn't bind `b`
211+
...
212+
LL | B(b),
213+
| - variable not in all patterns
214+
...
215+
LL | V3(c),
216+
| ^^^^^ pattern doesn't bind `b`
217+
218+
error[E0408]: variable `c` is not bound in all patterns
219+
--> $DIR/missing-bindings.rs:58:13
220+
|
221+
LL | / V1(
222+
LL | |
223+
LL | |
224+
LL | | A(
225+
... |
226+
LL | | B(Ok(a) | Err(a))
227+
LL | | ) |
228+
| |_____________^ pattern doesn't bind `c`
229+
LL | / V2(
230+
LL | | A(
231+
LL | | A(_, a) |
232+
LL | | B(b),
233+
... |
234+
LL | |
235+
LL | | ) |
236+
| |_____________^ pattern doesn't bind `c`
237+
LL | V3(c),
238+
| - variable not in all patterns
239+
240+
error: aborting due to 26 previous errors
241+
242+
For more information about this error, try `rustc --explain E0408`.

0 commit comments

Comments
 (0)