Skip to content

Commit aadd5e5

Browse files
committed
Factor out getting the boundaries of an IntRange
1 parent 84784dd commit aadd5e5

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/librustc_mir/hair/pattern/_match.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,10 @@ impl<'tcx> IntRange<'tcx> {
12831283
self.range.start() == self.range.end()
12841284
}
12851285

1286+
fn boundaries(&self) -> (u128, u128) {
1287+
(*self.range.start(), *self.range.end())
1288+
}
1289+
12861290
fn should_treat_range_exhaustively(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
12871291
// Don't treat `usize`/`isize` exhaustively unless the `precise_pointer_size_matching`
12881292
// feature is enabled.
@@ -1395,11 +1399,11 @@ impl<'tcx> IntRange<'tcx> {
13951399

13961400
/// Returns a collection of ranges that spans the values covered by `ranges`, subtracted
13971401
/// by the values covered by `self`: i.e., `ranges \ self` (in set notation).
1398-
fn subtract_from(self, ranges: Vec<IntRange<'tcx>>) -> Vec<IntRange<'tcx>> {
1402+
fn subtract_from(&self, ranges: Vec<IntRange<'tcx>>) -> Vec<IntRange<'tcx>> {
13991403
let mut remaining_ranges = vec![];
14001404
let ty = self.ty;
14011405
let span = self.span;
1402-
let (lo, hi) = self.range.into_inner();
1406+
let (lo, hi) = self.boundaries();
14031407
for subrange in ranges {
14041408
let (subrange_lo, subrange_hi) = subrange.range.into_inner();
14051409
if lo > subrange_hi || subrange_lo > hi {
@@ -1424,8 +1428,8 @@ impl<'tcx> IntRange<'tcx> {
14241428

14251429
fn intersection(&self, tcx: TyCtxt<'tcx>, other: &Self) -> Option<Self> {
14261430
let ty = self.ty;
1427-
let (lo, hi) = (*self.range.start(), *self.range.end());
1428-
let (other_lo, other_hi) = (*other.range.start(), *other.range.end());
1431+
let (lo, hi) = self.boundaries();
1432+
let (other_lo, other_hi) = other.boundaries();
14291433
if Self::should_treat_range_exhaustively(tcx, ty) {
14301434
if lo <= other_hi && other_lo <= hi {
14311435
let span = other.span;
@@ -1451,13 +1455,13 @@ impl<'tcx> IntRange<'tcx> {
14511455
// `true` in the following cases:
14521456
// 1 ------- // 1 -------
14531457
// 2 -------- // 2 -------
1454-
let (lo, hi) = (*self.range.start(), *self.range.end());
1455-
let (other_lo, other_hi) = (*other.range.start(), *other.range.end());
1458+
let (lo, hi) = self.boundaries();
1459+
let (other_lo, other_hi) = other.boundaries();
14561460
(lo == other_hi || hi == other_lo)
14571461
}
14581462

14591463
fn to_pat(&self, tcx: TyCtxt<'tcx>) -> Pat<'tcx> {
1460-
let (lo, hi) = (self.range.start(), self.range.end());
1464+
let (lo, hi) = self.boundaries();
14611465

14621466
let bias = IntRange::signed_bias(tcx, self.ty);
14631467
let (lo, hi) = (lo ^ bias, hi ^ bias);
@@ -2309,8 +2313,8 @@ fn specialize_one_pattern<'p, 'a: 'p, 'q: 'p, 'tcx>(
23092313
(Some(ctor), Some(pat)) => ctor.intersection(cx.tcx, &pat).map(|_| {
23102314
// Constructor splitting should ensure that all intersections we encounter
23112315
// are actually inclusions.
2312-
let (pat_lo, pat_hi) = pat.range.into_inner();
2313-
let (ctor_lo, ctor_hi) = ctor.range.into_inner();
2316+
let (pat_lo, pat_hi) = pat.boundaries();
2317+
let (ctor_lo, ctor_hi) = ctor.boundaries();
23142318
assert!(pat_lo <= ctor_lo && ctor_hi <= pat_hi);
23152319
PatStack::default()
23162320
}),

0 commit comments

Comments
 (0)