Skip to content

Commit 593cdcc

Browse files
committed
Lint only on single element overlap
1 parent 73d6efc commit 593cdcc

6 files changed

+20
-59
lines changed

src/librustc_mir/hair/pattern/_match.rs

+10-25
Original file line numberDiff line numberDiff line change
@@ -1077,35 +1077,20 @@ impl<'tcx> IntRange<'tcx> {
10771077
}
10781078

10791079
fn suspicious_intersection(&self, other: &Self) -> bool {
1080-
let (lo, hi) = (*self.range.start(), *self.range.end());
1081-
let (other_lo, other_hi) = (*other.range.start(), *other.range.end());
1082-
10831080
// `false` in the following cases:
1084-
// 1 ----
1085-
// 2 ----------
1086-
//
1087-
// 1 ----------
1088-
// 2 ----
1081+
// 1 ---- // 1 ---------- // 1 ---- // 1 ----
1082+
// 2 ---------- // 2 ---- // 2 ---- // 2 ----
10891083
//
1090-
// 1 ----
1091-
// 2 ----
1084+
// The following are currently `false`, but could be `true` in the future (#64007):
1085+
// 1 --------- // 1 ---------
1086+
// 2 ---------- // 2 ----------
10921087
//
1093-
// 1 ----
1094-
// 2 ----
1095-
10961088
// `true` in the following cases:
1097-
// 1 ---------
1098-
// 2 ----------
1099-
lo < other_lo && hi > other_lo && hi < other_hi ||
1100-
// 1 ---------
1101-
// 2 ----------
1102-
lo > other_lo && lo < other_hi && hi > other_hi ||
1103-
// 1 ----
1104-
// 2 ----
1105-
lo == other_hi && other_lo < lo ||
1106-
// 1 ----
1107-
// 2 -----
1108-
hi == other_lo && lo < other_lo
1089+
// 1 ------- // 1 -------
1090+
// 2 -------- // 2 -------
1091+
let (lo, hi) = (*self.range.start(), *self.range.end());
1092+
let (other_lo, other_hi) = (*other.range.start(), *other.range.end());
1093+
(lo == other_hi || hi == other_lo)
11091094
}
11101095
}
11111096

src/test/ui/exhaustive_integer_patterns.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn main() {
1919
0 ..= 32 => {}
2020
33 => {}
2121
34 .. 128 => {}
22-
100 ..= 200 => {} //~ ERROR multiple patterns covering the same range
22+
100 ..= 200 => {}
2323
200 => {} //~ ERROR unreachable pattern
2424
201 ..= 255 => {}
2525
}

src/test/ui/exhaustive_integer_patterns.stderr

+7-15
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
error: multiple patterns covering the same range
2-
--> $DIR/exhaustive_integer_patterns.rs:22:9
3-
|
4-
LL | 34 .. 128 => {}
5-
| --------- this range overlaps on `100u8..=127u8`
6-
LL | 100 ..= 200 => {}
7-
| ^^^^^^^^^^^ overlapping patterns
8-
|
9-
note: lint level defined here
10-
--> $DIR/exhaustive_integer_patterns.rs:4:9
11-
|
12-
LL | #![deny(overlapping_patterns)]
13-
| ^^^^^^^^^^^^^^^^^^^^
14-
151
error: unreachable pattern
162
--> $DIR/exhaustive_integer_patterns.rs:23:9
173
|
@@ -101,6 +87,12 @@ LL | 0 .. 2 => {}
10187
| ------ this range overlaps on `1u8`
10288
LL | 1 ..= 2 => {}
10389
| ^^^^^^^ overlapping patterns
90+
|
91+
note: lint level defined here
92+
--> $DIR/exhaustive_integer_patterns.rs:4:9
93+
|
94+
LL | #![deny(overlapping_patterns)]
95+
| ^^^^^^^^^^^^^^^^^^^^
10496

10597
error[E0004]: non-exhaustive patterns: `std::u128::MAX` not covered
10698
--> $DIR/exhaustive_integer_patterns.rs:146:11
@@ -126,6 +118,6 @@ LL | match 0u128 {
126118
|
127119
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
128120

129-
error: aborting due to 15 previous errors
121+
error: aborting due to 14 previous errors
130122

131123
For more information about this error, try `rustc --explain E0004`.

src/test/ui/issues/issue-13867.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// run-pass
22
// Test that codegen works correctly when there are multiple refutable
33
// patterns in match expression.
4-
#![allow(overlapping_patterns)]
5-
64

75
enum Foo {
86
FooUint(usize),

src/test/ui/precise_pointer_size_matching.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ fn main() {
2828

2929
match 0usize { //~ ERROR non-exhaustive patterns
3030
1 ..= 8 => {}
31-
5 ..= 20 => {} //~ ERROR multiple patterns covering the same range
31+
5 ..= 20 => {}
3232
}
3333
}

src/test/ui/precise_pointer_size_matching.stderr

+1-15
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,6 @@ LL | match 0isize {
66
|
77
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
88

9-
error: multiple patterns covering the same range
10-
--> $DIR/precise_pointer_size_matching.rs:31:9
11-
|
12-
LL | 1 ..= 8 => {}
13-
| ------- this range overlaps on `5usize..=8usize`
14-
LL | 5 ..= 20 => {}
15-
| ^^^^^^^^ overlapping patterns
16-
|
17-
note: lint level defined here
18-
--> $DIR/precise_pointer_size_matching.rs:11:31
19-
|
20-
LL | #![deny(unreachable_patterns, overlapping_patterns)]
21-
| ^^^^^^^^^^^^^^^^^^^^
22-
239
error[E0004]: non-exhaustive patterns: `0usize` and `21usize..=std::usize::MAX` not covered
2410
--> $DIR/precise_pointer_size_matching.rs:29:11
2511
|
@@ -28,6 +14,6 @@ LL | match 0usize {
2814
|
2915
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
3016

31-
error: aborting due to 3 previous errors
17+
error: aborting due to 2 previous errors
3218

3319
For more information about this error, try `rustc --explain E0004`.

0 commit comments

Comments
 (0)