Skip to content

Commit 1d442e7

Browse files
committed
Factor out IntRange::is_subrange
1 parent db18d14 commit 1d442e7

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
@@ -1304,6 +1304,10 @@ impl<'tcx> IntRange<'tcx> {
13041304
remaining_ranges
13051305
}
13061306

1307+
fn is_subrange(&self, other: &Self) -> bool {
1308+
other.range.start() <= self.range.start() && self.range.end() <= other.range.end()
1309+
}
1310+
13071311
fn intersection(&self, tcx: TyCtxt<'tcx>, other: &Self) -> Option<Self> {
13081312
let ty = self.ty;
13091313
let (lo, hi) = self.boundaries();
@@ -1317,7 +1321,7 @@ impl<'tcx> IntRange<'tcx> {
13171321
}
13181322
} else {
13191323
// If the range should not be treated exhaustively, fallback to checking for inclusion.
1320-
if other_lo <= lo && hi <= other_hi { Some(self.clone()) } else { None }
1324+
if self.is_subrange(other) { Some(self.clone()) } else { None }
13211325
}
13221326
}
13231327

@@ -2206,9 +2210,7 @@ fn specialize_one_pattern<'p, 'a: 'p, 'q: 'p, 'tcx>(
22062210
Some(pat) => ctor.intersection(cx.tcx, &pat).map(|_| {
22072211
// Constructor splitting should ensure that all intersections we encounter
22082212
// are actually inclusions.
2209-
let (pat_lo, pat_hi) = pat.boundaries();
2210-
let (ctor_lo, ctor_hi) = ctor.boundaries();
2211-
assert!(pat_lo <= ctor_lo && ctor_hi <= pat_hi);
2213+
assert!(ctor.is_subrange(&pat));
22122214
PatStack::default()
22132215
}),
22142216
_ => None,

0 commit comments

Comments
 (0)