Skip to content

Commit 1909e3f

Browse files
committed
Constructor::display was only needed for displaying IntRange
I'm planning to stop using `ConstantRange`/`ConstantValue` for integral types, so going through `Constructor` will soon not be relevant.
1 parent 75a5088 commit 1909e3f

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

src/librustc_mir/hair/pattern/_match.rs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -655,25 +655,6 @@ impl<'tcx> Constructor<'tcx> {
655655
}
656656
}
657657

658-
fn display(&self, tcx: TyCtxt<'tcx>) -> String {
659-
match self {
660-
Constructor::ConstantValue(val, _) => format!("{}", val),
661-
Constructor::ConstantRange(lo, hi, ty, range_end, _) => {
662-
// Get the right sign on the output:
663-
let ty = ty::ParamEnv::empty().and(*ty);
664-
format!(
665-
"{}{}{}",
666-
ty::Const::from_bits(tcx, *lo, ty),
667-
range_end,
668-
ty::Const::from_bits(tcx, *hi, ty),
669-
)
670-
}
671-
Constructor::FixedLenSlice(val) => format!("[{}]", val),
672-
Constructor::VarLenSlice(prefix, suffix) => format!("[{}, .., {}]", prefix, suffix),
673-
_ => bug!("bad constructor being displayed: `{:?}", self),
674-
}
675-
}
676-
677658
// Returns the set of constructors covered by `self` but not by
678659
// anything in `other_ctors`.
679660
fn subtract_ctors(
@@ -1473,6 +1454,23 @@ impl<'tcx> IntRange<'tcx> {
14731454
let (other_lo, other_hi) = (*other.range.start(), *other.range.end());
14741455
(lo == other_hi || hi == other_lo)
14751456
}
1457+
1458+
fn display(&self, tcx: TyCtxt<'tcx>) -> String {
1459+
let (lo, hi) = (self.range.start(), self.range.end());
1460+
1461+
let bias = IntRange::signed_bias(tcx, self.ty);
1462+
let (lo, hi) = (lo ^ bias, hi ^ bias);
1463+
1464+
let ty = ty::ParamEnv::empty().and(self.ty);
1465+
let lo_const = ty::Const::from_bits(tcx, lo, ty);
1466+
let hi_const = ty::Const::from_bits(tcx, hi, ty);
1467+
1468+
if lo == hi {
1469+
format!("{}", lo_const)
1470+
} else {
1471+
format!("{}{}{}", lo_const, RangeEnd::Included, hi_const)
1472+
}
1473+
}
14761474
}
14771475

14781476
// Ignore spans when comparing, they don't carry semantic information as they are only for lints.
@@ -2118,9 +2116,7 @@ fn lint_overlapping_patterns(
21182116
int_range.span,
21192117
&format!(
21202118
"this range overlaps on `{}`",
2121-
IntRange { range: int_range.range, ty, span: DUMMY_SP }
2122-
.into_ctor(tcx)
2123-
.display(tcx),
2119+
IntRange { range: int_range.range, ty, span: DUMMY_SP }.display(tcx),
21242120
),
21252121
);
21262122
}

0 commit comments

Comments
 (0)