diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index 580ded50b05c6..1d83b104177e2 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 442b2f772572c..59f749198971b 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 4c5806f9606f8..7a3a36a820c65 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 809205685634e..9510aae775341 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 ee91088c0c36a..54aeb8616d959 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 98d347e06b609..2c2c2aa04c233 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`.