]> git.proxmox.com Git - rustc.git/blame - src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs
Merge tag 'debian/1.52.1+dfsg1-1_exp2' into proxmox/buster
[rustc.git] / src / test / ui / or-patterns / exhaustiveness-unreachable-pattern.rs
CommitLineData
60c5eb7d 1#![feature(or_patterns)]
60c5eb7d
XL
2#![deny(unreachable_patterns)]
3
74b04a01 4// We wrap patterns in a tuple because top-level or-patterns were special-cased.
60c5eb7d 5fn main() {
60c5eb7d
XL
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) => {}
74b04a01
XL
24 (1, 3) => {} //~ ERROR unreachable pattern
25 (1, 4) => {} //~ ERROR unreachable pattern
26 (2, 4) => {} //~ ERROR unreachable pattern
60c5eb7d
XL
27 (2 | 1, 4) => {} //~ ERROR unreachable pattern
28 (1, 5 | 6) => {}
29 (1, 4 | 5) => {} //~ ERROR unreachable pattern
30 _ => {}
31 }
f035d41b
XL
32 match (true, true) {
33 (false | true, false | true) => (),
34 }
60c5eb7d
XL
35 match (Some(0u8),) {
36 (None | Some(1 | 2),) => {}
37 (Some(1),) => {} //~ ERROR unreachable pattern
74b04a01 38 (None,) => {} //~ ERROR unreachable pattern
60c5eb7d
XL
39 _ => {}
40 }
41 match ((0u8,),) {
74b04a01
XL
42 ((1 | 2,) | (3 | 4,),) => {}
43 ((1..=4,),) => {} //~ ERROR unreachable pattern
44 _ => {}
60c5eb7d
XL
45 }
46
47 match (0,) {
74b04a01 48 (1 | 1,) => {} //~ ERROR unreachable
60c5eb7d
XL
49 _ => {}
50 }
6a06907d
XL
51 match 0 {
52 (0 | 1) | 1 => {} //~ ERROR unreachable
53 _ => {}
54 }
55 match 0 {
56 // We get two errors because recursive or-pattern expansion means we don't notice the two
57 // errors span a whole pattern. This could be better but doesn't matter much
58 0 | (0 | 0) => {}
59 //~^ ERROR unreachable
60 //~| ERROR unreachable
61 _ => {}
62 }
63 match None {
64 // There is only one error that correctly points to the whole subpattern
65 Some(0) |
66 Some( //~ ERROR unreachable
67 0 | 0) => {}
68 _ => {}
69 }
60c5eb7d
XL
70 match [0; 2] {
71 [0
72 | 0 //~ ERROR unreachable
73 , 0
74 | 0] => {} //~ ERROR unreachable
75 _ => {}
76 }
77 match &[][..] {
78 [0] => {}
79 [0, _] => {}
80 [0, _, _] => {}
81 [1, ..] => {}
82 [1 //~ ERROR unreachable
83 | 2, ..] => {}
84 _ => {}
85 }
fc512014
XL
86 match &[][..] {
87 [true] => {}
88 [true | false, ..] => {}
89 _ => {}
90 }
91 match &[][..] {
92 [false] => {}
93 [true, ..] => {}
94 [true //~ ERROR unreachable
95 | false, ..] => {}
96 _ => {}
97 }
98 match (true, None) {
99 (true, Some(_)) => {}
100 (false, Some(true)) => {}
101 (true | false, None | Some(true //~ ERROR unreachable
102 | false)) => {}
103 }
104 macro_rules! t_or_f {
105 () => {
6a06907d
XL
106 (true //~ ERROR unreachable
107 | false)
fc512014
XL
108 };
109 }
110 match (true, None) {
111 (true, Some(_)) => {}
112 (false, Some(true)) => {}
113 (true | false, None | Some(t_or_f!())) => {}
114 }
60c5eb7d
XL
115 match Some(0) {
116 Some(0) => {}
117 Some(0 //~ ERROR unreachable
118 | 1) => {}
119 _ => {}
120 }
f035d41b
XL
121
122 // A subpattern that is only unreachable in one branch is overall reachable.
123 match (true, true) {
124 (true, true) => {}
125 (false | true, false | true) => {}
126 }
127 match (true, true) {
29967ef6
XL
128 (true, true) => {}
129 (false, false) => {}
f035d41b
XL
130 (false | true, false | true) => {}
131 }
29967ef6
XL
132 // https://github.com/rust-lang/rust/issues/76836
133 match None {
134 Some(false) => {}
135 None | Some(true
136 | false) => {} //~ ERROR unreachable
137 }
138
f035d41b
XL
139 // A subpattern that is unreachable in all branches is overall unreachable.
140 match (true, true) {
141 (false, true) => {}
142 (true, true) => {}
143 (false | true, false
144 | true) => {} //~ ERROR unreachable
145 }
146 match (true, true) {
147 (true, false) => {}
148 (true, true) => {}
149 (false
150 | true, //~ ERROR unreachable
151 false | true) => {}
152 }
60c5eb7d 153}