Restore old match behaviour

This commit is contained in:
varkor 2018-11-20 21:16:25 +00:00
parent 6561732f88
commit 3dd5034967
3 changed files with 32 additions and 4 deletions

View file

@ -230,7 +230,11 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
let scrutinee_is_uninhabited = if self.tcx.features().exhaustive_patterns {
self.tcx.is_ty_uninhabited_from(module, pat_ty)
} else {
pat_ty.is_never()
match pat_ty.sty {
ty::Never => true,
ty::Adt(def, _) => def.variants.is_empty(),
_ => false
}
};
if !scrutinee_is_uninhabited {
// We know the type is inhabited, so this must be wrong

View file

@ -20,10 +20,10 @@ fn main() {
let _ = match x {}; //~ ERROR non-exhaustive
let x: (Void,) = unsafe { std::mem::uninitialized() };
let _ = match x {}; // okay
let _ = match x {}; //~ ERROR non-exhaustive
let x: [Void; 1] = unsafe { std::mem::uninitialized() };
let _ = match x {}; // okay
let _ = match x {}; //~ ERROR non-exhaustive
let x: &[Void] = unsafe { std::mem::uninitialized() };
let _ = match x { //~ ERROR non-exhaustive

View file

@ -16,6 +16,30 @@ help: ensure that all possible cases are being handled, possibly by adding wildc
LL | let _ = match x {}; //~ ERROR non-exhaustive
| ^
error[E0004]: non-exhaustive patterns: type (Void,) is non-empty
--> $DIR/uninhabited-matches-feature-gated.rs:23:19
|
LL | let _ = match x {}; //~ ERROR non-exhaustive
| ^
|
help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
--> $DIR/uninhabited-matches-feature-gated.rs:23:19
|
LL | let _ = match x {}; //~ ERROR non-exhaustive
| ^
error[E0004]: non-exhaustive patterns: type [Void; 1] is non-empty
--> $DIR/uninhabited-matches-feature-gated.rs:26:19
|
LL | let _ = match x {}; //~ ERROR non-exhaustive
| ^
|
help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
--> $DIR/uninhabited-matches-feature-gated.rs:26:19
|
LL | let _ = match x {}; //~ ERROR non-exhaustive
| ^
error[E0004]: non-exhaustive patterns: `&[_]` not covered
--> $DIR/uninhabited-matches-feature-gated.rs:29:19
|
@ -34,7 +58,7 @@ error[E0005]: refutable pattern in local binding: `Err(_)` not covered
LL | let Ok(x) = x;
| ^^^^^ pattern `Err(_)` not covered
error: aborting due to 5 previous errors
error: aborting due to 7 previous errors
Some errors occurred: E0004, E0005.
For more information about an error, try `rustc --explain E0004`.