Ensure match_overlapping_arms
warns on first
This commit is contained in:
parent
c3d45775c4
commit
693df63c7d
@ -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));
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user