Skip to content

Commit b679e77

Browse files
committed
Factor out IntRange::is_subrange
1 parent 9165dd0 commit b679e77

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/librustc_mir/hair/pattern/_match.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,10 @@ impl<'tcx> IntRange<'tcx> {
13571357
remaining_ranges
13581358
}
13591359

1360+
fn is_subrange(&self, other: &Self) -> bool {
1361+
other.range.start() <= self.range.start() && self.range.end() <= other.range.end()
1362+
}
1363+
13601364
fn intersection(&self, tcx: TyCtxt<'tcx>, other: &Self) -> Option<Self> {
13611365
let ty = self.ty;
13621366
let (lo, hi) = self.boundaries();
@@ -1370,7 +1374,7 @@ impl<'tcx> IntRange<'tcx> {
13701374
}
13711375
} else {
13721376
// If the range should not be treated exhaustively, fallback to checking for inclusion.
1373-
if other_lo <= lo && hi <= other_hi { Some(self.clone()) } else { None }
1377+
if self.is_subrange(other) { Some(self.clone()) } else { None }
13741378
}
13751379
}
13761380

@@ -2236,9 +2240,7 @@ fn specialize_one_pattern<'p, 'a: 'p, 'q: 'p, 'tcx>(
22362240
Some(pat) => ctor.intersection(cx.tcx, &pat).map(|_| {
22372241
// Constructor splitting should ensure that all intersections we encounter
22382242
// are actually inclusions.
2239-
let (pat_lo, pat_hi) = pat.boundaries();
2240-
let (ctor_lo, ctor_hi) = ctor.boundaries();
2241-
assert!(pat_lo <= ctor_lo && ctor_hi <= pat_hi);
2243+
assert!(ctor.is_subrange(&pat));
22422244
PatStack::default()
22432245
}),
22442246
_ => None,

0 commit comments

Comments
 (0)