Skip to content

Commit

Permalink
Lint only on single element overlap
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Oct 16, 2019
1 parent 73d6efc commit 593cdcc
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 59 deletions.
35 changes: 10 additions & 25 deletions src/librustc_mir/hair/pattern/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/exhaustive_integer_patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {}
}
Expand Down
22 changes: 7 additions & 15 deletions src/test/ui/exhaustive_integer_patterns.stderr
Original file line number Diff line number Diff line change
@@ -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
|
Expand Down Expand Up @@ -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
Expand All @@ -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`.
2 changes: 0 additions & 2 deletions src/test/ui/issues/issue-13867.rs
Original file line number Diff line number Diff line change
@@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/precise_pointer_size_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {}
}
}
16 changes: 1 addition & 15 deletions src/test/ui/precise_pointer_size_matching.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand All @@ -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`.

0 comments on commit 593cdcc

Please sign in to comment.