Skip to content

Commit 8de1c1a

Browse files
committed
Use ConstantKind for constants in patterns
1 parent 092c29f commit 8de1c1a

File tree

6 files changed

+190
-134
lines changed

6 files changed

+190
-134
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,13 +867,13 @@ enum TestKind<'tcx> {
867867
///
868868
/// For `bool` we always generate two edges, one for `true` and one for
869869
/// `false`.
870-
options: FxIndexMap<&'tcx ty::Const<'tcx>, u128>,
870+
options: FxIndexMap<ConstantKind<'tcx>, u128>,
871871
},
872872

873873
/// Test for equality with value, possibly after an unsizing coercion to
874874
/// `ty`,
875875
Eq {
876-
value: &'tcx ty::Const<'tcx>,
876+
value: ConstantKind<'tcx>,
877877
// Integer types are handled by `SwitchInt`, and constants with ADT
878878
// types are converted back into patterns, so this can only be `&str`,
879879
// `&[T]`, `f32` or `f64`.

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
8585
test_place: &PlaceBuilder<'tcx>,
8686
candidate: &Candidate<'pat, 'tcx>,
8787
switch_ty: Ty<'tcx>,
88-
options: &mut FxIndexMap<&'tcx ty::Const<'tcx>, u128>,
88+
options: &mut FxIndexMap<ConstantKind<'tcx>, u128>,
8989
) -> bool {
9090
let match_pair = match candidate.match_pairs.iter().find(|mp| mp.place == *test_place) {
9191
Some(match_pair) => match_pair,
@@ -262,7 +262,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
262262
ty,
263263
);
264264
} else if let [success, fail] = *make_target_blocks(self) {
265-
assert_eq!(value.ty, ty);
265+
assert_eq!(value.ty(), ty);
266266
let expect = self.literal_operand(test.span, value);
267267
let val = Operand::Copy(place);
268268
self.compare(block, success, fail, source_info, BinOp::Eq, expect, val);
@@ -364,7 +364,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
364364
block: BasicBlock,
365365
make_target_blocks: impl FnOnce(&mut Self) -> Vec<BasicBlock>,
366366
source_info: SourceInfo,
367-
value: &'tcx ty::Const<'tcx>,
367+
value: ConstantKind<'tcx>,
368368
place: Place<'tcx>,
369369
mut ty: Ty<'tcx>,
370370
) {
@@ -385,7 +385,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
385385
_ => None,
386386
};
387387
let opt_ref_ty = unsize(ty);
388-
let opt_ref_test_ty = unsize(value.ty);
388+
let opt_ref_test_ty = unsize(value.ty());
389389
match (opt_ref_ty, opt_ref_test_ty) {
390390
// nothing to do, neither is an array
391391
(None, None) => {}
@@ -773,16 +773,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
773773
fn const_range_contains(
774774
&self,
775775
range: PatRange<'tcx>,
776-
value: &'tcx ty::Const<'tcx>,
776+
value: ConstantKind<'tcx>,
777777
) -> Option<bool> {
778778
use std::cmp::Ordering::*;
779779

780780
let tcx = self.tcx;
781781

782-
let lo = ty::Const::from_value(tcx, ConstValue::Scalar(range.lo.into()), value.ty);
783-
let hi = ty::Const::from_value(tcx, ConstValue::Scalar(range.hi.into()), value.ty);
784-
let a = compare_const_vals(tcx, lo, value, self.param_env, value.ty)?;
785-
let b = compare_const_vals(tcx, value, hi, self.param_env, value.ty)?;
782+
let lo = ConstantKind::Val(ConstValue::Scalar(range.lo.into()), value.ty());
783+
let hi = ConstantKind::Val(ConstValue::Scalar(range.hi.into()), value.ty());
784+
let a = compare_const_vals(tcx, lo, value, self.param_env, value.ty())?;
785+
let b = compare_const_vals(tcx, value, hi, self.param_env, value.ty())?;
786786

787787
match (b, range.end) {
788788
(Less, _) | (Equal, RangeEnd::Included) if a != Greater => Some(true),
@@ -793,7 +793,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
793793
fn values_not_contained_in_range(
794794
&self,
795795
range: PatRange<'tcx>,
796-
options: &FxIndexMap<&'tcx ty::Const<'tcx>, u128>,
796+
options: &FxIndexMap<ConstantKind<'tcx>, u128>,
797797
) -> Option<bool> {
798798
for &val in options.keys() {
799799
if self.const_range_contains(range, val)? {

compiler/rustc_mir_build/src/build/misc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2828
crate fn literal_operand(
2929
&mut self,
3030
span: Span,
31-
literal: &'tcx ty::Const<'tcx>,
31+
literal: impl Into<ConstantKind<'tcx>>,
3232
) -> Operand<'tcx> {
3333
let literal = literal.into();
3434
let constant = box Constant { span, user_ty: None, literal };

0 commit comments

Comments
 (0)