]> git.lizzy.rs Git - rust.git/blob - src/test/ui/or-patterns/already-bound-name.rs
Auto merge of #82624 - ojeda:rwlock-example-deadlock, r=JohnTitor
[rust.git] / src / test / ui / or-patterns / already-bound-name.rs
1 // This test ensures that the "already bound identifier in a product pattern"
2 // correctly accounts for or-patterns.
3
4 enum E<T> { A(T, T), B(T) }
5
6 use E::*;
7
8 fn main() {
9     let (a, a) = (0, 1); // Standard duplication without an or-pattern.
10     //~^ ERROR identifier `a` is bound more than once in the same pattern
11
12     let (a, A(a, _) | B(a)) = (0, A(1, 2));
13     //~^ ERROR identifier `a` is bound more than once in the same pattern
14     //~| ERROR identifier `a` is bound more than once in the same pattern
15
16     let (A(a, _) | B(a), a) = (A(0, 1), 2);
17     //~^ ERROR identifier `a` is bound more than once in the same pattern
18
19     let (A(a, a) | B(a)) = A(0, 1);
20     //~^ ERROR identifier `a` is bound more than once in the same pattern
21
22     let (B(a) | A(a, a)) = A(0, 1);
23     //~^ ERROR identifier `a` is bound more than once in the same pattern
24
25     match A(0, 1) {
26         B(a) | A(a, a) => {} // Let's ensure `match` has no funny business.
27         //~^ ERROR identifier `a` is bound more than once in the same pattern
28     }
29
30     let (B(A(a, _) | B(a)) | A(a, A(a, _) | B(a))) = B(B(1));
31     //~^ ERROR identifier `a` is bound more than once in the same pattern
32     //~| ERROR identifier `a` is bound more than once in the same pattern
33     //~| ERROR mismatched types
34
35     let (B(_) | A(A(a, _) | B(a), A(a, _) | B(a))) = B(B(1));
36     //~^ ERROR identifier `a` is bound more than once in the same pattern
37     //~| ERROR identifier `a` is bound more than once in the same pattern
38     //~| ERROR variable `a` is not bound in all patterns
39
40     let (B(A(a, _) | B(a)) | A(A(a, _) | B(a), A(a, _) | B(a))) = B(B(1));
41     //~^ ERROR identifier `a` is bound more than once in the same pattern
42     //~| ERROR identifier `a` is bound more than once in the same pattern
43 }