@@ -19,7 +19,7 @@ use llvm;
1919use llvm:: { ValueRef , get_param} ;
2020use middle:: lang_items:: ExchangeFreeFnLangItem ;
2121use rustc:: ty:: subst:: { Substs } ;
22- use rustc:: traits;
22+ use rustc:: { infer , traits} ;
2323use rustc:: ty:: { self , Ty , TyCtxt } ;
2424use abi:: { Abi , FnType } ;
2525use adt;
@@ -92,13 +92,12 @@ pub fn type_needs_drop<'tcx>(tcx: &TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
9292 tcx. type_needs_drop_given_env ( ty, & tcx. empty_parameter_environment ( ) )
9393}
9494
95- pub fn get_drop_glue_type < ' a , ' tcx > ( ccx : & CrateContext < ' a , ' tcx > ,
96- t : Ty < ' tcx > ) -> Ty < ' tcx > {
97- let tcx = ccx. tcx ( ) ;
95+ pub fn get_drop_glue_type < ' tcx > ( tcx : & TyCtxt < ' tcx > ,
96+ t : Ty < ' tcx > ) -> Ty < ' tcx > {
9897 // Even if there is no dtor for t, there might be one deeper down and we
9998 // might need to pass in the vtable ptr.
10099 if !type_is_sized ( tcx, t) {
101- return ccx . tcx ( ) . erase_regions ( & t) ;
100+ return tcx. erase_regions ( & t) ;
102101 }
103102
104103 // FIXME (#22815): note that type_needs_drop conservatively
@@ -116,15 +115,18 @@ pub fn get_drop_glue_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
116115 match t. sty {
117116 ty:: TyBox ( typ) if !type_needs_drop ( & tcx, typ)
118117 && type_is_sized ( tcx, typ) => {
119- let llty = sizing_type_of ( ccx, typ) ;
120- // `Box<ZeroSizeType>` does not allocate.
121- if llsize_of_alloc ( ccx, llty) == 0 {
118+ let infcx = infer:: normalizing_infer_ctxt ( tcx,
119+ & tcx. tables ,
120+ traits:: ProjectionMode :: Any ) ;
121+ let layout = t. layout ( & infcx) . unwrap ( ) ;
122+ if layout. size ( & tcx. data_layout ) . bytes ( ) == 0 {
123+ // `Box<ZeroSizeType>` does not allocate.
122124 tcx. types . i8
123125 } else {
124- ccx . tcx ( ) . erase_regions ( & t)
126+ tcx. erase_regions ( & t)
125127 }
126128 }
127- _ => ccx . tcx ( ) . erase_regions ( & t)
129+ _ => tcx. erase_regions ( & t)
128130 }
129131}
130132
@@ -154,7 +156,7 @@ pub fn drop_ty_core<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
154156 DropGlueKind :: Ty ( t)
155157 } ;
156158 let glue = get_drop_glue_core ( ccx, g) ;
157- let glue_type = get_drop_glue_type ( ccx, t) ;
159+ let glue_type = get_drop_glue_type ( ccx. tcx ( ) , t) ;
158160 let ptr = if glue_type != t {
159161 PointerCast ( bcx, v, type_of ( ccx, glue_type) . ptr_to ( ) )
160162 } else {
@@ -231,7 +233,7 @@ impl<'tcx> DropGlueKind<'tcx> {
231233fn get_drop_glue_core < ' a , ' tcx > ( ccx : & CrateContext < ' a , ' tcx > ,
232234 g : DropGlueKind < ' tcx > ) -> ValueRef {
233235 debug ! ( "make drop glue for {:?}" , g) ;
234- let g = g. map_ty ( |t| get_drop_glue_type ( ccx, t) ) ;
236+ let g = g. map_ty ( |t| get_drop_glue_type ( ccx. tcx ( ) , t) ) ;
235237 debug ! ( "drop glue type {:?}" , g) ;
236238 match ccx. drop_glues ( ) . borrow ( ) . get ( & g) {
237239 Some ( & glue) => return glue,
0 commit comments