diff options
| author | b-naber <bn263@gmx.de> | 2022-09-14 15:35:24 +0200 |
|---|---|---|
| committer | b-naber <bn263@gmx.de> | 2022-09-14 17:30:25 +0200 |
| commit | 6af8fb793697734bf3e19bcb1b5d152d617bb303 (patch) | |
| tree | ce28e3c0abc38368fba67c76de230c3c54a7792c /compiler/rustc_const_eval | |
| parent | ba00189d8e85b735d90144f9523b8a1dad2ccdce (diff) | |
address review again
Diffstat (limited to 'compiler/rustc_const_eval')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/operand.rs | 25 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs | 2 |
2 files changed, 15 insertions, 12 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index 1d1c0548d17..29c745a0886 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -564,8 +564,16 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { throw_inval!(AlreadyReported(reported)) } ty::ConstKind::Unevaluated(uv) => { + // NOTE: We evaluate to a `ValTree` here as a check to ensure + // we're working with valid constants, even though we never need it. let instance = self.resolve(uv.def, uv.substs)?; - Ok(self.eval_to_allocation(GlobalId { instance, promoted: None })?.into()) + let cid = GlobalId { instance, promoted: None }; + let _valtree = self + .tcx + .eval_to_valtree(self.param_env.and(cid))? + .unwrap_or_else(|| bug!("unable to create ValTree for {:?}", uv)); + + Ok(self.eval_to_allocation(cid)?.into()) } ty::ConstKind::Bound(..) | ty::ConstKind::Infer(..) => { span_bug!(self.cur_span(), "const_to_op: Unexpected ConstKind {:?}", c) @@ -578,16 +586,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } } - /// Tries to evaluate an unevaluated constant from the MIR (and not the type-system). - #[inline] - pub fn uneval_to_op( - &self, - uneval: &ty::Unevaluated<'tcx>, - ) -> 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()) - } - pub fn mir_const_to_op( &self, val: &mir::ConstantKind<'tcx>, @@ -596,7 +594,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { match val { mir::ConstantKind::Ty(ct) => self.const_to_op(*ct, layout), mir::ConstantKind::Val(val, ty) => self.const_val_to_op(*val, *ty, layout), - mir::ConstantKind::Unevaluated(uv, _) => self.uneval_to_op(uv), + mir::ConstantKind::Unevaluated(uv, _) => { + let instance = self.resolve(uv.def, uv.substs)?; + Ok(self.eval_to_allocation(GlobalId { instance, promoted: uv.promoted })?.into()) + } } } diff --git a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs index 23a013980be..6c73ef5a8fa 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs @@ -346,6 +346,8 @@ where }; // Check the qualifs of the value of `const` items. + // FIXME(valtrees): check whether const qualifs should behave the same + // way for type and mir constants. let uneval = match constant.literal { ConstantKind::Ty(ct) if matches!(ct.kind(), ty::ConstKind::Unevaluated(_)) => { let ty::ConstKind::Unevaluated(uv) = ct.kind() else { unreachable!() }; |
