@@ -19,7 +19,7 @@ use llvm;
19
19
use llvm:: { ValueRef , get_param} ;
20
20
use middle:: lang_items:: ExchangeFreeFnLangItem ;
21
21
use rustc:: ty:: subst:: { Substs } ;
22
- use rustc:: traits;
22
+ use rustc:: { infer , traits} ;
23
23
use rustc:: ty:: { self , Ty , TyCtxt } ;
24
24
use abi:: { Abi , FnType } ;
25
25
use adt;
@@ -92,13 +92,12 @@ pub fn type_needs_drop<'tcx>(tcx: &TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
92
92
tcx. type_needs_drop_given_env ( ty, & tcx. empty_parameter_environment ( ) )
93
93
}
94
94
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 > {
98
97
// Even if there is no dtor for t, there might be one deeper down and we
99
98
// might need to pass in the vtable ptr.
100
99
if !type_is_sized ( tcx, t) {
101
- return ccx . tcx ( ) . erase_regions ( & t) ;
100
+ return tcx. erase_regions ( & t) ;
102
101
}
103
102
104
103
// FIXME (#22815): note that type_needs_drop conservatively
@@ -116,15 +115,18 @@ pub fn get_drop_glue_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
116
115
match t. sty {
117
116
ty:: TyBox ( typ) if !type_needs_drop ( & tcx, typ)
118
117
&& 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.
122
124
tcx. types . i8
123
125
} else {
124
- ccx . tcx ( ) . erase_regions ( & t)
126
+ tcx. erase_regions ( & t)
125
127
}
126
128
}
127
- _ => ccx . tcx ( ) . erase_regions ( & t)
129
+ _ => tcx. erase_regions ( & t)
128
130
}
129
131
}
130
132
@@ -154,7 +156,7 @@ pub fn drop_ty_core<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
154
156
DropGlueKind :: Ty ( t)
155
157
} ;
156
158
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) ;
158
160
let ptr = if glue_type != t {
159
161
PointerCast ( bcx, v, type_of ( ccx, glue_type) . ptr_to ( ) )
160
162
} else {
@@ -231,7 +233,7 @@ impl<'tcx> DropGlueKind<'tcx> {
231
233
fn get_drop_glue_core < ' a , ' tcx > ( ccx : & CrateContext < ' a , ' tcx > ,
232
234
g : DropGlueKind < ' tcx > ) -> ValueRef {
233
235
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) ) ;
235
237
debug ! ( "drop glue type {:?}" , g) ;
236
238
match ccx. drop_glues ( ) . borrow ( ) . get ( & g) {
237
239
Some ( & glue) => return glue,
0 commit comments