about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-08-30 13:37:59 -0700
committerEsteban Küber <esteban@kuber.com.ar>2019-10-16 11:57:19 -0700
commit89b19ccfdc6117f4df4d8c765464d6d929d483e0 (patch)
tree5dc8764bbeced8f79b150bd12ded691bd34f0212
parent6832da85c2241c9d75d01f1779f54cd9054d7a08 (diff)
downloadrust-89b19ccfdc6117f4df4d8c765464d6d929d483e0.tar.gz
rust-89b19ccfdc6117f4df4d8c765464d6d929d483e0.zip
Continue to emit unreachable pattern on cases caught by overlapping patterns
-rw-r--r--src/librustc_mir/hair/pattern/check_match.rs4
-rw-r--r--src/test/ui/check_match/issue-43253.stderr6
-rw-r--r--src/test/ui/exhaustive_integer_patterns.rs4
-rw-r--r--src/test/ui/exhaustive_integer_patterns.stderr26
-rw-r--r--src/test/ui/match/match-range-fail-dominate.rs16
-rw-r--r--src/test/ui/match/match-range-fail-dominate.stderr54
6 files changed, 76 insertions, 34 deletions
diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs
index d6ec155c963..7bc4bf291ee 100644
--- a/src/librustc_mir/hair/pattern/check_match.rs
+++ b/src/librustc_mir/hair/pattern/check_match.rs
@@ -429,10 +429,6 @@ fn check_arms<'tcx>(
 
                         hir::MatchSource::ForLoopDesugar |
                         hir::MatchSource::Normal => {
-                            if let box PatternKind::Range(..) = pat.kind {
-                                // Covered by `overlapping_patterns` with more context
-                                break;
-                            }
                             let mut err = cx.tcx.struct_span_lint_hir(
                                 lint::builtin::UNREACHABLE_PATTERNS,
                                 hir_pat.hir_id,
diff --git a/src/test/ui/check_match/issue-43253.stderr b/src/test/ui/check_match/issue-43253.stderr
index 2f6888c0118..ca4cd897322 100644
--- a/src/test/ui/check_match/issue-43253.stderr
+++ b/src/test/ui/check_match/issue-43253.stderr
@@ -33,6 +33,12 @@ LL |         8..=9 => {},
    |         ^^^^^ overlapping patterns
 
 warning: unreachable pattern
+  --> $DIR/issue-43253.rs:35:9
+   |
+LL |         8..=9 => {},
+   |         ^^^^^
+
+warning: unreachable pattern
   --> $DIR/issue-43253.rs:41:9
    |
 LL |         6 => {},
diff --git a/src/test/ui/exhaustive_integer_patterns.rs b/src/test/ui/exhaustive_integer_patterns.rs
index ef88ce94aa6..a0c1b013f39 100644
--- a/src/test/ui/exhaustive_integer_patterns.rs
+++ b/src/test/ui/exhaustive_integer_patterns.rs
@@ -41,7 +41,9 @@ fn main() {
     match x { //~ ERROR non-exhaustive patterns
         -7 => {}
         -5..=120 => {}
-        -2..=20 => {} //~ ERROR multiple patterns covering the same range
+        -2..=20 => {}
+        //~^ ERROR unreachable pattern
+        //~| ERROR multiple patterns covering the same range
         125 => {}
     }
 
diff --git a/src/test/ui/exhaustive_integer_patterns.stderr b/src/test/ui/exhaustive_integer_patterns.stderr
index 59cd3fffa8d..44fbc969225 100644
--- a/src/test/ui/exhaustive_integer_patterns.stderr
+++ b/src/test/ui/exhaustive_integer_patterns.stderr
@@ -48,6 +48,12 @@ LL |         -5..=120 => {}
 LL |         -2..=20 => {}
    |         ^^^^^^^ overlapping patterns
 
+error: unreachable pattern
+  --> $DIR/exhaustive_integer_patterns.rs:44:9
+   |
+LL |         -2..=20 => {}
+   |         ^^^^^^^
+
 error[E0004]: non-exhaustive patterns: `std::i8::MIN..=-8i8`, `-6i8`, `121i8..=124i8` and 1 more not covered
   --> $DIR/exhaustive_integer_patterns.rs:41:11
    |
@@ -57,7 +63,7 @@ LL |     match x {
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
 
 error[E0004]: non-exhaustive patterns: `std::i8::MIN` not covered
-  --> $DIR/exhaustive_integer_patterns.rs:82:11
+  --> $DIR/exhaustive_integer_patterns.rs:84:11
    |
 LL |     match 0i8 {
    |           ^^^ pattern `std::i8::MIN` not covered
@@ -65,7 +71,7 @@ LL |     match 0i8 {
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
 
 error[E0004]: non-exhaustive patterns: `0i16` not covered
-  --> $DIR/exhaustive_integer_patterns.rs:90:11
+  --> $DIR/exhaustive_integer_patterns.rs:92:11
    |
 LL |     match 0i16 {
    |           ^^^^ pattern `0i16` not covered
@@ -73,7 +79,7 @@ LL |     match 0i16 {
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
 
 error[E0004]: non-exhaustive patterns: `128u8..=std::u8::MAX` not covered
-  --> $DIR/exhaustive_integer_patterns.rs:108:11
+  --> $DIR/exhaustive_integer_patterns.rs:110:11
    |
 LL |     match 0u8 {
    |           ^^^ pattern `128u8..=std::u8::MAX` not covered
@@ -81,7 +87,7 @@ LL |     match 0u8 {
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
 
 error[E0004]: non-exhaustive patterns: `(0u8, Some(_))` and `(2u8..=std::u8::MAX, Some(_))` not covered
-  --> $DIR/exhaustive_integer_patterns.rs:120:11
+  --> $DIR/exhaustive_integer_patterns.rs:122:11
    |
 LL |     match (0u8, Some(())) {
    |           ^^^^^^^^^^^^^^^ patterns `(0u8, Some(_))` and `(2u8..=std::u8::MAX, Some(_))` not covered
@@ -89,7 +95,7 @@ LL |     match (0u8, Some(())) {
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
 
 error[E0004]: non-exhaustive patterns: `(126u8..=127u8, false)` not covered
-  --> $DIR/exhaustive_integer_patterns.rs:125:11
+  --> $DIR/exhaustive_integer_patterns.rs:127:11
    |
 LL |     match (0u8, true) {
    |           ^^^^^^^^^^^ pattern `(126u8..=127u8, false)` not covered
@@ -97,7 +103,7 @@ LL |     match (0u8, true) {
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
 
 error: multiple patterns covering the same range
-  --> $DIR/exhaustive_integer_patterns.rs:140:9
+  --> $DIR/exhaustive_integer_patterns.rs:142:9
    |
 LL |         0 .. 2 => {}
    |         ------ this range overlaps on `1u8`
@@ -105,7 +111,7 @@ LL |         1 ..= 2 => {}
    |         ^^^^^^^ overlapping patterns
 
 error[E0004]: non-exhaustive patterns: `std::u128::MAX` not covered
-  --> $DIR/exhaustive_integer_patterns.rs:145:11
+  --> $DIR/exhaustive_integer_patterns.rs:147:11
    |
 LL |     match 0u128 {
    |           ^^^^^ pattern `std::u128::MAX` not covered
@@ -113,7 +119,7 @@ LL |     match 0u128 {
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
 
 error[E0004]: non-exhaustive patterns: `5u128..=std::u128::MAX` not covered
-  --> $DIR/exhaustive_integer_patterns.rs:149:11
+  --> $DIR/exhaustive_integer_patterns.rs:151:11
    |
 LL |     match 0u128 {
    |           ^^^^^ pattern `5u128..=std::u128::MAX` not covered
@@ -121,13 +127,13 @@ LL |     match 0u128 {
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
 
 error[E0004]: non-exhaustive patterns: `0u128..=3u128` not covered
-  --> $DIR/exhaustive_integer_patterns.rs:153:11
+  --> $DIR/exhaustive_integer_patterns.rs:155:11
    |
 LL |     match 0u128 {
    |           ^^^^^ pattern `0u128..=3u128` not covered
    |
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
 
-error: aborting due to 15 previous errors
+error: aborting due to 16 previous errors
 
 For more information about this error, try `rustc --explain E0004`.
diff --git a/src/test/ui/match/match-range-fail-dominate.rs b/src/test/ui/match/match-range-fail-dominate.rs
index bdbb1f050a7..b6a89b8910c 100644
--- a/src/test/ui/match/match-range-fail-dominate.rs
+++ b/src/test/ui/match/match-range-fail-dominate.rs
@@ -3,25 +3,33 @@
 fn main() {
     match 5 {
       1 ..= 10 => { }
-      5 ..= 6 => { } //~ ERROR multiple patterns covering the same range
+      5 ..= 6 => { }
+      //~^ ERROR unreachable pattern
+      //~| ERROR multiple patterns covering the same range
       _ => {}
     };
 
     match 5 {
       3 ..= 6 => { }
-      4 ..= 6 => { } //~ ERROR multiple patterns covering the same range
+      4 ..= 6 => { }
+      //~^ ERROR unreachable pattern
+      //~| ERROR multiple patterns covering the same range
       _ => {}
     };
 
     match 5 {
       4 ..= 6 => { }
-      4 ..= 6 => { } //~ ERROR multiple patterns covering the same range
+      4 ..= 6 => { }
+      //~^ ERROR unreachable pattern
+      //~| ERROR multiple patterns covering the same range
       _ => {}
     };
 
     match 'c' {
       'A' ..= 'z' => {}
-      'a' ..= 'z' => {} //~ ERROR multiple patterns covering the same range
+      'a' ..= 'z' => {}
+      //~^ ERROR unreachable pattern
+      //~| ERROR multiple patterns covering the same range
       _ => {}
     };
 
diff --git a/src/test/ui/match/match-range-fail-dominate.stderr b/src/test/ui/match/match-range-fail-dominate.stderr
index b14e9b5008d..4a76e05fab5 100644
--- a/src/test/ui/match/match-range-fail-dominate.stderr
+++ b/src/test/ui/match/match-range-fail-dominate.stderr
@@ -12,32 +12,62 @@ note: lint level defined here
 LL | #![deny(unreachable_patterns, overlapping_patterns)]
    |                               ^^^^^^^^^^^^^^^^^^^^
 
+error: unreachable pattern
+  --> $DIR/match-range-fail-dominate.rs:6:7
+   |
+LL |       5 ..= 6 => { }
+   |       ^^^^^^^
+   |
+note: lint level defined here
+  --> $DIR/match-range-fail-dominate.rs:1:9
+   |
+LL | #![deny(unreachable_patterns, overlapping_patterns)]
+   |         ^^^^^^^^^^^^^^^^^^^^
+
 error: multiple patterns covering the same range
-  --> $DIR/match-range-fail-dominate.rs:12:7
+  --> $DIR/match-range-fail-dominate.rs:14:7
    |
 LL |       3 ..= 6 => { }
    |       ------- this range overlaps on `4i32..=6i32`
 LL |       4 ..= 6 => { }
    |       ^^^^^^^ overlapping patterns
 
+error: unreachable pattern
+  --> $DIR/match-range-fail-dominate.rs:14:7
+   |
+LL |       4 ..= 6 => { }
+   |       ^^^^^^^
+
 error: multiple patterns covering the same range
-  --> $DIR/match-range-fail-dominate.rs:18:7
+  --> $DIR/match-range-fail-dominate.rs:22:7
    |
 LL |       4 ..= 6 => { }
    |       ------- this range overlaps on `4i32..=6i32`
 LL |       4 ..= 6 => { }
    |       ^^^^^^^ overlapping patterns
 
+error: unreachable pattern
+  --> $DIR/match-range-fail-dominate.rs:22:7
+   |
+LL |       4 ..= 6 => { }
+   |       ^^^^^^^
+
 error: multiple patterns covering the same range
-  --> $DIR/match-range-fail-dominate.rs:24:7
+  --> $DIR/match-range-fail-dominate.rs:30:7
    |
 LL |       'A' ..= 'z' => {}
    |       ----------- this range overlaps on `'a'..='z'`
 LL |       'a' ..= 'z' => {}
    |       ^^^^^^^^^^^ overlapping patterns
 
+error: unreachable pattern
+  --> $DIR/match-range-fail-dominate.rs:30:7
+   |
+LL |       'a' ..= 'z' => {}
+   |       ^^^^^^^^^^^
+
 warning: floating-point types cannot be used in patterns
-  --> $DIR/match-range-fail-dominate.rs:29:7
+  --> $DIR/match-range-fail-dominate.rs:37:7
    |
 LL |       0.01f64 ..= 6.5f64 => {}
    |       ^^^^^^^
@@ -47,7 +77,7 @@ LL |       0.01f64 ..= 6.5f64 => {}
    = note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
 
 warning: floating-point types cannot be used in patterns
-  --> $DIR/match-range-fail-dominate.rs:29:19
+  --> $DIR/match-range-fail-dominate.rs:37:19
    |
 LL |       0.01f64 ..= 6.5f64 => {}
    |                   ^^^^^^
@@ -56,7 +86,7 @@ LL |       0.01f64 ..= 6.5f64 => {}
    = note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
 
 warning: floating-point types cannot be used in patterns
-  --> $DIR/match-range-fail-dominate.rs:36:7
+  --> $DIR/match-range-fail-dominate.rs:44:7
    |
 LL |       0.02f64 => {}
    |       ^^^^^^^
@@ -65,19 +95,13 @@ LL |       0.02f64 => {}
    = note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
 
 error: unreachable pattern
-  --> $DIR/match-range-fail-dominate.rs:36:7
+  --> $DIR/match-range-fail-dominate.rs:44:7
    |
 LL |       0.02f64 => {}
    |       ^^^^^^^
-   |
-note: lint level defined here
-  --> $DIR/match-range-fail-dominate.rs:1:9
-   |
-LL | #![deny(unreachable_patterns, overlapping_patterns)]
-   |         ^^^^^^^^^^^^^^^^^^^^
 
 warning: floating-point types cannot be used in patterns
-  --> $DIR/match-range-fail-dominate.rs:29:7
+  --> $DIR/match-range-fail-dominate.rs:37:7
    |
 LL |       0.01f64 ..= 6.5f64 => {}
    |       ^^^^^^^
@@ -85,5 +109,5 @@ LL |       0.01f64 ..= 6.5f64 => {}
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
 
-error: aborting due to 5 previous errors
+error: aborting due to 9 previous errors