]> git.lizzy.rs Git - rust.git/commitdiff
Better handling of ref types equality in write_cvalue
authorbjorn3 <bjorn3@users.noreply.github.com>
Fri, 29 Jun 2018 16:57:59 +0000 (18:57 +0200)
committerbjorn3 <bjorn3@users.noreply.github.com>
Sun, 15 Jul 2018 18:11:49 +0000 (20:11 +0200)
src/common.rs

index cf08ddc281a7bffa9136d1231d9801f79497c15b..83f992380c0c51036ab3e2f175266734d1aba8c0 100644 (file)
@@ -192,12 +192,28 @@ pub fn expect_addr(self) -> Value {
     }
 
     pub fn write_cvalue(self, fx: &mut FunctionCx<'a, 'tcx>, from: CValue<'tcx>) {
-        assert_eq!(
-            self.layout().ty, from.layout().ty,
-            "Can't write value of incompatible type to place {:?} {:?}\n\n{:#?}",
-            self.layout().ty.sty, from.layout().ty.sty,
-            fx,
-        );
+        match (&self.layout().ty.sty, &from.layout().ty.sty) {
+            (TypeVariants::TyRef(_, t, dest_mut), TypeVariants::TyRef(_, u, src_mut)) if (
+                if *dest_mut != ::rustc::hir::Mutability::MutImmutable && src_mut != dest_mut {
+                    false
+                } else if t != u {
+                    false
+                } else {
+                    true
+                }
+            ) => {
+                // &mut T -> &T is allowed
+                // &'a T -> &'b T is allowed
+            }
+            _ => {
+                assert_eq!(
+                    self.layout().ty, from.layout().ty,
+                    "Can't write value of incompatible type to place {:?} {:?}\n\n{:#?}",
+                    self.layout().ty.sty, from.layout().ty.sty,
+                    fx,
+                );
+            }
+        }
 
         match self {
             CPlace::Var(var, _) => {