Skip to content

Commit 36591d9

Browse files
committed
shrink TestBranch::Constant
1 parent 9f3f015 commit 36591d9

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

compiler/rustc_middle/src/thir.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -955,11 +955,10 @@ impl<'tcx> PatRange<'tcx> {
955955
}
956956

957957
#[inline]
958-
pub fn contains(&self, value: ty::Value<'tcx>, tcx: TyCtxt<'tcx>) -> Option<bool> {
958+
pub fn contains(&self, valtree: ty::ValTree<'tcx>, tcx: TyCtxt<'tcx>) -> Option<bool> {
959959
use Ordering::*;
960-
debug_assert_eq!(self.ty, value.ty);
961960
let ty = self.ty;
962-
let value = PatRangeBoundary::Finite(value);
961+
let value = PatRangeBoundary::Finite(ty::Value { ty, valtree });
963962
// For performance, it's important to only do the second comparison if necessary.
964963
Some(
965964
match self.lo.compare_with(value, ty, tcx)? {

compiler/rustc_mir_build/src/builder/matches/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,15 +1373,15 @@ enum TestBranch<'tcx> {
13731373
/// Success branch, used for tests with two possible outcomes.
13741374
Success,
13751375
/// Branch corresponding to this constant.
1376-
Constant(ty::Value<'tcx>, u128),
1376+
Constant(ty::ValTree<'tcx>, u128),
13771377
/// Branch corresponding to this variant.
13781378
Variant(VariantIdx),
13791379
/// Failure branch for tests with two possible outcomes, and "otherwise" branch for other tests.
13801380
Failure,
13811381
}
13821382

13831383
impl<'tcx> TestBranch<'tcx> {
1384-
fn as_constant(&self) -> Option<ty::Value<'tcx>> {
1384+
fn as_constant(&self) -> Option<ty::ValTree<'tcx>> {
13851385
if let Self::Constant(v, _) = self { Some(*v) } else { None }
13861386
}
13871387
}

compiler/rustc_mir_build/src/builder/matches/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
558558
// not to add such values here.
559559
let is_covering_range = |test_case: &TestCase<'tcx>| {
560560
test_case.as_range().is_some_and(|range| {
561-
matches!(range.contains(value, self.tcx), None | Some(true))
561+
matches!(range.contains(value.valtree, self.tcx), None | Some(true))
562562
})
563563
};
564564
let is_conflicting_candidate = |candidate: &&mut Candidate<'tcx>| {
@@ -576,7 +576,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
576576
} else {
577577
fully_matched = true;
578578
let bits = value.try_to_scalar_int().unwrap().to_bits_unchecked();
579-
Some(TestBranch::Constant(value, bits))
579+
Some(TestBranch::Constant(value.valtree, bits))
580580
}
581581
}
582582
(TestKind::SwitchInt, TestCase::Range(range)) => {
@@ -684,7 +684,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
684684
}
685685
(TestKind::Range(range), &TestCase::Constant { value }) => {
686686
fully_matched = false;
687-
if !range.contains(value, self.tcx)? {
687+
if !range.contains(value.valtree, self.tcx)? {
688688
// `value` is not contained in the testing range,
689689
// so `value` can be matched only if this test fails.
690690
Some(TestBranch::Failure)

0 commit comments

Comments
 (0)