Skip to content

Commit a7a011d

Browse files
committed
Immediately evaluate and validate constants when we want them as operands
1 parent 0e969b7 commit a7a011d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/librustc_mir/interpret/operand.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,9 +578,16 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
578578
ty::ConstKind::Param(_) => throw_inval!(TooGeneric),
579579
ty::ConstKind::Unevaluated(def_id, substs) => {
580580
let instance = self.resolve(def_id, substs)?;
581-
// FIXME: don't use `const_eval_raw` for regular constants, instead use `const_eval`
582-
// which immediately validates the result before we continue with it here.
583-
return Ok(OpTy::from(self.const_eval_raw(GlobalId { instance, promoted: None })?));
581+
let param_env = if self.tcx.is_static(def_id) {
582+
ty::ParamEnv::reveal_all()
583+
} else {
584+
self.param_env
585+
};
586+
let val =
587+
self.tcx.const_eval(param_env.and(GlobalId { instance, promoted: None }))?;
588+
// "recurse". This is only ever going into a recusion depth of 1, because after
589+
// `const_eval` we don't have `Unevaluated` anymore.
590+
return self.eval_const_to_op(val, layout);
584591
}
585592
ty::ConstKind::Value(val_val) => val_val,
586593
};

0 commit comments

Comments
 (0)