From 3dd5034967ab61bfe4dd906fe794ced1279b318a Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 20 Nov 2018 21:16:25 +0000 Subject: [PATCH] Restore old match behaviour --- src/librustc_mir/hair/pattern/check_match.rs | 6 ++++- .../uninhabited-matches-feature-gated.rs | 4 +-- .../uninhabited-matches-feature-gated.stderr | 26 ++++++++++++++++++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 66de4e6b37f1..a251b723d61f 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -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 diff --git a/src/test/ui/uninhabited/uninhabited-matches-feature-gated.rs b/src/test/ui/uninhabited/uninhabited-matches-feature-gated.rs index a3b99deac233..1d3f8ff12d86 100644 --- a/src/test/ui/uninhabited/uninhabited-matches-feature-gated.rs +++ b/src/test/ui/uninhabited/uninhabited-matches-feature-gated.rs @@ -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 diff --git a/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr b/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr index 658ed9f46609..5b5b6df85fc0 100644 --- a/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr +++ b/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr @@ -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`.