Skip to content

Commit dcd4784

Browse files
Type level consts can show up in MIR type checker
1 parent 45e08a5 commit dcd4784

8 files changed

+19
-24
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
349349
let tcx = self.tcx();
350350
let maybe_uneval = match constant.const_ {
351351
Const::Ty(_, ct) => match ct.kind() {
352-
ty::ConstKind::Unevaluated(_) => {
353-
bug!("should not encounter unevaluated Const::Ty here, got {:?}", ct)
352+
ty::ConstKind::Unevaluated(uv) => {
353+
Some(UnevaluatedConst { def: uv.def, args: uv.args, promoted: None })
354354
}
355355
_ => None,
356356
},

compiler/rustc_mir_build/src/builder/expr/as_place.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
651651
// though. FIXME: Do we really *need* to count this as a use?
652652
// Could partial array tracking work off something else instead?
653653
self.cfg.push_fake_read(block, source_info, FakeReadCause::ForIndex, place);
654-
let const_ = Const::from_ty_const(*len_const, self.tcx.types.usize, self.tcx);
655-
Operand::Constant(Box::new(ConstOperand { span, user_ty: None, const_ }))
654+
Operand::Constant(Box::new(ConstOperand {
655+
span,
656+
user_ty: None,
657+
const_: Const::Ty(self.tcx.types.usize, *len_const),
658+
}))
656659
}
657660
ty::Slice(_elem_ty) => {
658661
let ptr_or_ref = if let [PlaceElem::Deref] = place.projection[..]

tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-abort.diff

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
StorageDead(_2);
3131
StorageDead(_3);
3232
StorageLive(_5);
33-
- StorageLive(_6);
34-
+ nop;
33+
StorageLive(_6);
3534
_6 = const 3_usize;
3635
- _7 = PtrMetadata(copy _1);
3736
- _8 = Lt(copy _6, copy _7);
@@ -43,9 +42,8 @@
4342

4443
bb1: {
4544
- _5 = copy (*_1)[_6];
46-
- StorageDead(_6);
4745
+ _5 = copy (*_1)[3 of 4];
48-
+ nop;
46+
StorageDead(_6);
4947
_0 = const ();
5048
StorageDead(_5);
5149
StorageDead(_1);

tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-unwind.diff

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
StorageDead(_2);
3131
StorageDead(_3);
3232
StorageLive(_5);
33-
- StorageLive(_6);
34-
+ nop;
33+
StorageLive(_6);
3534
_6 = const 3_usize;
3635
- _7 = PtrMetadata(copy _1);
3736
- _8 = Lt(copy _6, copy _7);
@@ -43,9 +42,8 @@
4342

4443
bb1: {
4544
- _5 = copy (*_1)[_6];
46-
- StorageDead(_6);
4745
+ _5 = copy (*_1)[3 of 4];
48-
+ nop;
46+
StorageDead(_6);
4947
_0 = const ();
5048
StorageDead(_5);
5149
StorageDead(_1);

tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-abort.diff

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
StorageDead(_2);
3131
StorageDead(_3);
3232
StorageLive(_5);
33-
- StorageLive(_6);
34-
+ nop;
33+
StorageLive(_6);
3534
_6 = const 3_usize;
3635
- _7 = PtrMetadata(copy _1);
3736
- _8 = Lt(copy _6, copy _7);
@@ -43,9 +42,8 @@
4342

4443
bb1: {
4544
- _5 = copy (*_1)[_6];
46-
- StorageDead(_6);
4745
+ _5 = copy (*_1)[3 of 4];
48-
+ nop;
46+
StorageDead(_6);
4947
_0 = const ();
5048
StorageDead(_5);
5149
StorageDead(_1);

tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-unwind.diff

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
StorageDead(_2);
3131
StorageDead(_3);
3232
StorageLive(_5);
33-
- StorageLive(_6);
34-
+ nop;
33+
StorageLive(_6);
3534
_6 = const 3_usize;
3635
- _7 = PtrMetadata(copy _1);
3736
- _8 = Lt(copy _6, copy _7);
@@ -43,9 +42,8 @@
4342

4443
bb1: {
4544
- _5 = copy (*_1)[_6];
46-
- StorageDead(_6);
4745
+ _5 = copy (*_1)[3 of 4];
48-
+ nop;
46+
StorageDead(_6);
4947
_0 = const ();
5048
StorageDead(_5);
5149
StorageDead(_1);

tests/mir-opt/nll/region_subtyping_basic.main.nll.0.32bit.mir

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ fn main() -> () {
5252
StorageLive(_3);
5353
_3 = const ConstValue(Scalar(0x00000000): usize);
5454
FakeRead(ForIndex, _1);
55-
_4 = Lt(copy _3, const ConstValue(Scalar(0x00000003): usize));
56-
assert(move _4, "index out of bounds: the length is {} but the index is {}", const ConstValue(Scalar(0x00000003): usize), copy _3) -> [success: bb1, unwind: bb7];
55+
_4 = Lt(copy _3, const ValTree(Leaf(0x00000003): usize));
56+
assert(move _4, "index out of bounds: the length is {} but the index is {}", const ValTree(Leaf(0x00000003): usize), copy _3) -> [success: bb1, unwind: bb7];
5757
}
5858

5959
bb1: {

tests/mir-opt/nll/region_subtyping_basic.main.nll.0.64bit.mir

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ fn main() -> () {
5252
StorageLive(_3);
5353
_3 = const ConstValue(Scalar(0x0000000000000000): usize);
5454
FakeRead(ForIndex, _1);
55-
_4 = Lt(copy _3, const ConstValue(Scalar(0x0000000000000003): usize));
56-
assert(move _4, "index out of bounds: the length is {} but the index is {}", const ConstValue(Scalar(0x0000000000000003): usize), copy _3) -> [success: bb1, unwind: bb7];
55+
_4 = Lt(copy _3, const ValTree(Leaf(0x0000000000000003): usize));
56+
assert(move _4, "index out of bounds: the length is {} but the index is {}", const ValTree(Leaf(0x0000000000000003): usize), copy _3) -> [success: bb1, unwind: bb7];
5757
}
5858

5959
bb1: {

0 commit comments

Comments
 (0)