about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-10-16 12:22:23 -0700
committerEsteban Küber <esteban@kuber.com.ar>2019-10-16 12:22:23 -0700
commit593cdcccf28361df155c37916dcfcbe1bf19d9a5 (patch)
tree5ebe8d47bc6ee696b4f301081d79a08fffa35845 /src
parent73d6efc43e0629b2028e7d031306088f44f84782 (diff)
downloadrust-593cdcccf28361df155c37916dcfcbe1bf19d9a5.tar.gz
rust-593cdcccf28361df155c37916dcfcbe1bf19d9a5.zip
Lint only on single element overlap
Diffstat (limited to 'src')
-rw-r--r--src/librustc_mir/hair/pattern/_match.rs35
-rw-r--r--src/test/ui/exhaustive_integer_patterns.rs2
-rw-r--r--src/test/ui/exhaustive_integer_patterns.stderr22
-rw-r--r--src/test/ui/issues/issue-13867.rs2
-rw-r--r--src/test/ui/precise_pointer_size_matching.rs2
-rw-r--r--src/test/ui/precise_pointer_size_matching.stderr16
6 files changed, 20 insertions, 59 deletions
diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs
index 580ded50b05..1d83b104177 100644
--- a/src/librustc_mir/hair/pattern/_match.rs
+++ b/src/librustc_mir/hair/pattern/_match.rs
@@ -1077,35 +1077,20 @@ impl<'tcx> IntRange<'tcx> {
     }
 
     fn suspicious_intersection(&self, other: &Self) -> bool {
-        let (lo, hi) = (*self.range.start(), *self.range.end());
-        let (other_lo, other_hi) = (*other.range.start(), *other.range.end());
-
         // `false` in the following cases:
-        // 1     ----
-        // 2  ----------
-        //
-        // 1  ----------
-        // 2     ----
+        // 1     ----      // 1  ----------   // 1 ----        // 1       ----
+        // 2  ----------   // 2     ----      // 2       ----  // 2 ----
         //
-        // 1 ----
-        // 2       ----
+        // The following are currently `false`, but could be `true` in the future (#64007):
+        // 1 ---------       // 1     ---------
+        // 2     ----------  // 2 ----------
         //
-        // 1       ----
-        // 2 ----
-
         // `true` in the following cases:
-        // 1 ---------
-        // 2     ----------
-        lo < other_lo && hi > other_lo && hi < other_hi ||
-            // 1     ---------
-            // 2  ----------
-            lo > other_lo && lo < other_hi && hi > other_hi ||
-            // 1  ----
-            // 2     ----
-            lo == other_hi && other_lo < lo ||
-            // 1     ----
-            // 2 -----
-            hi == other_lo && lo < other_lo
+        // 1 -------          // 1       -------
+        // 2       --------   // 2 -------
+        let (lo, hi) = (*self.range.start(), *self.range.end());
+        let (other_lo, other_hi) = (*other.range.start(), *other.range.end());
+        (lo == other_hi || hi == other_lo)
     }
 }
 
diff --git a/src/test/ui/exhaustive_integer_patterns.rs b/src/test/ui/exhaustive_integer_patterns.rs
index 442b2f77257..59f74919897 100644
--- a/src/test/ui/exhaustive_integer_patterns.rs
+++ b/src/test/ui/exhaustive_integer_patterns.rs
@@ -19,7 +19,7 @@ fn main() {
         0 ..= 32 => {}
         33 => {}
         34 .. 128 => {}
-        100 ..= 200 => {} //~ ERROR multiple patterns covering the same range
+        100 ..= 200 => {}
         200 => {} //~ ERROR unreachable pattern
         201 ..= 255 => {}
     }
diff --git a/src/test/ui/exhaustive_integer_patterns.stderr b/src/test/ui/exhaustive_integer_patterns.stderr
index 4c5806f9606..7a3a36a820c 100644
--- a/src/test/ui/exhaustive_integer_patterns.stderr
+++ b/src/test/ui/exhaustive_integer_patterns.stderr
@@ -1,17 +1,3 @@
-error: multiple patterns covering the same range
-  --> $DIR/exhaustive_integer_patterns.rs:22:9
-   |
-LL |         34 .. 128 => {}
-   |         --------- this range overlaps on `100u8..=127u8`
-LL |         100 ..= 200 => {}
-   |         ^^^^^^^^^^^ overlapping patterns
-   |
-note: lint level defined here
-  --> $DIR/exhaustive_integer_patterns.rs:4:9
-   |
-LL | #![deny(overlapping_patterns)]
-   |         ^^^^^^^^^^^^^^^^^^^^
-
 error: unreachable pattern
   --> $DIR/exhaustive_integer_patterns.rs:23:9
    |
@@ -101,6 +87,12 @@ LL |         0 .. 2 => {}
    |         ------ this range overlaps on `1u8`
 LL |         1 ..= 2 => {}
    |         ^^^^^^^ overlapping patterns
+   |
+note: lint level defined here
+  --> $DIR/exhaustive_integer_patterns.rs:4:9
+   |
+LL | #![deny(overlapping_patterns)]
+   |         ^^^^^^^^^^^^^^^^^^^^
 
 error[E0004]: non-exhaustive patterns: `std::u128::MAX` not covered
   --> $DIR/exhaustive_integer_patterns.rs:146:11
@@ -126,6 +118,6 @@ LL |     match 0u128 {
    |
    = 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 14 previous errors
 
 For more information about this error, try `rustc --explain E0004`.
diff --git a/src/test/ui/issues/issue-13867.rs b/src/test/ui/issues/issue-13867.rs
index 80920568563..9510aae7753 100644
--- a/src/test/ui/issues/issue-13867.rs
+++ b/src/test/ui/issues/issue-13867.rs
@@ -1,8 +1,6 @@
 // run-pass
 // Test that codegen works correctly when there are multiple refutable
 // patterns in match expression.
-#![allow(overlapping_patterns)]
-
 
 enum Foo {
     FooUint(usize),
diff --git a/src/test/ui/precise_pointer_size_matching.rs b/src/test/ui/precise_pointer_size_matching.rs
index ee91088c0c3..54aeb8616d9 100644
--- a/src/test/ui/precise_pointer_size_matching.rs
+++ b/src/test/ui/precise_pointer_size_matching.rs
@@ -28,6 +28,6 @@ fn main() {
 
     match 0usize { //~ ERROR non-exhaustive patterns
         1 ..= 8 => {}
-        5 ..= 20 => {} //~ ERROR multiple patterns covering the same range
+        5 ..= 20 => {}
     }
 }
diff --git a/src/test/ui/precise_pointer_size_matching.stderr b/src/test/ui/precise_pointer_size_matching.stderr
index 98d347e06b6..2c2c2aa04c2 100644
--- a/src/test/ui/precise_pointer_size_matching.stderr
+++ b/src/test/ui/precise_pointer_size_matching.stderr
@@ -6,20 +6,6 @@ LL |     match 0isize {
    |
    = 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/precise_pointer_size_matching.rs:31:9
-   |
-LL |         1 ..= 8 => {}
-   |         ------- this range overlaps on `5usize..=8usize`
-LL |         5 ..= 20 => {}
-   |         ^^^^^^^^ overlapping patterns
-   |
-note: lint level defined here
-  --> $DIR/precise_pointer_size_matching.rs:11:31
-   |
-LL | #![deny(unreachable_patterns, overlapping_patterns)]
-   |                               ^^^^^^^^^^^^^^^^^^^^
-
 error[E0004]: non-exhaustive patterns: `0usize` and `21usize..=std::usize::MAX` not covered
   --> $DIR/precise_pointer_size_matching.rs:29:11
    |
@@ -28,6 +14,6 @@ LL |     match 0usize {
    |
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
 
-error: aborting due to 3 previous errors
+error: aborting due to 2 previous errors
 
 For more information about this error, try `rustc --explain E0004`.