about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-08-12 08:13:35 +0000
committerbors <bors@rust-lang.org>2015-08-12 08:13:35 +0000
commit2b45a0d90853deca584a28a55237d996a274a833 (patch)
treeef9ebf2ca8197982da800a694cab6e164143a1d6
parent542d56ea91f403c5d7eb9511848509e5ddb8e05e (diff)
parentf804872502587290dcab42eda35301314173cbd7 (diff)
downloadrust-2b45a0d90853deca584a28a55237d996a274a833.tar.gz
rust-2b45a0d90853deca584a28a55237d996a274a833.zip
Auto merge of #27618 - dotdash:drop_fixes, r=luqmana
-rw-r--r--src/librustc_trans/trans/glue.rs8
-rw-r--r--src/librustc_trans/trans/type_of.rs7
-rw-r--r--src/test/auxiliary/fat_drop.rs23
-rw-r--r--src/test/run-pass/extern_fat_drop.rs23
4 files changed, 53 insertions, 8 deletions
diff --git a/src/librustc_trans/trans/glue.rs b/src/librustc_trans/trans/glue.rs
index cf3cde8907f..fe20ae2cf39 100644
--- a/src/librustc_trans/trans/glue.rs
+++ b/src/librustc_trans/trans/glue.rs
@@ -324,7 +324,6 @@ fn trans_struct_drop_flag<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
 
 pub fn get_res_dtor<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
                               did: ast::DefId,
-                              t: Ty<'tcx>,
                               parent_id: ast::DefId,
                               substs: &Substs<'tcx>)
                               -> ValueRef {
@@ -347,11 +346,8 @@ pub fn get_res_dtor<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
         let name = csearch::get_symbol(&ccx.sess().cstore, did);
         let class_ty = tcx.lookup_item_type(parent_id).ty.subst(tcx, substs);
         let llty = type_of_dtor(ccx, class_ty);
-        let dtor_ty = ccx.tcx().mk_ctor_fn(did,
-                                           &[get_drop_glue_type(ccx, t)],
-                                           ccx.tcx().mk_nil());
         foreign::get_extern_fn(ccx, &mut *ccx.externs().borrow_mut(), &name[..], llvm::CCallConv,
-                               llty, dtor_ty)
+                               llty, ccx.tcx().mk_nil())
     }
 }
 
@@ -366,7 +362,7 @@ fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
     debug!("trans_struct_drop t: {}", t);
 
     // Find and call the actual destructor
-    let dtor_addr = get_res_dtor(bcx.ccx(), dtor_did, t, class_did, substs);
+    let dtor_addr = get_res_dtor(bcx.ccx(), dtor_did, class_did, substs);
 
     // Class dtors have no explicit args, so the params should
     // just consist of the environment (self).
diff --git a/src/librustc_trans/trans/type_of.rs b/src/librustc_trans/trans/type_of.rs
index 0b969360f53..5991d61a1e4 100644
--- a/src/librustc_trans/trans/type_of.rs
+++ b/src/librustc_trans/trans/type_of.rs
@@ -472,6 +472,9 @@ fn llvm_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
 }
 
 pub fn type_of_dtor<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, self_ty: Ty<'tcx>) -> Type {
-    let self_ty = type_of(ccx, self_ty).ptr_to();
-    Type::func(&[self_ty], &Type::void(ccx))
+    if type_is_sized(ccx.tcx(), self_ty) {
+        Type::func(&[type_of(ccx, self_ty).ptr_to()], &Type::void(ccx))
+    } else {
+        Type::func(&type_of(ccx, self_ty).field_types(), &Type::void(ccx))
+    }
 }
diff --git a/src/test/auxiliary/fat_drop.rs b/src/test/auxiliary/fat_drop.rs
new file mode 100644
index 00000000000..1f944b6ed32
--- /dev/null
+++ b/src/test/auxiliary/fat_drop.rs
@@ -0,0 +1,23 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub static mut DROPPED: bool = false;
+
+pub struct S {
+    _unsized: [u8]
+}
+
+impl Drop for S {
+    fn drop(&mut self) {
+        unsafe {
+            DROPPED = true;
+        }
+    }
+}
diff --git a/src/test/run-pass/extern_fat_drop.rs b/src/test/run-pass/extern_fat_drop.rs
new file mode 100644
index 00000000000..f587dc7821d
--- /dev/null
+++ b/src/test/run-pass/extern_fat_drop.rs
@@ -0,0 +1,23 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:fat_drop.rs
+
+#![feature(core_intrinsics)]
+
+extern crate fat_drop;
+
+fn main() {
+    unsafe {
+        let s: &mut fat_drop::S = std::mem::uninitialized();
+        std::intrinsics::drop_in_place(s);
+        assert!(fat_drop::DROPPED);
+    }
+}