Skip to content

Commit 3dd5034

Browse files
committed
Restore old match behaviour
1 parent 6561732 commit 3dd5034

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

src/librustc_mir/hair/pattern/check_match.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,11 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
230230
let scrutinee_is_uninhabited = if self.tcx.features().exhaustive_patterns {
231231
self.tcx.is_ty_uninhabited_from(module, pat_ty)
232232
} else {
233-
pat_ty.is_never()
233+
match pat_ty.sty {
234+
ty::Never => true,
235+
ty::Adt(def, _) => def.variants.is_empty(),
236+
_ => false
237+
}
234238
};
235239
if !scrutinee_is_uninhabited {
236240
// We know the type is inhabited, so this must be wrong

src/test/ui/uninhabited/uninhabited-matches-feature-gated.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ fn main() {
2020
let _ = match x {}; //~ ERROR non-exhaustive
2121

2222
let x: (Void,) = unsafe { std::mem::uninitialized() };
23-
let _ = match x {}; // okay
23+
let _ = match x {}; //~ ERROR non-exhaustive
2424

2525
let x: [Void; 1] = unsafe { std::mem::uninitialized() };
26-
let _ = match x {}; // okay
26+
let _ = match x {}; //~ ERROR non-exhaustive
2727

2828
let x: &[Void] = unsafe { std::mem::uninitialized() };
2929
let _ = match x { //~ ERROR non-exhaustive

src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,30 @@ help: ensure that all possible cases are being handled, possibly by adding wildc
1616
LL | let _ = match x {}; //~ ERROR non-exhaustive
1717
| ^
1818

19+
error[E0004]: non-exhaustive patterns: type (Void,) is non-empty
20+
--> $DIR/uninhabited-matches-feature-gated.rs:23:19
21+
|
22+
LL | let _ = match x {}; //~ ERROR non-exhaustive
23+
| ^
24+
|
25+
help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
26+
--> $DIR/uninhabited-matches-feature-gated.rs:23:19
27+
|
28+
LL | let _ = match x {}; //~ ERROR non-exhaustive
29+
| ^
30+
31+
error[E0004]: non-exhaustive patterns: type [Void; 1] is non-empty
32+
--> $DIR/uninhabited-matches-feature-gated.rs:26:19
33+
|
34+
LL | let _ = match x {}; //~ ERROR non-exhaustive
35+
| ^
36+
|
37+
help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
38+
--> $DIR/uninhabited-matches-feature-gated.rs:26:19
39+
|
40+
LL | let _ = match x {}; //~ ERROR non-exhaustive
41+
| ^
42+
1943
error[E0004]: non-exhaustive patterns: `&[_]` not covered
2044
--> $DIR/uninhabited-matches-feature-gated.rs:29:19
2145
|
@@ -34,7 +58,7 @@ error[E0005]: refutable pattern in local binding: `Err(_)` not covered
3458
LL | let Ok(x) = x;
3559
| ^^^^^ pattern `Err(_)` not covered
3660

37-
error: aborting due to 5 previous errors
61+
error: aborting due to 7 previous errors
3862

3963
Some errors occurred: E0004, E0005.
4064
For more information about an error, try `rustc --explain E0004`.

0 commit comments

Comments
 (0)