This commit is contained in:
b-naber 2022-07-28 11:06:16 +02:00
parent db9a2d2fbe
commit 29c0364c37
22 changed files with 25 additions and 56 deletions

View File

@ -583,7 +583,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
pub fn uneval_to_op(
&self,
uneval: &ty::Unevaluated<'tcx>,
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
let instance = self.resolve(uneval.def, uneval.substs)?;
Ok(self.eval_to_allocation(GlobalId { instance, promoted: uneval.promoted })?.into())
}

View File

@ -1717,7 +1717,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// Postpone the evaluation of constants whose substs depend on inference
// variables
if substs.has_infer_types_or_consts() {
let ac = AbstractConst::new(self.tcx, unevaluated.shrink());
let ac = AbstractConst::new(self.tcx, unevaluated);
match ac {
Ok(None) => {
substs = InternalSubsts::identity_for_item(self.tcx, unevaluated.def.did);

View File

@ -222,17 +222,6 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
debug!("AbstractConstBuilder::build: body={:?}", &*self.body);
self.recurse_build(self.body_id)?;
for n in self.nodes.iter() {
if let Node::Leaf(ct) = n {
if let ty::ConstKind::Unevaluated(ct) = ct.kind() {
// `AbstractConst`s should not contain any promoteds as they require references which
// are not allowed.
assert_eq!(ct.promoted, None);
assert_eq!(ct, self.tcx.erase_regions(ct));
}
}
}
Ok(self.tcx.arena.alloc_from_iter(self.nodes.into_iter()))
}

View File

@ -236,7 +236,7 @@ pub(crate) fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String {
match n.kind() {
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs: _, promoted }) => {
assert_eq!(promoted, ());
let mut s = if let Some(def) = def.as_local() {
let s = if let Some(def) = def.as_local() {
print_const_expr(cx.tcx, cx.tcx.hir().body_owned_by(def.did))
} else {
inline::print_inlined_const(cx.tcx, def.did)

View File

@ -17,7 +17,7 @@
- StorageLive(_4); // scope 0 at $DIR/const-promotion-extern-static.rs:+0:32: +0:34
- StorageLive(_5); // scope 0 at $DIR/const-promotion-extern-static.rs:+0:33: +0:34
- _5 = const {alloc1: &i32}; // scope 0 at $DIR/const-promotion-extern-static.rs:+0:33: +0:34
+ _6 = const BAR::promoted[0]; // scope 0 at $DIR/const-promotion-extern-static.rs:+0:31: +0:44
+ _6 = const _; // scope 0 at $DIR/const-promotion-extern-static.rs:+0:31: +0:44
// mir::Constant
- // + span: $DIR/const-promotion-extern-static.rs:9:33: 9:34
- // + literal: Const { ty: &i32, val: Value(Scalar(alloc1)) }

View File

@ -19,7 +19,7 @@
- StorageLive(_4); // scope 0 at $DIR/const-promotion-extern-static.rs:+0:32: +0:45
- StorageLive(_5); // scope 1 at $DIR/const-promotion-extern-static.rs:+0:42: +0:43
- _5 = const {alloc3: *const i32}; // scope 1 at $DIR/const-promotion-extern-static.rs:+0:42: +0:43
+ _6 = const FOO::promoted[0]; // scope 0 at $DIR/const-promotion-extern-static.rs:+0:31: +0:55
+ _6 = const _; // scope 0 at $DIR/const-promotion-extern-static.rs:+0:31: +0:55
// mir::Constant
- // + span: $DIR/const-promotion-extern-static.rs:13:42: 13:43
- // + literal: Const { ty: *const i32, val: Value(Scalar(alloc3)) }

View File

@ -25,7 +25,7 @@
StorageLive(_1); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:+1:9: +1:10
StorageLive(_2); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:+1:25: +1:35
StorageLive(_3); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:+1:25: +1:35
_9 = const main::promoted[0]; // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:+1:25: +1:35
_9 = const _; // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:+1:25: +1:35
// mir::Constant
// + span: $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35
// + literal: Const { ty: &[i32; 3], val: Unevaluated(main, [], Some(promoted[0])) }

View File

@ -25,7 +25,7 @@
StorageLive(_1); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:+1:9: +1:10
StorageLive(_2); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:+1:25: +1:35
StorageLive(_3); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:+1:25: +1:35
_9 = const main::promoted[0]; // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:+1:25: +1:35
_9 = const _; // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:+1:25: +1:35
// mir::Constant
// + span: $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35
// + literal: Const { ty: &[i32; 3], val: Unevaluated(main, [], Some(promoted[0])) }

View File

@ -18,8 +18,8 @@
StorageLive(_3); // scope 0 at $DIR/const_prop_fails_gracefully.rs:+2:13: +2:16
_3 = const FOO; // scope 0 at $DIR/const_prop_fails_gracefully.rs:+2:13: +2:16
// mir::Constant
// + span: $DIR/const_prop_fails_gracefully.rs:8:13: 8:16
// + literal: Const { ty: &i32, val: Unevaluated(FOO, [], None) }
// + span: $DIR/const_prop_fails_gracefully.rs:7:13: 7:16
// + literal: Const { ty: &i32, val: Unevaluated(FOO, [], ()) }
_2 = &raw const (*_3); // scope 0 at $DIR/const_prop_fails_gracefully.rs:+2:13: +2:16
_1 = move _2 as usize (PointerExposeAddress); // scope 0 at $DIR/const_prop_fails_gracefully.rs:+2:13: +2:39
StorageDead(_2); // scope 0 at $DIR/const_prop_fails_gracefully.rs:+2:38: +2:39

View File

@ -11,7 +11,7 @@
bb0: {
StorageLive(_1); // scope 0 at $DIR/ref_deref.rs:+1:5: +1:10
StorageLive(_2); // scope 0 at $DIR/ref_deref.rs:+1:6: +1:10
_4 = const main::promoted[0]; // scope 0 at $DIR/ref_deref.rs:+1:6: +1:10
_4 = const _; // scope 0 at $DIR/ref_deref.rs:+1:6: +1:10
// mir::Constant
// + span: $DIR/ref_deref.rs:5:6: 5:10
// + literal: Const { ty: &i32, val: Unevaluated(main, [], Some(promoted[0])) }

View File

@ -14,7 +14,7 @@
- StorageLive(_3); // scope 0 at $DIR/ref_deref.rs:+1:8: +1:9
- _3 = const 4_i32; // scope 0 at $DIR/ref_deref.rs:+1:8: +1:9
- _2 = &_3; // scope 0 at $DIR/ref_deref.rs:+1:6: +1:10
+ _4 = const main::promoted[0]; // scope 0 at $DIR/ref_deref.rs:+1:6: +1:10
+ _4 = const _; // scope 0 at $DIR/ref_deref.rs:+1:6: +1:10
+ // mir::Constant
+ // + span: $DIR/ref_deref.rs:5:6: 5:10
+ // + literal: Const { ty: &i32, val: Unevaluated(main, [], Some(promoted[0])) }

View File

@ -11,7 +11,7 @@
bb0: {
StorageLive(_1); // scope 0 at $DIR/ref_deref_project.rs:+1:5: +1:17
StorageLive(_2); // scope 0 at $DIR/ref_deref_project.rs:+1:6: +1:17
_4 = const main::promoted[0]; // scope 0 at $DIR/ref_deref_project.rs:+1:6: +1:17
_4 = const _; // scope 0 at $DIR/ref_deref_project.rs:+1:6: +1:17
// mir::Constant
// + span: $DIR/ref_deref_project.rs:6:6: 6:17
// + literal: Const { ty: &(i32, i32), val: Unevaluated(main, [], Some(promoted[0])) }

View File

@ -14,7 +14,7 @@
- StorageLive(_3); // scope 0 at $DIR/ref_deref_project.rs:+1:8: +1:14
- _3 = (const 4_i32, const 5_i32); // scope 0 at $DIR/ref_deref_project.rs:+1:8: +1:14
- _2 = &(_3.1: i32); // scope 0 at $DIR/ref_deref_project.rs:+1:6: +1:17
+ _4 = const main::promoted[0]; // scope 0 at $DIR/ref_deref_project.rs:+1:6: +1:17
+ _4 = const _; // scope 0 at $DIR/ref_deref_project.rs:+1:6: +1:17
+ // mir::Constant
+ // + span: $DIR/ref_deref_project.rs:6:6: 6:17
+ // + literal: Const { ty: &(i32, i32), val: Unevaluated(main, [], Some(promoted[0])) }

View File

@ -19,7 +19,7 @@
StorageLive(_2); // scope 0 at $DIR/slice_len.rs:+1:5: +1:30
StorageLive(_3); // scope 0 at $DIR/slice_len.rs:+1:6: +1:19
StorageLive(_4); // scope 0 at $DIR/slice_len.rs:+1:6: +1:19
_9 = const main::promoted[0]; // scope 0 at $DIR/slice_len.rs:+1:6: +1:19
_9 = const _; // scope 0 at $DIR/slice_len.rs:+1:6: +1:19
// mir::Constant
// + span: $DIR/slice_len.rs:5:6: 5:19
// + literal: Const { ty: &[u32; 3], val: Unevaluated(main, [], Some(promoted[0])) }

View File

@ -19,7 +19,7 @@
StorageLive(_2); // scope 0 at $DIR/slice_len.rs:+1:5: +1:30
StorageLive(_3); // scope 0 at $DIR/slice_len.rs:+1:6: +1:19
StorageLive(_4); // scope 0 at $DIR/slice_len.rs:+1:6: +1:19
_9 = const main::promoted[0]; // scope 0 at $DIR/slice_len.rs:+1:6: +1:19
_9 = const _; // scope 0 at $DIR/slice_len.rs:+1:6: +1:19
// mir::Constant
// + span: $DIR/slice_len.rs:5:6: 5:19
// + literal: Const { ty: &[u32; 3], val: Unevaluated(main, [], Some(promoted[0])) }

View File

@ -28,7 +28,7 @@
bb0: {
StorageLive(_1); // scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
StorageLive(_2); // scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
_14 = const main::promoted[0]; // scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
_14 = const _; // scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
// mir::Constant
// + span: $DIR/derefer_complex_case.rs:6:17: 6:26
// + literal: Const { ty: &[i32; 2], val: Unevaluated(main, [], Some(promoted[0])) }

View File

@ -32,7 +32,7 @@ fn bar() -> bool {
_2 = _1; // scope 1 at $DIR/inline-retag.rs:+2:5: +2:6
StorageLive(_3); // scope 1 at $DIR/inline-retag.rs:+2:7: +2:9
StorageLive(_4); // scope 1 at $DIR/inline-retag.rs:+2:7: +2:9
_10 = const bar::promoted[1]; // scope 1 at $DIR/inline-retag.rs:+2:7: +2:9
_10 = const _; // scope 1 at $DIR/inline-retag.rs:+2:7: +2:9
// mir::Constant
// + span: $DIR/inline-retag.rs:12:7: 12:9
// + literal: Const { ty: &i32, val: Unevaluated(bar, [], Some(promoted[1])) }
@ -43,7 +43,7 @@ fn bar() -> bool {
Retag(_3); // scope 1 at $DIR/inline-retag.rs:+2:7: +2:9
StorageLive(_6); // scope 1 at $DIR/inline-retag.rs:+2:11: +2:14
StorageLive(_7); // scope 1 at $DIR/inline-retag.rs:+2:11: +2:14
_9 = const bar::promoted[0]; // scope 1 at $DIR/inline-retag.rs:+2:11: +2:14
_9 = const _; // scope 1 at $DIR/inline-retag.rs:+2:11: +2:14
// mir::Constant
// + span: $DIR/inline-retag.rs:12:11: 12:14
// + literal: Const { ty: &i32, val: Unevaluated(bar, [], Some(promoted[0])) }

View File

@ -87,7 +87,7 @@
StorageLive(_10); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
_10 = &_1; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
StorageLive(_11); // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
_28 = _; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
_28 = const _; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
// mir::Constant
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
// + literal: Const { ty: &i32, val: Unevaluated(main, [], Some(promoted[0])) }

View File

@ -2,7 +2,7 @@
| User Type Annotations
| 0: user_ty: Canonical { max_universe: U0, variables: [], value: TypeOf(DefId(0:3 ~ issue_99325[8f58]::function_with_bytes), UserSubsts { substs: [Const { ty: &'static [u8; 4], kind: Value(Branch([Leaf(0x41), Leaf(0x41), Leaf(0x41), Leaf(0x41)])) }], user_self_ty: None }) }, span: $DIR/issue-99325.rs:10:16: 10:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
| 1: user_ty: Canonical { max_universe: U0, variables: [], value: TypeOf(DefId(0:3 ~ issue_99325[8f58]::function_with_bytes), UserSubsts { substs: [Const { ty: &'static [u8; 4], kind: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:8 ~ issue_99325[8f58]::main::{constant#1}), const_param_did: Some(DefId(0:4 ~ issue_99325[8f58]::function_with_bytes::BYTES)) }, substs: [], promoted: None }) }], user_self_ty: None }) }, span: $DIR/issue-99325.rs:11:16: 11:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
| 1: user_ty: Canonical { max_universe: U0, variables: [], value: TypeOf(DefId(0:3 ~ issue_99325[8f58]::function_with_bytes), UserSubsts { substs: [Const { ty: &'static [u8; 4], kind: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:8 ~ issue_99325[8f58]::main::{constant#1}), const_param_did: Some(DefId(0:4 ~ issue_99325[8f58]::function_with_bytes::BYTES)) }, substs: [], promoted: () }) }], user_self_ty: None }) }, span: $DIR/issue-99325.rs:11:16: 11:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
|
fn main() -> () {
let mut _0: (); // return place in scope 0 at $DIR/issue-99325.rs:+0:15: +0:15

View File

@ -44,7 +44,7 @@
StorageLive(_5); // scope 0 at $DIR/lower_intrinsics.rs:+2:5: +2:45
StorageLive(_6); // scope 0 at $DIR/lower_intrinsics.rs:+2:42: +2:44
StorageLive(_7); // scope 0 at $DIR/lower_intrinsics.rs:+2:42: +2:44
_19 = const discriminant::<T>::promoted[2]; // scope 0 at $DIR/lower_intrinsics.rs:+2:42: +2:44
_19 = const _; // scope 0 at $DIR/lower_intrinsics.rs:+2:42: +2:44
// mir::Constant
// + span: $DIR/lower_intrinsics.rs:50:42: 50:44
// + literal: Const { ty: &i32, val: Unevaluated(discriminant, [T], Some(promoted[2])) }
@ -59,23 +59,13 @@
}
bb2: {
<<<<<<< HEAD
StorageDead(_6); // scope 0 at $DIR/lower_intrinsics.rs:+2:44: +2:45
StorageDead(_7); // scope 0 at $DIR/lower_intrinsics.rs:+2:45: +2:46
StorageDead(_5); // scope 0 at $DIR/lower_intrinsics.rs:+2:45: +2:46
StorageLive(_9); // scope 0 at $DIR/lower_intrinsics.rs:+3:5: +3:46
StorageLive(_10); // scope 0 at $DIR/lower_intrinsics.rs:+3:42: +3:45
StorageLive(_11); // scope 0 at $DIR/lower_intrinsics.rs:+3:42: +3:45
_18 = const discriminant::<T>::promoted[1]; // scope 0 at $DIR/lower_intrinsics.rs:+3:42: +3:45
=======
StorageDead(_6); // scope 0 at $DIR/lower_intrinsics.rs:75:44: 75:45
StorageDead(_7); // scope 0 at $DIR/lower_intrinsics.rs:75:45: 75:46
StorageDead(_5); // scope 0 at $DIR/lower_intrinsics.rs:75:45: 75:46
StorageLive(_9); // scope 0 at $DIR/lower_intrinsics.rs:76:5: 76:46
StorageLive(_10); // scope 0 at $DIR/lower_intrinsics.rs:76:42: 76:45
StorageLive(_11); // scope 0 at $DIR/lower_intrinsics.rs:76:42: 76:45
_18 = const _; // scope 0 at $DIR/lower_intrinsics.rs:76:42: 76:45
>>>>>>> 631a70cb406 (bless tests)
_18 = const _; // scope 0 at $DIR/lower_intrinsics.rs:+3:42: +3:45
// mir::Constant
// + span: $DIR/lower_intrinsics.rs:51:42: 51:45
// + literal: Const { ty: &(), val: Unevaluated(discriminant, [T], Some(promoted[1])) }
@ -90,23 +80,13 @@
}
bb3: {
<<<<<<< HEAD
StorageDead(_10); // scope 0 at $DIR/lower_intrinsics.rs:+3:45: +3:46
StorageDead(_11); // scope 0 at $DIR/lower_intrinsics.rs:+3:46: +3:47
StorageDead(_9); // scope 0 at $DIR/lower_intrinsics.rs:+3:46: +3:47
StorageLive(_13); // scope 0 at $DIR/lower_intrinsics.rs:+4:5: +4:48
StorageLive(_14); // scope 0 at $DIR/lower_intrinsics.rs:+4:42: +4:47
StorageLive(_15); // scope 0 at $DIR/lower_intrinsics.rs:+4:42: +4:47
_17 = const discriminant::<T>::promoted[0]; // scope 0 at $DIR/lower_intrinsics.rs:+4:42: +4:47
=======
StorageDead(_10); // scope 0 at $DIR/lower_intrinsics.rs:76:45: 76:46
StorageDead(_11); // scope 0 at $DIR/lower_intrinsics.rs:76:46: 76:47
StorageDead(_9); // scope 0 at $DIR/lower_intrinsics.rs:76:46: 76:47
StorageLive(_13); // scope 0 at $DIR/lower_intrinsics.rs:77:5: 77:48
StorageLive(_14); // scope 0 at $DIR/lower_intrinsics.rs:77:42: 77:47
StorageLive(_15); // scope 0 at $DIR/lower_intrinsics.rs:77:42: 77:47
_17 = const _; // scope 0 at $DIR/lower_intrinsics.rs:77:42: 77:47
>>>>>>> 631a70cb406 (bless tests)
_17 = const _; // scope 0 at $DIR/lower_intrinsics.rs:+4:42: +4:47
// mir::Constant
// + span: $DIR/lower_intrinsics.rs:52:42: 52:47
// + literal: Const { ty: &E, val: Unevaluated(discriminant, [T], Some(promoted[0])) }

View File

@ -51,7 +51,7 @@ fn full_tested_match() -> () {
bb5: {
StorageLive(_6); // scope 0 at $DIR/match_false_edges.rs:+2:14: +2:15
_11 = const full_tested_match::promoted[0]; // scope 0 at $DIR/match_false_edges.rs:+2:14: +2:15
_11 = const _; // scope 0 at $DIR/match_false_edges.rs:+2:14: +2:15
// mir::Constant
// + span: $DIR/match_false_edges.rs:14:14: 14:15
// + literal: Const { ty: &Option<i32>, val: Unevaluated(full_tested_match, [], Some(promoted[0])) }

View File

@ -142,7 +142,7 @@ fn main() -> () {
Retag(_20); // scope 7 at $DIR/retag.rs:+18:5: +18:24
StorageLive(_22); // scope 7 at $DIR/retag.rs:+18:21: +18:23
StorageLive(_23); // scope 7 at $DIR/retag.rs:+18:21: +18:23
_28 = const main::promoted[0]; // scope 7 at $DIR/retag.rs:+18:21: +18:23
_28 = const _; // scope 7 at $DIR/retag.rs:+18:21: +18:23
// mir::Constant
// + span: $DIR/retag.rs:48:21: 48:23
// + literal: Const { ty: &i32, val: Unevaluated(main, [], Some(promoted[0])) }