]> git.lizzy.rs Git - rust.git/commitdiff
Handle Misc casts slightly more sanely.
authorScott Olson <scott@solson.me>
Mon, 13 Jun 2016 03:00:23 +0000 (21:00 -0600)
committerScott Olson <scott@solson.me>
Mon, 13 Jun 2016 03:00:23 +0000 (21:00 -0600)
Still insanely, though.

src/interpreter/mod.rs

index 37113f38731973c8c63d699a8047bed51e609ca5..39dc20bb855ef1795cf27a26bbe2e4c1c4c961cf 100644 (file)
@@ -1045,8 +1045,14 @@ fn eval_assignment(&mut self, lvalue: &mir::Lvalue<'tcx>, rvalue: &mir::Rvalue<'
 
                     Misc => {
                         // FIXME(solson): Wrong for almost everything.
-                        let size = dest_layout.size(&self.tcx.data_layout).bytes() as usize;
-                        self.memory.copy(src, dest, size)?;
+                        let dest_size = self.type_size(dest_ty, self.substs());
+                        let src_size = self.type_size(src_ty, self.substs());
+                        if dest_size == src_size {
+                            warn!("performing fishy cast from {:?} to {:?}", src_ty, dest_ty);
+                            self.memory.copy(src, dest, dest_size)?;
+                        } else {
+                            return Err(EvalError::Unimplemented(format!("can't handle cast: {:?}", rvalue)));
+                        }
                     }
 
                     _ => return Err(EvalError::Unimplemented(format!("can't handle cast: {:?}", rvalue))),