Ensure match_overlapping_arms warns on first

This commit is contained in:
Michael Wright 2021-11-01 06:12:43 +02:00
parent c3d45775c4
commit 693df63c7d
3 changed files with 32 additions and 4 deletions

View File

@ -1761,10 +1761,17 @@ where
match value {
Kind::Start(_, r) => started.push(r),
Kind::End(_, er) => {
if let Some(sr) = started.pop() {
if sr != er {
return Some((er, sr));
let mut overlap = None;
while let Some(sr) = started.pop() {
if sr == er {
break;
}
overlap = Some(sr);
}
if let Some(sr) = overlap {
return Some((er, sr));
}
},
}

View File

@ -116,6 +116,15 @@ fn overlapping() {
_ => (),
}
// Only warn about the first if there are multiple overlaps
match 42u128 {
0..=0x0000_0000_0000_00ff => (),
0..=0x0000_0000_0000_ffff => (),
0..=0x0000_0000_ffff_ffff => (),
0..=0xffff_ffff_ffff_ffff => (),
_ => (),
}
if let None = Some(42) {
// nothing
} else if let None = Some(42) {

View File

@ -83,5 +83,17 @@ note: overlaps with this
LL | 21..=40 => (),
| ^^^^^^^
error: aborting due to 7 previous errors
error: some ranges overlap
--> $DIR/match_overlapping_arm.rs:121:9
|
LL | 0..=0x0000_0000_0000_00ff => (),
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: overlaps with this
--> $DIR/match_overlapping_arm.rs:122:9
|
LL | 0..=0x0000_0000_0000_ffff => (),
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 8 previous errors