Skip to content

Commit ddf0e85

Browse files
committed
Factor out getting the boundaries of an IntRange
1 parent fa256f7 commit ddf0e85

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
@@ -1231,6 +1231,10 @@ impl<'tcx> IntRange<'tcx> {
12311231
self.range.start() == self.range.end()
12321232
}
12331233

1234+
fn boundaries(&self) -> (u128, u128) {
1235+
(*self.range.start(), *self.range.end())
1236+
}
1237+
12341238
fn should_treat_range_exhaustively(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
12351239
// Don't treat `usize`/`isize` exhaustively unless the `precise_pointer_size_matching`
12361240
// feature is enabled.
@@ -1341,11 +1345,11 @@ impl<'tcx> IntRange<'tcx> {
13411345

13421346
/// Returns a collection of ranges that spans the values covered by `ranges`, subtracted
13431347
/// by the values covered by `self`: i.e., `ranges \ self` (in set notation).
1344-
fn subtract_from(self, ranges: Vec<IntRange<'tcx>>) -> Vec<IntRange<'tcx>> {
1348+
fn subtract_from(&self, ranges: Vec<IntRange<'tcx>>) -> Vec<IntRange<'tcx>> {
13451349
let mut remaining_ranges = vec![];
13461350
let ty = self.ty;
13471351
let span = self.span;
1348-
let (lo, hi) = self.range.into_inner();
1352+
let (lo, hi) = self.boundaries();
13491353
for subrange in ranges {
13501354
let (subrange_lo, subrange_hi) = subrange.range.into_inner();
13511355
if lo > subrange_hi || subrange_lo > hi {
@@ -1370,8 +1374,8 @@ impl<'tcx> IntRange<'tcx> {
13701374

13711375
fn intersection(&self, tcx: TyCtxt<'tcx>, other: &Self) -> Option<Self> {
13721376
let ty = self.ty;
1373-
let (lo, hi) = (*self.range.start(), *self.range.end());
1374-
let (other_lo, other_hi) = (*other.range.start(), *other.range.end());
1377+
let (lo, hi) = self.boundaries();
1378+
let (other_lo, other_hi) = other.boundaries();
13751379
if Self::should_treat_range_exhaustively(tcx, ty) {
13761380
if lo <= other_hi && other_lo <= hi {
13771381
let span = other.span;
@@ -1397,13 +1401,13 @@ impl<'tcx> IntRange<'tcx> {
13971401
// `true` in the following cases:
13981402
// 1 ------- // 1 -------
13991403
// 2 -------- // 2 -------
1400-
let (lo, hi) = (*self.range.start(), *self.range.end());
1401-
let (other_lo, other_hi) = (*other.range.start(), *other.range.end());
1404+
let (lo, hi) = self.boundaries();
1405+
let (other_lo, other_hi) = other.boundaries();
14021406
(lo == other_hi || hi == other_lo)
14031407
}
14041408

14051409
fn to_pat(&self, tcx: TyCtxt<'tcx>) -> Pat<'tcx> {
1406-
let (lo, hi) = (self.range.start(), self.range.end());
1410+
let (lo, hi) = self.boundaries();
14071411

14081412
let bias = IntRange::signed_bias(tcx, self.ty);
14091413
let (lo, hi) = (lo ^ bias, hi ^ bias);
@@ -2278,8 +2282,8 @@ fn specialize_one_pattern<'p, 'a: 'p, 'q: 'p, 'tcx>(
22782282
(Some(ctor), Some(pat)) => ctor.intersection(cx.tcx, &pat).map(|_| {
22792283
// Constructor splitting should ensure that all intersections we encounter
22802284
// are actually inclusions.
2281-
let (pat_lo, pat_hi) = pat.range.into_inner();
2282-
let (ctor_lo, ctor_hi) = ctor.range.into_inner();
2285+
let (pat_lo, pat_hi) = pat.boundaries();
2286+
let (ctor_lo, ctor_hi) = ctor.boundaries();
22832287
assert!(pat_lo <= ctor_lo && ctor_hi <= pat_hi);
22842288
PatStack::default()
22852289
}),

0 commit comments

Comments
 (0)