]> git.proxmox.com Git - rustc.git/blob - src/test/ui/or-patterns/or-patterns-binding-type-mismatch.rs
New upstream version 1.53.0+dfsg1
[rustc.git] / src / test / ui / or-patterns / or-patterns-binding-type-mismatch.rs
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.
3
4 fn main() {
5 enum Blah {
6 A(isize, isize, usize),
7 B(isize, isize),
8 }
9
10 match Blah::A(1, 1, 2) {
11 Blah::A(_, x, y) | Blah::B(x, y) => {} //~ ERROR mismatched types
12 }
13
14 match Some(Blah::A(1, 1, 2)) {
15 Some(Blah::A(_, x, y) | Blah::B(x, y)) => {} //~ ERROR mismatched types
16 }
17
18 match (0u8, 1u16) {
19 (x, y) | (y, x) => {} //~ ERROR mismatched types
20 //~^ ERROR mismatched types
21 }
22
23 match Some((0u8, Some((1u16, 2u32)))) {
24 Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) => {}
25 //~^ ERROR mismatched types
26 //~| ERROR mismatched types
27 //~| ERROR mismatched types
28 //~| ERROR mismatched types
29 _ => {}
30 }
31
32 if let Blah::A(_, x, y) | Blah::B(x, y) = Blah::A(1, 1, 2) {
33 //~^ ERROR mismatched types
34 }
35
36 if let Some(Blah::A(_, x, y) | Blah::B(x, y)) = Some(Blah::A(1, 1, 2)) {
37 //~^ ERROR mismatched types
38 }
39
40 if let (x, y) | (y, x) = (0u8, 1u16) {
41 //~^ ERROR mismatched types
42 //~| ERROR mismatched types
43 }
44
45 if let Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x))))
46 //~^ ERROR mismatched types
47 //~| ERROR mismatched types
48 //~| ERROR mismatched types
49 //~| ERROR mismatched types
50 = Some((0u8, Some((1u16, 2u32))))
51 {}
52
53 let (Blah::A(_, x, y) | Blah::B(x, y)) = Blah::A(1, 1, 2);
54 //~^ ERROR mismatched types
55
56 let ((x, y) | (y, x)) = (0u8, 1u16);
57 //~^ ERROR mismatched types
58 //~| ERROR mismatched types
59
60 fn f1((Blah::A(_, x, y) | Blah::B(x, y)): Blah) {}
61 //~^ ERROR mismatched types
62
63 fn f2(((x, y) | (y, x)): (u8, u16)) {}
64 //~^ ERROR mismatched types
65 //~| ERROR mismatched types
66 }