Skip to content

Commit ecc4cc2

Browse files
committed
[const-prop] Replace Cast handling with use of InterpCx
1 parent 86c7c4d commit ecc4cc2

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

src/librustc_mir/transform/const_prop.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc::ty::layout::{
2424

2525
use crate::interpret::{
2626
self, InterpCx, ScalarMaybeUndef, Immediate, OpTy,
27-
ImmTy, MemoryKind, StackPopCleanup, LocalValue, LocalState,
27+
ImmTy, StackPopCleanup, LocalValue, LocalState,
2828
};
2929
use crate::const_eval::{
3030
CompileTimeInterpreter, error_to_const_error, mk_eval_cx,
@@ -305,7 +305,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
305305
let span = source_info.span;
306306
match *rvalue {
307307
Rvalue::Use(_) |
308-
Rvalue::Len(_) => {
308+
Rvalue::Len(_) |
309+
Rvalue::Cast(..) => {
309310
self.use_ecx(source_info, |this| {
310311
this.ecx.eval_rvalue_into_place(rvalue, place)?;
311312
this.ecx.eval_place_to_op(place, Some(place_layout))
@@ -321,14 +322,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
321322
Rvalue::NullaryOp(NullOp::Box, _) |
322323
Rvalue::Discriminant(..) => None,
323324

324-
Rvalue::Cast(kind, ref operand, _) => {
325-
let op = self.eval_operand(operand, source_info)?;
326-
self.use_ecx(source_info, |this| {
327-
let dest = this.ecx.allocate(place_layout, MemoryKind::Stack);
328-
this.ecx.cast(op, kind, dest.into())?;
329-
Ok(dest.into())
330-
})
331-
},
332325
Rvalue::NullaryOp(NullOp::SizeOf, ty) => {
333326
type_size_of(self.tcx, self.param_env, ty).and_then(|n| Some(
334327
ImmTy::from_uint(

src/test/mir-opt/const_prop/reify_fn_ptr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() {
1616
// START rustc.main.ConstProp.after.mir
1717
// bb0: {
1818
// ...
19-
// _3 = const Scalar(AllocId(1).0x0) : fn();
19+
// _3 = const Scalar(AllocId(0).0x0) : fn();
2020
// _2 = move _3 as usize (Misc);
2121
// ...
2222
// _1 = move _2 as *const fn() (Misc);

0 commit comments

Comments
 (0)