1
Fork 0

Lint only on single element overlap

This commit is contained in:
Esteban Küber 2019-10-16 12:22:23 -07:00
parent 73d6efc43e
commit 593cdcccf2
6 changed files with 22 additions and 61 deletions

View file

@ -1077,35 +1077,20 @@ impl<'tcx> IntRange<'tcx> {
}
fn suspicious_intersection(&self, other: &Self) -> bool {
// `false` in the following cases:
// 1 ---- // 1 ---------- // 1 ---- // 1 ----
// 2 ---------- // 2 ---- // 2 ---- // 2 ----
//
// The following are currently `false`, but could be `true` in the future (#64007):
// 1 --------- // 1 ---------
// 2 ---------- // 2 ----------
//
// `true` in the following cases:
// 1 ------- // 1 -------
// 2 -------- // 2 -------
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 ----
// 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
(lo == other_hi || hi == other_lo)
}
}

View file

@ -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 => {}
}

View file

@ -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`.

View file

@ -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),

View file

@ -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 => {}
}
}

View file

@ -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`.