about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJames Miller <james@aatch.net>2013-06-25 16:39:56 +1200
committerJames Miller <james@aatch.net>2013-06-25 16:39:56 +1200
commit721164d5ec0c8b617bd72df36830fe1861e6362b (patch)
treed349572dc3bbb8f4c4f21f90706b5c8f56616327
parentd9f6dd263c16a21108c27dbf15a3d59a43a5b490 (diff)
downloadrust-721164d5ec0c8b617bd72df36830fe1861e6362b.tar.gz
rust-721164d5ec0c8b617bd72df36830fe1861e6362b.zip
Zero the struct in the take glue, not the drop glue
-rw-r--r--src/librustc/middle/trans/glue.rs23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs
index 056e5b8cdf7..8ed3112b520 100644
--- a/src/librustc/middle/trans/glue.rs
+++ b/src/librustc/middle/trans/glue.rs
@@ -484,12 +484,6 @@ pub fn trans_struct_drop(mut bcx: block, t: ty::t, v0: ValueRef, dtor_did: ast::
         bcx = drop_ty(bcx, llfld_a, fld.mt.ty);
     }
 
-    // Zero out the struct
-    unsafe {
-        let ty = Type::from_ref(llvm::LLVMTypeOf(v0));
-        memzero(bcx, v0, ty);
-    }
-
     bcx
 }
 
@@ -635,6 +629,23 @@ pub fn make_take_glue(bcx: block, v: ValueRef, t: ty::t) {
       ty::ty_opaque_closure_ptr(ck) => {
         closure::make_opaque_cbox_take_glue(bcx, ck, v)
       }
+      ty::ty_struct(did, ref substs) => {
+        let tcx = bcx.tcx();
+        let bcx = iter_structural_ty(bcx, v, t, take_ty);
+
+        match ty::ty_dtor(tcx, did) {
+          ty::TraitDtor(dtor, false) => {
+            // Zero out the struct
+            unsafe {
+                let ty = Type::from_ref(llvm::LLVMTypeOf(v));
+                memzero(bcx, v, ty);
+            }
+
+          }
+          _ => { }
+        }
+        bcx
+      }
       _ if ty::type_is_structural(t) => {
         iter_structural_ty(bcx, v, t, take_ty)
       }