about summary refs log tree commit diff
diff options
context:
space:
mode:
authorvarkor <github@varkor.com>2018-10-16 14:56:39 +0100
committervarkor <github@varkor.com>2018-10-16 16:12:05 +0100
commitfe09dbfcba0ba812d671f2c255a986bbabdd878d (patch)
treec11127e10a43600d1e08e420523565e35f5a04e9
parent5ea8eb55cd9f4547b332f43c9f723de30187c223 (diff)
downloadrust-fe09dbfcba0ba812d671f2c255a986bbabdd878d.tar.gz
rust-fe09dbfcba0ba812d671f2c255a986bbabdd878d.zip
Allow explicit matches on ! without warning
-rw-r--r--src/librustc_typeck/check/_match.rs5
-rw-r--r--src/test/ui/unreachable/unwarned-match-on-never.rs18
-rw-r--r--src/test/ui/unreachable/unwarned-match-on-never.stderr22
3 files changed, 40 insertions, 5 deletions
diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs
index c9158af178f..b4c969447de 100644
--- a/src/librustc_typeck/check/_match.rs
+++ b/src/librustc_typeck/check/_match.rs
@@ -608,10 +608,6 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
             self.check_expr_has_type_or_error(discrim, discrim_ty);
         };
 
-        // If the discriminant diverges, the match is pointless (e.g.,
-        // `match (return) { }`).
-        self.warn_if_unreachable(expr.id, expr.span, "expression");
-
         // If there are no arms, that is a diverging match; a special case.
         if arms.is_empty() {
             self.diverges.set(self.diverges.get() | Diverges::Always);
@@ -620,7 +616,6 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
 
         // Otherwise, we have to union together the types that the
         // arms produce and so forth.
-
         let discrim_diverges = self.diverges.get();
         self.diverges.set(Diverges::Maybe);
 
diff --git a/src/test/ui/unreachable/unwarned-match-on-never.rs b/src/test/ui/unreachable/unwarned-match-on-never.rs
new file mode 100644
index 00000000000..0c160615c8b
--- /dev/null
+++ b/src/test/ui/unreachable/unwarned-match-on-never.rs
@@ -0,0 +1,18 @@
+#![deny(unreachable_code)]
+#![allow(dead_code)]
+
+#![feature(never_type)]
+
+fn foo(x: !) -> bool {
+    // Explicit matches on the never type are unwarned.
+    match x {}
+    // But matches in unreachable code are warned.
+    match x {} //~ ERROR: unreachable expression
+}
+
+fn main() {
+    return;
+    match () { //~ ERROR: unreachable expression
+        () => (),
+    }
+}
diff --git a/src/test/ui/unreachable/unwarned-match-on-never.stderr b/src/test/ui/unreachable/unwarned-match-on-never.stderr
new file mode 100644
index 00000000000..969c24a07e8
--- /dev/null
+++ b/src/test/ui/unreachable/unwarned-match-on-never.stderr
@@ -0,0 +1,22 @@
+error: unreachable expression
+  --> $DIR/unwarned-match-on-never.rs:10:5
+   |
+LL |     match x {} //~ ERROR: unreachable expression
+   |     ^^^^^^^^^^
+   |
+note: lint level defined here
+  --> $DIR/unwarned-match-on-never.rs:1:9
+   |
+LL | #![deny(unreachable_code)]
+   |         ^^^^^^^^^^^^^^^^
+
+error: unreachable expression
+  --> $DIR/unwarned-match-on-never.rs:15:5
+   |
+LL | /     match () { //~ ERROR: unreachable expression
+LL | |         () => (),
+LL | |     }
+   | |_____^
+
+error: aborting due to 2 previous errors
+