Skip to content

Commit b82f149

Browse files
committed
Add tests for uninhabited types
1 parent 622bfdb commit b82f149

File tree

5 files changed

+351
-212
lines changed

5 files changed

+351
-212
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
#![crate_type = "rlib"]
22
pub enum EmptyForeignEnum {}
3+
4+
pub struct VisiblyUninhabitedForeignStruct {
5+
pub field: EmptyForeignEnum,
6+
}
7+
8+
pub struct SecretlyUninhabitedForeignStruct {
9+
_priv: EmptyForeignEnum,
10+
}

src/test/ui/pattern/usefulness/empty-match.exhaustive_patterns.stderr

+80-80
Original file line numberDiff line numberDiff line change
@@ -1,257 +1,257 @@
11
error: unreachable pattern
2-
--> $DIR/empty-match.rs:53:9
2+
--> $DIR/empty-match.rs:37:9
33
|
44
LL | _ => {},
55
| ^
66
|
77
note: the lint level is defined here
8-
--> $DIR/empty-match.rs:6:9
8+
--> $DIR/empty-match.rs:8:9
99
|
1010
LL | #![deny(unreachable_patterns)]
1111
| ^^^^^^^^^^^^^^^^^^^^
1212

1313
error: unreachable pattern
14-
--> $DIR/empty-match.rs:56:9
14+
--> $DIR/empty-match.rs:40:9
1515
|
1616
LL | _ if false => {},
1717
| ^
1818

1919
error: unreachable pattern
20-
--> $DIR/empty-match.rs:63:9
20+
--> $DIR/empty-match.rs:47:9
2121
|
2222
LL | _ => {},
2323
| ^
2424

2525
error: unreachable pattern
26-
--> $DIR/empty-match.rs:66:9
26+
--> $DIR/empty-match.rs:50:9
2727
|
2828
LL | _ if false => {},
2929
| ^
3030

3131
error: unreachable pattern
32-
--> $DIR/empty-match.rs:73:9
32+
--> $DIR/empty-match.rs:57:9
3333
|
3434
LL | _ => {},
3535
| ^
3636

3737
error: unreachable pattern
38-
--> $DIR/empty-match.rs:76:9
38+
--> $DIR/empty-match.rs:60:9
3939
|
4040
LL | _ if false => {},
4141
| ^
4242

43-
error: unreachable pattern
44-
--> $DIR/empty-match.rs:83:9
43+
error[E0004]: non-exhaustive patterns: type `u8` is non-empty
44+
--> $DIR/empty-match.rs:78:20
4545
|
46-
LL | Some(_) => {}
47-
| ^^^^^^^
48-
49-
error: unreachable pattern
50-
--> $DIR/empty-match.rs:87:9
46+
LL | match_no_arms!(0u8);
47+
| ^^^
5148
|
52-
LL | Some(_) => {}
53-
| ^^^^^^^
49+
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
50+
= note: the matched value is of type `u8`
5451

55-
error[E0004]: non-exhaustive patterns: type `u8` is non-empty
56-
--> $DIR/empty-match.rs:90:18
52+
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct1` is non-empty
53+
--> $DIR/empty-match.rs:79:20
5754
|
58-
LL | match_empty!(0u8);
59-
| ^^^
55+
LL | struct NonEmptyStruct1;
56+
| ----------------------- `NonEmptyStruct1` defined here
57+
...
58+
LL | match_no_arms!(NonEmptyStruct1);
59+
| ^^^^^^^^^^^^^^^
6060
|
6161
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
62-
= note: the matched value is of type `u8`
62+
= note: the matched value is of type `NonEmptyStruct1`
6363

64-
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct` is non-empty
65-
--> $DIR/empty-match.rs:92:18
64+
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct2` is non-empty
65+
--> $DIR/empty-match.rs:80:20
6666
|
67-
LL | struct NonEmptyStruct(bool);
68-
| ---------------------------- `NonEmptyStruct` defined here
67+
LL | struct NonEmptyStruct2(bool);
68+
| ----------------------------- `NonEmptyStruct2` defined here
6969
...
70-
LL | match_empty!(NonEmptyStruct(true));
71-
| ^^^^^^^^^^^^^^^^^^^^
70+
LL | match_no_arms!(NonEmptyStruct2(true));
71+
| ^^^^^^^^^^^^^^^^^^^^^
7272
|
7373
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
74-
= note: the matched value is of type `NonEmptyStruct`
74+
= note: the matched value is of type `NonEmptyStruct2`
7575

7676
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion1` is non-empty
77-
--> $DIR/empty-match.rs:94:18
77+
--> $DIR/empty-match.rs:81:20
7878
|
7979
LL | / union NonEmptyUnion1 {
8080
LL | | foo: (),
8181
LL | | }
8282
| |_- `NonEmptyUnion1` defined here
8383
...
84-
LL | match_empty!((NonEmptyUnion1 { foo: () }));
85-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
84+
LL | match_no_arms!((NonEmptyUnion1 { foo: () }));
85+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8686
|
8787
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
8888
= note: the matched value is of type `NonEmptyUnion1`
8989

9090
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion2` is non-empty
91-
--> $DIR/empty-match.rs:96:18
91+
--> $DIR/empty-match.rs:82:20
9292
|
9393
LL | / union NonEmptyUnion2 {
9494
LL | | foo: (),
9595
LL | | bar: (),
9696
LL | | }
9797
| |_- `NonEmptyUnion2` defined here
9898
...
99-
LL | match_empty!((NonEmptyUnion2 { foo: () }));
100-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
99+
LL | match_no_arms!((NonEmptyUnion2 { foo: () }));
100+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
101101
|
102102
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
103103
= note: the matched value is of type `NonEmptyUnion2`
104104

105105
error[E0004]: non-exhaustive patterns: `Foo(_)` not covered
106-
--> $DIR/empty-match.rs:98:18
106+
--> $DIR/empty-match.rs:83:20
107107
|
108108
LL | / enum NonEmptyEnum1 {
109109
LL | | Foo(bool),
110110
| | --- not covered
111-
LL | |
112-
LL | |
113111
LL | | }
114112
| |_- `NonEmptyEnum1` defined here
115113
...
116-
LL | match_empty!(NonEmptyEnum1::Foo(true));
117-
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `Foo(_)` not covered
114+
LL | match_no_arms!(NonEmptyEnum1::Foo(true));
115+
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `Foo(_)` not covered
118116
|
119117
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
120118
= note: the matched value is of type `NonEmptyEnum1`
121119

122120
error[E0004]: non-exhaustive patterns: `Foo(_)` and `Bar` not covered
123-
--> $DIR/empty-match.rs:100:18
121+
--> $DIR/empty-match.rs:84:20
124122
|
125123
LL | / enum NonEmptyEnum2 {
126124
LL | | Foo(bool),
127125
| | --- not covered
128-
LL | |
129-
LL | |
130126
LL | | Bar,
131127
| | --- not covered
132-
LL | |
133-
LL | |
134128
LL | | }
135129
| |_- `NonEmptyEnum2` defined here
136130
...
137-
LL | match_empty!(NonEmptyEnum2::Foo(true));
138-
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `Foo(_)` and `Bar` not covered
131+
LL | match_no_arms!(NonEmptyEnum2::Foo(true));
132+
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `Foo(_)` and `Bar` not covered
139133
|
140134
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
141135
= note: the matched value is of type `NonEmptyEnum2`
142136

143137
error[E0004]: non-exhaustive patterns: `V1`, `V2`, `V3` and 2 more not covered
144-
--> $DIR/empty-match.rs:102:18
138+
--> $DIR/empty-match.rs:85:20
145139
|
146140
LL | / enum NonEmptyEnum5 {
147141
LL | | V1, V2, V3, V4, V5,
148142
LL | | }
149143
| |_- `NonEmptyEnum5` defined here
150144
...
151-
LL | match_empty!(NonEmptyEnum5::V1);
152-
| ^^^^^^^^^^^^^^^^^ patterns `V1`, `V2`, `V3` and 2 more not covered
145+
LL | match_no_arms!(NonEmptyEnum5::V1);
146+
| ^^^^^^^^^^^^^^^^^ patterns `V1`, `V2`, `V3` and 2 more not covered
153147
|
154148
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
155149
= note: the matched value is of type `NonEmptyEnum5`
156150

157151
error[E0004]: non-exhaustive patterns: `_` not covered
158-
--> $DIR/empty-match.rs:105:18
152+
--> $DIR/empty-match.rs:87:24
159153
|
160-
LL | match_false!(0u8);
161-
| ^^^ pattern `_` not covered
154+
LL | match_guarded_arm!(0u8);
155+
| ^^^ pattern `_` not covered
162156
|
163157
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
164158
= note: the matched value is of type `u8`
165159

166-
error[E0004]: non-exhaustive patterns: `NonEmptyStruct(_)` not covered
167-
--> $DIR/empty-match.rs:107:18
160+
error[E0004]: non-exhaustive patterns: `NonEmptyStruct1` not covered
161+
--> $DIR/empty-match.rs:88:24
162+
|
163+
LL | struct NonEmptyStruct1;
164+
| ----------------------- `NonEmptyStruct1` defined here
165+
...
166+
LL | match_guarded_arm!(NonEmptyStruct1);
167+
| ^^^^^^^^^^^^^^^ pattern `NonEmptyStruct1` not covered
168+
|
169+
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
170+
= note: the matched value is of type `NonEmptyStruct1`
171+
172+
error[E0004]: non-exhaustive patterns: `NonEmptyStruct2(_)` not covered
173+
--> $DIR/empty-match.rs:89:24
168174
|
169-
LL | struct NonEmptyStruct(bool);
170-
| ---------------------------- `NonEmptyStruct` defined here
175+
LL | struct NonEmptyStruct2(bool);
176+
| ----------------------------- `NonEmptyStruct2` defined here
171177
...
172-
LL | match_false!(NonEmptyStruct(true));
173-
| ^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyStruct(_)` not covered
178+
LL | match_guarded_arm!(NonEmptyStruct2(true));
179+
| ^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyStruct2(_)` not covered
174180
|
175181
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
176-
= note: the matched value is of type `NonEmptyStruct`
182+
= note: the matched value is of type `NonEmptyStruct2`
177183

178184
error[E0004]: non-exhaustive patterns: `NonEmptyUnion1 { .. }` not covered
179-
--> $DIR/empty-match.rs:109:18
185+
--> $DIR/empty-match.rs:90:24
180186
|
181187
LL | / union NonEmptyUnion1 {
182188
LL | | foo: (),
183189
LL | | }
184190
| |_- `NonEmptyUnion1` defined here
185191
...
186-
LL | match_false!((NonEmptyUnion1 { foo: () }));
187-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion1 { .. }` not covered
192+
LL | match_guarded_arm!((NonEmptyUnion1 { foo: () }));
193+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion1 { .. }` not covered
188194
|
189195
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
190196
= note: the matched value is of type `NonEmptyUnion1`
191197

192198
error[E0004]: non-exhaustive patterns: `NonEmptyUnion2 { .. }` not covered
193-
--> $DIR/empty-match.rs:111:18
199+
--> $DIR/empty-match.rs:91:24
194200
|
195201
LL | / union NonEmptyUnion2 {
196202
LL | | foo: (),
197203
LL | | bar: (),
198204
LL | | }
199205
| |_- `NonEmptyUnion2` defined here
200206
...
201-
LL | match_false!((NonEmptyUnion2 { foo: () }));
202-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion2 { .. }` not covered
207+
LL | match_guarded_arm!((NonEmptyUnion2 { foo: () }));
208+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion2 { .. }` not covered
203209
|
204210
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
205211
= note: the matched value is of type `NonEmptyUnion2`
206212

207213
error[E0004]: non-exhaustive patterns: `Foo(_)` not covered
208-
--> $DIR/empty-match.rs:113:18
214+
--> $DIR/empty-match.rs:92:24
209215
|
210216
LL | / enum NonEmptyEnum1 {
211217
LL | | Foo(bool),
212218
| | --- not covered
213-
LL | |
214-
LL | |
215219
LL | | }
216220
| |_- `NonEmptyEnum1` defined here
217221
...
218-
LL | match_false!(NonEmptyEnum1::Foo(true));
219-
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `Foo(_)` not covered
222+
LL | match_guarded_arm!(NonEmptyEnum1::Foo(true));
223+
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `Foo(_)` not covered
220224
|
221225
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
222226
= note: the matched value is of type `NonEmptyEnum1`
223227

224228
error[E0004]: non-exhaustive patterns: `Foo(_)` and `Bar` not covered
225-
--> $DIR/empty-match.rs:115:18
229+
--> $DIR/empty-match.rs:93:24
226230
|
227231
LL | / enum NonEmptyEnum2 {
228232
LL | | Foo(bool),
229233
| | --- not covered
230-
LL | |
231-
LL | |
232234
LL | | Bar,
233235
| | --- not covered
234-
LL | |
235-
LL | |
236236
LL | | }
237237
| |_- `NonEmptyEnum2` defined here
238238
...
239-
LL | match_false!(NonEmptyEnum2::Foo(true));
240-
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `Foo(_)` and `Bar` not covered
239+
LL | match_guarded_arm!(NonEmptyEnum2::Foo(true));
240+
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `Foo(_)` and `Bar` not covered
241241
|
242242
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
243243
= note: the matched value is of type `NonEmptyEnum2`
244244

245245
error[E0004]: non-exhaustive patterns: `V1`, `V2`, `V3` and 2 more not covered
246-
--> $DIR/empty-match.rs:117:18
246+
--> $DIR/empty-match.rs:94:24
247247
|
248248
LL | / enum NonEmptyEnum5 {
249249
LL | | V1, V2, V3, V4, V5,
250250
LL | | }
251251
| |_- `NonEmptyEnum5` defined here
252252
...
253-
LL | match_false!(NonEmptyEnum5::V1);
254-
| ^^^^^^^^^^^^^^^^^ patterns `V1`, `V2`, `V3` and 2 more not covered
253+
LL | match_guarded_arm!(NonEmptyEnum5::V1);
254+
| ^^^^^^^^^^^^^^^^^ patterns `V1`, `V2`, `V3` and 2 more not covered
255255
|
256256
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
257257
= note: the matched value is of type `NonEmptyEnum5`

0 commit comments

Comments
 (0)