]> git.lizzy.rs Git - rust.git/blob - src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs
512f1e283cb462a0cff4ace899421714bd4c4d4d
[rust.git] / src / test / ui / or-patterns / exhaustiveness-unreachable-pattern.rs
1 #![feature(or_patterns)]
2 #![deny(unreachable_patterns)]
3
4 // We wrap patterns in a tuple because top-level or-patterns were special-cased.
5 fn main() {
6     match (0u8,) {
7         (1 | 2,) => {}
8         (1,) => {} //~ ERROR unreachable pattern
9         _ => {}
10     }
11     match (0u8,) {
12         (1 | 2,) => {}
13         (2,) => {} //~ ERROR unreachable pattern
14         _ => {}
15     }
16     match (0u8,) {
17         (1,) => {}
18         (2,) => {}
19         (1 | 2,) => {} //~ ERROR unreachable pattern
20         _ => {}
21     }
22     match (0u8, 0u8) {
23         (1 | 2, 3 | 4) => {}
24         (1, 3) => {}     //~ ERROR unreachable pattern
25         (1, 4) => {}     //~ ERROR unreachable pattern
26         (2, 4) => {}     //~ ERROR unreachable pattern
27         (2 | 1, 4) => {} //~ ERROR unreachable pattern
28         (1, 5 | 6) => {}
29         (1, 4 | 5) => {} //~ ERROR unreachable pattern
30         _ => {}
31     }
32     match (true, true) {
33         (false | true, false | true) => (),
34     }
35     match (Some(0u8),) {
36         (None | Some(1 | 2),) => {}
37         (Some(1),) => {} //~ ERROR unreachable pattern
38         (None,) => {}    //~ ERROR unreachable pattern
39         _ => {}
40     }
41     match ((0u8,),) {
42         ((1 | 2,) | (3 | 4,),) => {}
43         ((1..=4,),) => {} //~ ERROR unreachable pattern
44         _ => {}
45     }
46
47     match (0,) {
48         (1 | 1,) => {} //~ ERROR unreachable
49         _ => {}
50     }
51     match [0; 2] {
52         [0
53             | 0 //~ ERROR unreachable
54         , 0
55             | 0] => {} //~ ERROR unreachable
56         _ => {}
57     }
58     match &[][..] {
59         [0] => {}
60         [0, _] => {}
61         [0, _, _] => {}
62         [1, ..] => {}
63         [1 //~ ERROR unreachable
64             | 2, ..] => {}
65         _ => {}
66     }
67     match Some(0) {
68         Some(0) => {}
69         Some(0 //~ ERROR unreachable
70              | 1) => {}
71         _ => {}
72     }
73
74     // A subpattern that is only unreachable in one branch is overall reachable.
75     match (true, true) {
76         (true, true) => {}
77         (false | true, false | true) => {}
78     }
79     match (true, true) {
80         (true, true) => {}
81         (false, false) => {}
82         (false | true, false | true) => {}
83     }
84     // https://github.com/rust-lang/rust/issues/76836
85     match None {
86         Some(false) => {}
87         None | Some(true
88                 | false) => {} //~ ERROR unreachable
89     }
90
91     // A subpattern that is unreachable in all branches is overall unreachable.
92     match (true, true) {
93         (false, true) => {}
94         (true, true) => {}
95         (false | true, false
96             | true) => {} //~ ERROR unreachable
97     }
98     match (true, true) {
99         (true, false) => {}
100         (true, true) => {}
101         (false
102             | true, //~ ERROR unreachable
103             false | true) => {}
104     }
105 }