]> git.lizzy.rs Git - rust.git/commitdiff
[const-prop] Replace `Cast` handling with use of `InterpCx`
authorWesley Wiser <wwiser@gmail.com>
Fri, 6 Sep 2019 01:42:30 +0000 (21:42 -0400)
committerWesley Wiser <wwiser@gmail.com>
Sat, 28 Sep 2019 00:11:12 +0000 (20:11 -0400)
src/librustc_mir/transform/const_prop.rs
src/test/mir-opt/const_prop/reify_fn_ptr.rs

index d92eb4706bb28374d0e4b04409b0457d84545394..e1a2d1693199885fdd9446aae73b9312913fb55b 100644 (file)
@@ -24,7 +24,7 @@
 
 use crate::interpret::{
     self, InterpCx, ScalarMaybeUndef, Immediate, OpTy,
-    ImmTy, MemoryKind, StackPopCleanup, LocalValue, LocalState,
+    ImmTy, StackPopCleanup, LocalValue, LocalState,
 };
 use crate::const_eval::{
     CompileTimeInterpreter, error_to_const_error, mk_eval_cx,
@@ -305,7 +305,8 @@ fn const_prop(
         let span = source_info.span;
         match *rvalue {
             Rvalue::Use(_) |
-            Rvalue::Len(_) => {
+            Rvalue::Len(_) |
+            Rvalue::Cast(..) => {
                 self.use_ecx(source_info, |this| {
                     this.ecx.eval_rvalue_into_place(rvalue, place)?;
                     this.ecx.eval_place_to_op(place, Some(place_layout))
@@ -321,14 +322,6 @@ fn const_prop(
             Rvalue::NullaryOp(NullOp::Box, _) |
             Rvalue::Discriminant(..) => None,
 
-            Rvalue::Cast(kind, ref operand, _) => {
-                let op = self.eval_operand(operand, source_info)?;
-                self.use_ecx(source_info, |this| {
-                    let dest = this.ecx.allocate(place_layout, MemoryKind::Stack);
-                    this.ecx.cast(op, kind, dest.into())?;
-                    Ok(dest.into())
-                })
-            },
             Rvalue::NullaryOp(NullOp::SizeOf, ty) => {
                 type_size_of(self.tcx, self.param_env, ty).and_then(|n| Some(
                     ImmTy::from_uint(
index 7e36b2a6b1b396bc35b8e4813e1e8a4323fc37ee..e9b61690cf89e43b40eda855ca94340cb1a21c93 100644 (file)
@@ -16,7 +16,7 @@ fn main() {
 // START rustc.main.ConstProp.after.mir
 //  bb0: {
 //      ...
-//      _3 = const Scalar(AllocId(1).0x0) : fn();
+//      _3 = const Scalar(AllocId(0).0x0) : fn();
 //      _2 = move _3 as usize (Misc);
 //      ...
 //      _1 = move _2 as *const fn() (Misc);