Skip to content

Commit 76ddede

Browse files
committed
Reintroduce some sanity checks
1 parent 8b99c61 commit 76ddede

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/librustc_mir/interpret/const_eval.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ pub fn value_to_const_value<'tcx>(
9898
mut val: Value,
9999
ty: Ty<'tcx>,
100100
) -> &'tcx ty::Const<'tcx> {
101+
let layout = tcx.layout_of(ty::ParamEnv::reveal_all().and(ty)).unwrap();
102+
match (val, &layout.abi) {
103+
(Value::ByRef(..), _) |
104+
(Value::ByVal(_), &layout::Abi::Scalar(_)) |
105+
(Value::ByValPair(..), &layout::Abi::ScalarPair(..)) => {},
106+
_ => bug!("bad value/layout combo: {:#?}, {:#?}", val, layout),
107+
}
101108
let val = (|| {
102109
// Convert to ByVal or ByValPair if possible
103110
if let Value::ByRef(ptr, align) = val {

src/librustc_mir/interpret/eval_context.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,10 +1416,6 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
14161416
let layout = self.layout_of(ty)?;
14171417
self.memory.check_align(ptr, ptr_align)?;
14181418

1419-
if layout.size.bytes() == 0 {
1420-
return Ok(Some(Value::ByVal(PrimVal::Undef)));
1421-
}
1422-
14231419
let ptr = ptr.to_ptr()?;
14241420

14251421
// Not the right place to do this

0 commit comments

Comments
 (0)