Skip to content

Commit f5fb34c

Browse files
committed
Make const eval not use the hacky op_to_const function
1 parent a5a5ef1 commit f5fb34c

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/librustc_mir/const_eval.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,6 @@ fn validate_and_turn_into_const<'a, 'tcx>(
523523
constant: RawConst<'tcx>,
524524
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
525525
) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> {
526-
let cid = key.value;
527526
let ecx = mk_eval_cx(tcx, tcx.def_span(key.value.instance.def_id()), key.param_env);
528527
let val = (|| {
529528
let op = ecx.raw_const_to_mplace(constant)?.into();
@@ -539,9 +538,17 @@ fn validate_and_turn_into_const<'a, 'tcx>(
539538
)?;
540539
}
541540
// Now that we validated, turn this into a proper constant.
542-
let def_id = cid.instance.def.def_id();
543-
let normalize = tcx.is_static(def_id).is_none() && cid.promoted.is_none();
544-
op_to_const(&ecx, op, normalize)
541+
let val = match op.layout.abi {
542+
layout::Abi::Scalar(..) => ConstValue::Scalar(ecx.read_immediate(op)?.to_scalar()?),
543+
layout::Abi::ScalarPair(..) if op.layout.ty.is_slice() => {
544+
let (a, b) = ecx.read_immediate(op)?.to_scalar_pair()?;
545+
ConstValue::Slice(a, b.to_usize(&ecx)?)
546+
},
547+
_ => ConstValue::ByRef,
548+
};
549+
let ptr = Pointer::from(constant.alloc_id);
550+
let alloc = constant.alloc;
551+
Ok(ty::Const { val, ty: op.layout.ty, alloc: Some((alloc, ptr))})
545552
})();
546553

547554
val.map_err(|error| {

0 commit comments

Comments
 (0)