Skip to content

Commit 498ec59

Browse files
committed
resolve: add tests for already-bound check.
1 parent 166a558 commit 498ec59

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// This test ensures that the "already bound identifier in a product pattern"
2+
// correctly accounts for or-patterns.
3+
4+
#![allow(warnings)]
5+
#![feature(or_patterns)]
6+
7+
enum E<T> { A(T, T), B(T) }
8+
9+
use E::*;
10+
11+
fn main() {
12+
let (a, a) = (0, 1); // Standard duplication without an or-pattern.
13+
//~^ ERROR identifier `a` is bound more than once in the same pattern
14+
15+
let (a, A(a, _) | B(a)) = (0, A(1, 2));
16+
//~^ ERROR identifier `a` is bound more than once in the same pattern
17+
//~| ERROR identifier `a` is bound more than once in the same pattern
18+
19+
let (A(a, _) | B(a), a) = (A(0, 1), 2);
20+
//~^ ERROR identifier `a` is bound more than once in the same pattern
21+
22+
let A(a, a) | B(a) = A(0, 1);
23+
//~^ ERROR identifier `a` is bound more than once in the same pattern
24+
25+
let B(a) | A(a, a) = A(0, 1);
26+
//~^ ERROR identifier `a` is bound more than once in the same pattern
27+
28+
match A(0, 1) {
29+
B(a) | A(a, a) => {} // Let's ensure `match` has no funny business.
30+
//~^ ERROR identifier `a` is bound more than once in the same pattern
31+
}
32+
33+
let B(A(a, _) | B(a)) | A(a, A(a, _) | B(a)) = B(B(1));
34+
//~^ ERROR identifier `a` is bound more than once in the same pattern
35+
//~| ERROR identifier `a` is bound more than once in the same pattern
36+
//~| ERROR mismatched types
37+
38+
let B(_) | A(A(a, _) | B(a), A(a, _) | B(a)) = B(B(1));
39+
//~^ ERROR identifier `a` is bound more than once in the same pattern
40+
//~| ERROR identifier `a` is bound more than once in the same pattern
41+
42+
let B(A(a, _) | B(a)) | A(A(a, _) | B(a), A(a, _) | B(a)) = B(B(1));
43+
//~^ ERROR identifier `a` is bound more than once in the same pattern
44+
//~| ERROR identifier `a` is bound more than once in the same pattern
45+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
error[E0416]: identifier `a` is bound more than once in the same pattern
2+
--> $DIR/already-bound-name.rs:12:13
3+
|
4+
LL | let (a, a) = (0, 1); // Standard duplication without an or-pattern.
5+
| ^ used in a pattern more than once
6+
7+
error[E0416]: identifier `a` is bound more than once in the same pattern
8+
--> $DIR/already-bound-name.rs:15:15
9+
|
10+
LL | let (a, A(a, _) | B(a)) = (0, A(1, 2));
11+
| ^ used in a pattern more than once
12+
13+
error[E0416]: identifier `a` is bound more than once in the same pattern
14+
--> $DIR/already-bound-name.rs:15:25
15+
|
16+
LL | let (a, A(a, _) | B(a)) = (0, A(1, 2));
17+
| ^ used in a pattern more than once
18+
19+
error[E0416]: identifier `a` is bound more than once in the same pattern
20+
--> $DIR/already-bound-name.rs:19:26
21+
|
22+
LL | let (A(a, _) | B(a), a) = (A(0, 1), 2);
23+
| ^ used in a pattern more than once
24+
25+
error[E0416]: identifier `a` is bound more than once in the same pattern
26+
--> $DIR/already-bound-name.rs:22:14
27+
|
28+
LL | let A(a, a) | B(a) = A(0, 1);
29+
| ^ used in a pattern more than once
30+
31+
error[E0416]: identifier `a` is bound more than once in the same pattern
32+
--> $DIR/already-bound-name.rs:25:21
33+
|
34+
LL | let B(a) | A(a, a) = A(0, 1);
35+
| ^ used in a pattern more than once
36+
37+
error[E0416]: identifier `a` is bound more than once in the same pattern
38+
--> $DIR/already-bound-name.rs:29:21
39+
|
40+
LL | B(a) | A(a, a) => {} // Let's ensure `match` has no funny business.
41+
| ^ used in a pattern more than once
42+
43+
error[E0416]: identifier `a` is bound more than once in the same pattern
44+
--> $DIR/already-bound-name.rs:33:36
45+
|
46+
LL | let B(A(a, _) | B(a)) | A(a, A(a, _) | B(a)) = B(B(1));
47+
| ^ used in a pattern more than once
48+
49+
error[E0416]: identifier `a` is bound more than once in the same pattern
50+
--> $DIR/already-bound-name.rs:33:46
51+
|
52+
LL | let B(A(a, _) | B(a)) | A(a, A(a, _) | B(a)) = B(B(1));
53+
| ^ used in a pattern more than once
54+
55+
error[E0416]: identifier `a` is bound more than once in the same pattern
56+
--> $DIR/already-bound-name.rs:38:36
57+
|
58+
LL | let B(_) | A(A(a, _) | B(a), A(a, _) | B(a)) = B(B(1));
59+
| ^ used in a pattern more than once
60+
61+
error[E0416]: identifier `a` is bound more than once in the same pattern
62+
--> $DIR/already-bound-name.rs:38:46
63+
|
64+
LL | let B(_) | A(A(a, _) | B(a), A(a, _) | B(a)) = B(B(1));
65+
| ^ used in a pattern more than once
66+
67+
error[E0416]: identifier `a` is bound more than once in the same pattern
68+
--> $DIR/already-bound-name.rs:42:49
69+
|
70+
LL | let B(A(a, _) | B(a)) | A(A(a, _) | B(a), A(a, _) | B(a)) = B(B(1));
71+
| ^ used in a pattern more than once
72+
73+
error[E0416]: identifier `a` is bound more than once in the same pattern
74+
--> $DIR/already-bound-name.rs:42:59
75+
|
76+
LL | let B(A(a, _) | B(a)) | A(A(a, _) | B(a), A(a, _) | B(a)) = B(B(1));
77+
| ^ used in a pattern more than once
78+
79+
error[E0308]: mismatched types
80+
--> $DIR/already-bound-name.rs:33:31
81+
|
82+
LL | let B(A(a, _) | B(a)) | A(a, A(a, _) | B(a)) = B(B(1));
83+
| ^ expected integer, found enum `E`
84+
|
85+
= note: expected type `{integer}`
86+
found type `E<{integer}>`
87+
88+
error: aborting due to 14 previous errors
89+
90+
Some errors have detailed explanations: E0308, E0416.
91+
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)