Skip to content

Commit 320f6f4

Browse files
committed
Add inter-crate test.
1 parent 1895292 commit 320f6f4

File tree

3 files changed

+75
-40
lines changed

3 files changed

+75
-40
lines changed

tests/ui/pattern/usefulness/empty-match.exhaustive_patterns.stderr

+36-20
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,35 @@ error: unreachable pattern
2828
LL | _ if false => {},
2929
| ^
3030

31+
error[E0005]: refutable pattern in local binding
32+
--> $DIR/empty-match.rs:55:9
33+
|
34+
LL | let None = x;
35+
| ^^^^ pattern `Some(_)` not covered
36+
|
37+
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
38+
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
39+
= note: pattern `Some(_)` is currently uninhabited, but this variant contains private fields which may become inhabited in the future
40+
= note: the matched value is of type `Option<SecretlyUninhabitedForeignStruct>`
41+
help: you might want to use `if let` to ignore the variant that isn't matched
42+
|
43+
LL | if let None = x { todo!() };
44+
| ++ +++++++++++
45+
3146
error: unreachable pattern
32-
--> $DIR/empty-match.rs:57:9
47+
--> $DIR/empty-match.rs:61:9
3348
|
3449
LL | _ => {},
3550
| ^
3651

3752
error: unreachable pattern
38-
--> $DIR/empty-match.rs:60:9
53+
--> $DIR/empty-match.rs:64:9
3954
|
4055
LL | _ if false => {},
4156
| ^
4257

4358
error[E0004]: non-exhaustive patterns: type `u8` is non-empty
44-
--> $DIR/empty-match.rs:78:20
59+
--> $DIR/empty-match.rs:82:20
4560
|
4661
LL | match_no_arms!(0u8);
4762
| ^^^
@@ -50,7 +65,7 @@ LL | match_no_arms!(0u8);
5065
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
5166

5267
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct1` is non-empty
53-
--> $DIR/empty-match.rs:79:20
68+
--> $DIR/empty-match.rs:83:20
5469
|
5570
LL | match_no_arms!(NonEmptyStruct1);
5671
| ^^^^^^^^^^^^^^^
@@ -64,7 +79,7 @@ LL | struct NonEmptyStruct1;
6479
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
6580

6681
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct2` is non-empty
67-
--> $DIR/empty-match.rs:80:20
82+
--> $DIR/empty-match.rs:84:20
6883
|
6984
LL | match_no_arms!(NonEmptyStruct2(true));
7085
| ^^^^^^^^^^^^^^^^^^^^^
@@ -78,7 +93,7 @@ LL | struct NonEmptyStruct2(bool);
7893
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
7994

8095
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion1` is non-empty
81-
--> $DIR/empty-match.rs:81:20
96+
--> $DIR/empty-match.rs:85:20
8297
|
8398
LL | match_no_arms!((NonEmptyUnion1 { foo: () }));
8499
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -92,7 +107,7 @@ LL | union NonEmptyUnion1 {
92107
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
93108

94109
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion2` is non-empty
95-
--> $DIR/empty-match.rs:82:20
110+
--> $DIR/empty-match.rs:86:20
96111
|
97112
LL | match_no_arms!((NonEmptyUnion2 { foo: () }));
98113
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -106,7 +121,7 @@ LL | union NonEmptyUnion2 {
106121
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
107122

108123
error[E0004]: non-exhaustive patterns: `NonEmptyEnum1::Foo(_)` not covered
109-
--> $DIR/empty-match.rs:83:20
124+
--> $DIR/empty-match.rs:87:20
110125
|
111126
LL | match_no_arms!(NonEmptyEnum1::Foo(true));
112127
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered
@@ -122,7 +137,7 @@ LL | Foo(bool),
122137
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern
123138

124139
error[E0004]: non-exhaustive patterns: `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
125-
--> $DIR/empty-match.rs:84:20
140+
--> $DIR/empty-match.rs:88:20
126141
|
127142
LL | match_no_arms!(NonEmptyEnum2::Foo(true));
128143
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
@@ -140,7 +155,7 @@ LL | Bar,
140155
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms
141156

142157
error[E0004]: non-exhaustive patterns: `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
143-
--> $DIR/empty-match.rs:85:20
158+
--> $DIR/empty-match.rs:89:20
144159
|
145160
LL | match_no_arms!(NonEmptyEnum5::V1);
146161
| ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
@@ -154,7 +169,7 @@ LL | enum NonEmptyEnum5 {
154169
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms
155170

156171
error[E0004]: non-exhaustive patterns: `_` not covered
157-
--> $DIR/empty-match.rs:87:24
172+
--> $DIR/empty-match.rs:91:24
158173
|
159174
LL | match_guarded_arm!(0u8);
160175
| ^^^ pattern `_` not covered
@@ -167,7 +182,7 @@ LL + _ => todo!()
167182
|
168183

169184
error[E0004]: non-exhaustive patterns: `NonEmptyStruct1` not covered
170-
--> $DIR/empty-match.rs:88:24
185+
--> $DIR/empty-match.rs:92:24
171186
|
172187
LL | match_guarded_arm!(NonEmptyStruct1);
173188
| ^^^^^^^^^^^^^^^ pattern `NonEmptyStruct1` not covered
@@ -185,7 +200,7 @@ LL + NonEmptyStruct1 => todo!()
185200
|
186201

187202
error[E0004]: non-exhaustive patterns: `NonEmptyStruct2(_)` not covered
188-
--> $DIR/empty-match.rs:89:24
203+
--> $DIR/empty-match.rs:93:24
189204
|
190205
LL | match_guarded_arm!(NonEmptyStruct2(true));
191206
| ^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyStruct2(_)` not covered
@@ -203,7 +218,7 @@ LL + NonEmptyStruct2(_) => todo!()
203218
|
204219

205220
error[E0004]: non-exhaustive patterns: `NonEmptyUnion1 { .. }` not covered
206-
--> $DIR/empty-match.rs:90:24
221+
--> $DIR/empty-match.rs:94:24
207222
|
208223
LL | match_guarded_arm!((NonEmptyUnion1 { foo: () }));
209224
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion1 { .. }` not covered
@@ -221,7 +236,7 @@ LL + NonEmptyUnion1 { .. } => todo!()
221236
|
222237

223238
error[E0004]: non-exhaustive patterns: `NonEmptyUnion2 { .. }` not covered
224-
--> $DIR/empty-match.rs:91:24
239+
--> $DIR/empty-match.rs:95:24
225240
|
226241
LL | match_guarded_arm!((NonEmptyUnion2 { foo: () }));
227242
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion2 { .. }` not covered
@@ -239,7 +254,7 @@ LL + NonEmptyUnion2 { .. } => todo!()
239254
|
240255

241256
error[E0004]: non-exhaustive patterns: `NonEmptyEnum1::Foo(_)` not covered
242-
--> $DIR/empty-match.rs:92:24
257+
--> $DIR/empty-match.rs:96:24
243258
|
244259
LL | match_guarded_arm!(NonEmptyEnum1::Foo(true));
245260
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered
@@ -259,7 +274,7 @@ LL + NonEmptyEnum1::Foo(_) => todo!()
259274
|
260275

261276
error[E0004]: non-exhaustive patterns: `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
262-
--> $DIR/empty-match.rs:93:24
277+
--> $DIR/empty-match.rs:97:24
263278
|
264279
LL | match_guarded_arm!(NonEmptyEnum2::Foo(true));
265280
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
@@ -281,7 +296,7 @@ LL + NonEmptyEnum2::Foo(_) | NonEmptyEnum2::Bar => todo!()
281296
|
282297

283298
error[E0004]: non-exhaustive patterns: `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
284-
--> $DIR/empty-match.rs:94:24
299+
--> $DIR/empty-match.rs:98:24
285300
|
286301
LL | match_guarded_arm!(NonEmptyEnum5::V1);
287302
| ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
@@ -298,6 +313,7 @@ LL ~ _ if false => {},
298313
LL + _ => todo!()
299314
|
300315

301-
error: aborting due to 22 previous errors
316+
error: aborting due to 23 previous errors
302317

303-
For more information about this error, try `rustc --explain E0004`.
318+
Some errors have detailed explanations: E0004, E0005.
319+
For more information about an error, try `rustc --explain E0004`.

tests/ui/pattern/usefulness/empty-match.normal.stderr

+35-20
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,34 @@ error: unreachable pattern
2828
LL | _ if false => {},
2929
| ^
3030

31+
error[E0005]: refutable pattern in local binding
32+
--> $DIR/empty-match.rs:55:9
33+
|
34+
LL | let None = x;
35+
| ^^^^ pattern `Some(_)` not covered
36+
|
37+
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
38+
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
39+
= note: the matched value is of type `Option<SecretlyUninhabitedForeignStruct>`
40+
help: you might want to use `if let` to ignore the variant that isn't matched
41+
|
42+
LL | if let None = x { todo!() };
43+
| ++ +++++++++++
44+
3145
error: unreachable pattern
32-
--> $DIR/empty-match.rs:57:9
46+
--> $DIR/empty-match.rs:61:9
3347
|
3448
LL | _ => {},
3549
| ^
3650

3751
error: unreachable pattern
38-
--> $DIR/empty-match.rs:60:9
52+
--> $DIR/empty-match.rs:64:9
3953
|
4054
LL | _ if false => {},
4155
| ^
4256

4357
error[E0004]: non-exhaustive patterns: type `u8` is non-empty
44-
--> $DIR/empty-match.rs:78:20
58+
--> $DIR/empty-match.rs:82:20
4559
|
4660
LL | match_no_arms!(0u8);
4761
| ^^^
@@ -50,7 +64,7 @@ LL | match_no_arms!(0u8);
5064
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
5165

5266
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct1` is non-empty
53-
--> $DIR/empty-match.rs:79:20
67+
--> $DIR/empty-match.rs:83:20
5468
|
5569
LL | match_no_arms!(NonEmptyStruct1);
5670
| ^^^^^^^^^^^^^^^
@@ -64,7 +78,7 @@ LL | struct NonEmptyStruct1;
6478
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
6579

6680
error[E0004]: non-exhaustive patterns: type `NonEmptyStruct2` is non-empty
67-
--> $DIR/empty-match.rs:80:20
81+
--> $DIR/empty-match.rs:84:20
6882
|
6983
LL | match_no_arms!(NonEmptyStruct2(true));
7084
| ^^^^^^^^^^^^^^^^^^^^^
@@ -78,7 +92,7 @@ LL | struct NonEmptyStruct2(bool);
7892
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
7993

8094
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion1` is non-empty
81-
--> $DIR/empty-match.rs:81:20
95+
--> $DIR/empty-match.rs:85:20
8296
|
8397
LL | match_no_arms!((NonEmptyUnion1 { foo: () }));
8498
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -92,7 +106,7 @@ LL | union NonEmptyUnion1 {
92106
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
93107

94108
error[E0004]: non-exhaustive patterns: type `NonEmptyUnion2` is non-empty
95-
--> $DIR/empty-match.rs:82:20
109+
--> $DIR/empty-match.rs:86:20
96110
|
97111
LL | match_no_arms!((NonEmptyUnion2 { foo: () }));
98112
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -106,7 +120,7 @@ LL | union NonEmptyUnion2 {
106120
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
107121

108122
error[E0004]: non-exhaustive patterns: `NonEmptyEnum1::Foo(_)` not covered
109-
--> $DIR/empty-match.rs:83:20
123+
--> $DIR/empty-match.rs:87:20
110124
|
111125
LL | match_no_arms!(NonEmptyEnum1::Foo(true));
112126
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered
@@ -122,7 +136,7 @@ LL | Foo(bool),
122136
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern
123137

124138
error[E0004]: non-exhaustive patterns: `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
125-
--> $DIR/empty-match.rs:84:20
139+
--> $DIR/empty-match.rs:88:20
126140
|
127141
LL | match_no_arms!(NonEmptyEnum2::Foo(true));
128142
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
@@ -140,7 +154,7 @@ LL | Bar,
140154
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms
141155

142156
error[E0004]: non-exhaustive patterns: `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
143-
--> $DIR/empty-match.rs:85:20
157+
--> $DIR/empty-match.rs:89:20
144158
|
145159
LL | match_no_arms!(NonEmptyEnum5::V1);
146160
| ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
@@ -154,7 +168,7 @@ LL | enum NonEmptyEnum5 {
154168
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms
155169

156170
error[E0004]: non-exhaustive patterns: `_` not covered
157-
--> $DIR/empty-match.rs:87:24
171+
--> $DIR/empty-match.rs:91:24
158172
|
159173
LL | match_guarded_arm!(0u8);
160174
| ^^^ pattern `_` not covered
@@ -167,7 +181,7 @@ LL + _ => todo!()
167181
|
168182

169183
error[E0004]: non-exhaustive patterns: `NonEmptyStruct1` not covered
170-
--> $DIR/empty-match.rs:88:24
184+
--> $DIR/empty-match.rs:92:24
171185
|
172186
LL | match_guarded_arm!(NonEmptyStruct1);
173187
| ^^^^^^^^^^^^^^^ pattern `NonEmptyStruct1` not covered
@@ -185,7 +199,7 @@ LL + NonEmptyStruct1 => todo!()
185199
|
186200

187201
error[E0004]: non-exhaustive patterns: `NonEmptyStruct2(_)` not covered
188-
--> $DIR/empty-match.rs:89:24
202+
--> $DIR/empty-match.rs:93:24
189203
|
190204
LL | match_guarded_arm!(NonEmptyStruct2(true));
191205
| ^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyStruct2(_)` not covered
@@ -203,7 +217,7 @@ LL + NonEmptyStruct2(_) => todo!()
203217
|
204218

205219
error[E0004]: non-exhaustive patterns: `NonEmptyUnion1 { .. }` not covered
206-
--> $DIR/empty-match.rs:90:24
220+
--> $DIR/empty-match.rs:94:24
207221
|
208222
LL | match_guarded_arm!((NonEmptyUnion1 { foo: () }));
209223
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion1 { .. }` not covered
@@ -221,7 +235,7 @@ LL + NonEmptyUnion1 { .. } => todo!()
221235
|
222236

223237
error[E0004]: non-exhaustive patterns: `NonEmptyUnion2 { .. }` not covered
224-
--> $DIR/empty-match.rs:91:24
238+
--> $DIR/empty-match.rs:95:24
225239
|
226240
LL | match_guarded_arm!((NonEmptyUnion2 { foo: () }));
227241
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyUnion2 { .. }` not covered
@@ -239,7 +253,7 @@ LL + NonEmptyUnion2 { .. } => todo!()
239253
|
240254

241255
error[E0004]: non-exhaustive patterns: `NonEmptyEnum1::Foo(_)` not covered
242-
--> $DIR/empty-match.rs:92:24
256+
--> $DIR/empty-match.rs:96:24
243257
|
244258
LL | match_guarded_arm!(NonEmptyEnum1::Foo(true));
245259
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered
@@ -259,7 +273,7 @@ LL + NonEmptyEnum1::Foo(_) => todo!()
259273
|
260274

261275
error[E0004]: non-exhaustive patterns: `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
262-
--> $DIR/empty-match.rs:93:24
276+
--> $DIR/empty-match.rs:97:24
263277
|
264278
LL | match_guarded_arm!(NonEmptyEnum2::Foo(true));
265279
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
@@ -281,7 +295,7 @@ LL + NonEmptyEnum2::Foo(_) | NonEmptyEnum2::Bar => todo!()
281295
|
282296

283297
error[E0004]: non-exhaustive patterns: `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
284-
--> $DIR/empty-match.rs:94:24
298+
--> $DIR/empty-match.rs:98:24
285299
|
286300
LL | match_guarded_arm!(NonEmptyEnum5::V1);
287301
| ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
@@ -298,6 +312,7 @@ LL ~ _ if false => {},
298312
LL + _ => todo!()
299313
|
300314

301-
error: aborting due to 22 previous errors
315+
error: aborting due to 23 previous errors
302316

303-
For more information about this error, try `rustc --explain E0004`.
317+
Some errors have detailed explanations: E0004, E0005.
318+
For more information about an error, try `rustc --explain E0004`.

tests/ui/pattern/usefulness/empty-match.rs

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ fn empty_foreign_enum(x: empty::EmptyForeignEnum) {
5151
}
5252
}
5353

54+
fn empty_foreign_enum_private(x: Option<empty::SecretlyUninhabitedForeignStruct>) {
55+
let None = x; //~ ERROR refutable pattern in local binding
56+
}
57+
5458
fn never(x: !) {
5559
match x {} // ok
5660
match x {

0 commit comments

Comments
 (0)