@@ -99,8 +99,9 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
99
99
} ,
100
100
mir:: Lvalue :: Arg ( index) => self . args [ index as usize ] ,
101
101
mir:: Lvalue :: Static ( def_id) => {
102
- let const_ty = self . mir . lvalue_ty ( tcx, lvalue) ;
103
- LvalueRef :: new_sized ( consts:: get_static ( ccx, def_id) . val , const_ty)
102
+ let const_ty = self . lvalue_ty ( lvalue) ;
103
+ LvalueRef :: new_sized ( consts:: get_static ( ccx, def_id) . val ,
104
+ LvalueTy :: from_ty ( const_ty) )
104
105
} ,
105
106
mir:: Lvalue :: ReturnPointer => {
106
107
let llval = if !fcx. fn_ty . ret . is_ignore ( ) {
@@ -195,7 +196,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
195
196
ty:: TyArray ( ..) => {
196
197
// must cast the lvalue pointer type to the new
197
198
// array type (*[%_; new_len]).
198
- let base_ty = self . mir . lvalue_ty ( tcx , lvalue) . to_ty ( tcx ) ;
199
+ let base_ty = self . lvalue_ty ( lvalue) ;
199
200
let llbasety = type_of:: type_of ( bcx. ccx ( ) , base_ty) . ptr_to ( ) ;
200
201
let llbase = bcx. pointercast ( llbase, llbasety) ;
201
202
( bcx. pointercast ( llbase, llbasety) , ptr:: null_mut ( ) )
@@ -236,27 +237,23 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
236
237
match self . temps [ idx as usize ] {
237
238
TempRef :: Lvalue ( lvalue) => f ( self , lvalue) ,
238
239
TempRef :: Operand ( None ) => {
239
- let lvalue_ty = self . mir . lvalue_ty ( bcx. tcx ( ) , lvalue) ;
240
- let lvalue_ty = bcx. monomorphize ( & lvalue_ty) ;
240
+ let lvalue_ty = self . lvalue_ty ( lvalue) ;
241
241
let lvalue = LvalueRef :: alloca ( bcx,
242
- lvalue_ty. to_ty ( bcx . tcx ( ) ) ,
242
+ lvalue_ty,
243
243
"lvalue_temp" ) ;
244
244
let ret = f ( self , lvalue) ;
245
- let op = self . trans_load ( bcx, lvalue. llval , lvalue_ty. to_ty ( bcx . tcx ( ) ) ) ;
245
+ let op = self . trans_load ( bcx, lvalue. llval , lvalue_ty) ;
246
246
self . temps [ idx as usize ] = TempRef :: Operand ( Some ( op) ) ;
247
247
ret
248
248
}
249
249
TempRef :: Operand ( Some ( _) ) => {
250
- let lvalue_ty = self . mir . lvalue_ty ( bcx. tcx ( ) , lvalue) ;
251
- let lvalue_ty = bcx. monomorphize ( & lvalue_ty) ;
252
-
253
250
// See comments in TempRef::new_operand as to why
254
251
// we always have Some in a ZST TempRef::Operand.
255
- let ty = lvalue_ty . to_ty ( bcx . tcx ( ) ) ;
252
+ let ty = self . lvalue_ty ( lvalue ) ;
256
253
if common:: type_is_zero_size ( bcx. ccx ( ) , ty) {
257
254
// Pass an undef pointer as no stores can actually occur.
258
255
let llptr = C_undef ( type_of ( bcx. ccx ( ) , ty) . ptr_to ( ) ) ;
259
- f ( self , LvalueRef :: new_sized ( llptr, lvalue_ty ) )
256
+ f ( self , LvalueRef :: new_sized ( llptr, LvalueTy :: from_ty ( ty ) ) )
260
257
} else {
261
258
bug ! ( "Lvalue temp already set" ) ;
262
259
}
@@ -290,4 +287,10 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
290
287
llindex
291
288
}
292
289
}
290
+
291
+ pub fn lvalue_ty ( & self , lvalue : & mir:: Lvalue < ' tcx > ) -> Ty < ' tcx > {
292
+ let tcx = self . fcx . ccx . tcx ( ) ;
293
+ let lvalue_ty = self . mir . lvalue_ty ( tcx, lvalue) ;
294
+ self . fcx . monomorphize ( & lvalue_ty. to_ty ( tcx) )
295
+ }
293
296
}
0 commit comments