about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc_trans/collector.rs14
-rw-r--r--src/librustc_trans/glue.rs26
-rw-r--r--src/librustc_trans/mir/block.rs2
3 files changed, 22 insertions, 20 deletions
diff --git a/src/librustc_trans/collector.rs b/src/librustc_trans/collector.rs
index 5258bdf5d3c..ac42eb0ee62 100644
--- a/src/librustc_trans/collector.rs
+++ b/src/librustc_trans/collector.rs
@@ -390,7 +390,7 @@ fn collect_items_rec<'a, 'tcx: 'a>(ccx: &CrateContext<'a, 'tcx>,
         TransItem::Static(node_id) => {
             let def_id = ccx.tcx().map.local_def_id(node_id);
             let ty = ccx.tcx().lookup_item_type(def_id).ty;
-            let ty = glue::get_drop_glue_type(ccx, ty);
+            let ty = glue::get_drop_glue_type(ccx.tcx(), ty);
             neighbors.push(TransItem::DropGlue(DropGlueKind::Ty(ty)));
             recursion_depth_reset = None;
         }
@@ -554,7 +554,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
                                                       self.param_substs,
                                                       &ty);
             let ty = self.ccx.tcx().erase_regions(&ty);
-            let ty = glue::get_drop_glue_type(self.ccx, ty);
+            let ty = glue::get_drop_glue_type(self.ccx.tcx(), ty);
             self.output.push(TransItem::DropGlue(DropGlueKind::Ty(ty)));
         }
 
@@ -740,7 +740,7 @@ fn find_drop_glue_neighbors<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
                 let field_type = monomorphize::apply_param_substs(ccx.tcx(),
                                                                   substs,
                                                                   &field.unsubst_ty());
-                let field_type = glue::get_drop_glue_type(ccx, field_type);
+                let field_type = glue::get_drop_glue_type(ccx.tcx(), field_type);
 
                 if glue::type_needs_drop(ccx.tcx(), field_type) {
                     output.push(TransItem::DropGlue(DropGlueKind::Ty(field_type)));
@@ -749,7 +749,7 @@ fn find_drop_glue_neighbors<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
         }
         ty::TyClosure(_, ref substs) => {
             for upvar_ty in &substs.upvar_tys {
-                let upvar_ty = glue::get_drop_glue_type(ccx, upvar_ty);
+                let upvar_ty = glue::get_drop_glue_type(ccx.tcx(), upvar_ty);
                 if glue::type_needs_drop(ccx.tcx(), upvar_ty) {
                     output.push(TransItem::DropGlue(DropGlueKind::Ty(upvar_ty)));
                 }
@@ -757,14 +757,14 @@ fn find_drop_glue_neighbors<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
         }
         ty::TyBox(inner_type)      |
         ty::TyArray(inner_type, _) => {
-            let inner_type = glue::get_drop_glue_type(ccx, inner_type);
+            let inner_type = glue::get_drop_glue_type(ccx.tcx(), inner_type);
             if glue::type_needs_drop(ccx.tcx(), inner_type) {
                 output.push(TransItem::DropGlue(DropGlueKind::Ty(inner_type)));
             }
         }
         ty::TyTuple(ref args) => {
             for arg in args {
-                let arg = glue::get_drop_glue_type(ccx, arg);
+                let arg = glue::get_drop_glue_type(ccx.tcx(), arg);
                 if glue::type_needs_drop(ccx.tcx(), arg) {
                     output.push(TransItem::DropGlue(DropGlueKind::Ty(arg)));
                 }
@@ -1079,7 +1079,7 @@ impl<'b, 'a, 'v> hir_visit::Visitor<'v> for RootCollector<'b, 'a, 'v> {
                                def_id_to_string(self.ccx.tcx(),
                                                 self.ccx.tcx().map.local_def_id(item.id)));
 
-                        let ty = glue::get_drop_glue_type(self.ccx, ty);
+                        let ty = glue::get_drop_glue_type(self.ccx.tcx(), ty);
                         self.output.push(TransItem::DropGlue(DropGlueKind::Ty(ty)));
                     }
                 }
diff --git a/src/librustc_trans/glue.rs b/src/librustc_trans/glue.rs
index 06f9000c4ba..e83580b95bc 100644
--- a/src/librustc_trans/glue.rs
+++ b/src/librustc_trans/glue.rs
@@ -19,7 +19,7 @@ use llvm;
 use llvm::{ValueRef, get_param};
 use middle::lang_items::ExchangeFreeFnLangItem;
 use rustc::ty::subst::{Substs};
-use rustc::traits;
+use rustc::{infer, traits};
 use rustc::ty::{self, Ty, TyCtxt};
 use abi::{Abi, FnType};
 use adt;
@@ -92,13 +92,12 @@ pub fn type_needs_drop<'tcx>(tcx: &TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
     tcx.type_needs_drop_given_env(ty, &tcx.empty_parameter_environment())
 }
 
-pub fn get_drop_glue_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
-                                    t: Ty<'tcx>) -> Ty<'tcx> {
-    let tcx = ccx.tcx();
+pub fn get_drop_glue_type<'tcx>(tcx: &TyCtxt<'tcx>,
+                                t: Ty<'tcx>) -> Ty<'tcx> {
     // Even if there is no dtor for t, there might be one deeper down and we
     // might need to pass in the vtable ptr.
     if !type_is_sized(tcx, t) {
-        return ccx.tcx().erase_regions(&t);
+        return tcx.erase_regions(&t);
     }
 
     // FIXME (#22815): note that type_needs_drop conservatively
@@ -116,15 +115,18 @@ pub fn get_drop_glue_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
     match t.sty {
         ty::TyBox(typ) if !type_needs_drop(&tcx, typ)
                          && type_is_sized(tcx, typ) => {
-            let llty = sizing_type_of(ccx, typ);
-            // `Box<ZeroSizeType>` does not allocate.
-            if llsize_of_alloc(ccx, llty) == 0 {
+            let infcx = infer::normalizing_infer_ctxt(tcx,
+                                                      &tcx.tables,
+                                                      traits::ProjectionMode::Any);
+            let layout = t.layout(&infcx).unwrap();
+            if layout.size(&tcx.data_layout).bytes() == 0 {
+                // `Box<ZeroSizeType>` does not allocate.
                 tcx.types.i8
             } else {
-                ccx.tcx().erase_regions(&t)
+                tcx.erase_regions(&t)
             }
         }
-        _ => ccx.tcx().erase_regions(&t)
+        _ => tcx.erase_regions(&t)
     }
 }
 
@@ -154,7 +156,7 @@ pub fn drop_ty_core<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
             DropGlueKind::Ty(t)
         };
         let glue = get_drop_glue_core(ccx, g);
-        let glue_type = get_drop_glue_type(ccx, t);
+        let glue_type = get_drop_glue_type(ccx.tcx(), t);
         let ptr = if glue_type != t {
             PointerCast(bcx, v, type_of(ccx, glue_type).ptr_to())
         } else {
@@ -231,7 +233,7 @@ impl<'tcx> DropGlueKind<'tcx> {
 fn get_drop_glue_core<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
                                 g: DropGlueKind<'tcx>) -> ValueRef {
     debug!("make drop glue for {:?}", g);
-    let g = g.map_ty(|t| get_drop_glue_type(ccx, t));
+    let g = g.map_ty(|t| get_drop_glue_type(ccx.tcx(), t));
     debug!("drop glue type {:?}", g);
     match ccx.drop_glues().borrow().get(&g) {
         Some(&glue) => return glue,
diff --git a/src/librustc_trans/mir/block.rs b/src/librustc_trans/mir/block.rs
index e605ef81c58..39bf0da5cf9 100644
--- a/src/librustc_trans/mir/block.rs
+++ b/src/librustc_trans/mir/block.rs
@@ -136,7 +136,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
                     return;
                 }
                 let drop_fn = glue::get_drop_glue(bcx.ccx(), ty);
-                let drop_ty = glue::get_drop_glue_type(bcx.ccx(), ty);
+                let drop_ty = glue::get_drop_glue_type(bcx.tcx(), ty);
                 let llvalue = if drop_ty != ty {
                     bcx.pointercast(lvalue.llval, type_of::type_of(bcx.ccx(), drop_ty).ptr_to())
                 } else {