Skip to content

Commit 64bb77f

Browse files
committed
Immediately evaluate and validate constants when we want them as operands
1 parent 03999ce commit 64bb77f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/librustc_mir/interpret/operand.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,18 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
584584
throw_inval!(TooGeneric),
585585
ty::ConstKind::Unevaluated(def_id, substs) => {
586586
let instance = self.resolve(def_id, substs)?;
587-
// FIXME: don't use `const_eval_raw` for regular constants, instead use `const_eval`
588-
// which immediately validates the result before we continue with it here.
589-
return Ok(OpTy::from(self.const_eval_raw(GlobalId {
587+
let param_env = if self.tcx.is_static(def_id) {
588+
ty::ParamEnv::reveal_all()
589+
} else {
590+
self.param_env
591+
};
592+
let val = self.tcx.const_eval(param_env.and(GlobalId {
590593
instance,
591594
promoted: None,
592-
})?));
595+
}))?;
596+
// "recurse". This is only ever going into a recusion depth of 1, because after
597+
// `const_eval` we don't have `Unevaluated` anymore.
598+
return self.eval_const_to_op(val, layout);
593599
}
594600
ty::ConstKind::Infer(..) |
595601
ty::ConstKind::Bound(..) |

0 commit comments

Comments
 (0)