@@ -288,64 +288,47 @@ pub fn get_dataptr(bcx: Block, fat_ptr: ValueRef) -> ValueRef {
288
288
// Retrieve the information we are losing (making dynamic) in an unsizing
289
289
// adjustment.
290
290
//
291
- // When making a dtor, we need to do different things depending on the
292
- // ownership of the object.. mk_ty is a function for turning `unadjusted_ty`
293
- // into a type to be destructed. If we want to end up with a Box pointer,
294
- // then mk_ty should make a Box pointer (T -> Box<T>), if we want a
295
- // borrowed reference then it should be T -> &T.
296
- //
297
291
// The `unadjusted_val` argument is a bit funny. It is intended
298
292
// for use in an upcast, where the new vtable for an object will
299
293
// be drived from the old one. Hence it is a pointer to the fat
300
294
// pointer.
301
- pub fn unsized_info_bcx < ' blk , ' tcx , F > ( bcx : Block < ' blk , ' tcx > ,
302
- kind : & ty:: UnsizeKind < ' tcx > ,
303
- id : ast:: NodeId ,
304
- unadjusted_ty : Ty < ' tcx > ,
305
- unadjusted_val : ValueRef , // see above (*)
306
- param_substs : & ' tcx subst:: Substs < ' tcx > ,
307
- mk_ty : F )
308
- -> ValueRef
309
- where F : FnOnce ( Ty < ' tcx > ) -> Ty < ' tcx >
310
- {
295
+ pub fn unsized_info_bcx < ' blk , ' tcx > ( bcx : Block < ' blk , ' tcx > ,
296
+ kind : & ty:: UnsizeKind < ' tcx > ,
297
+ id : ast:: NodeId ,
298
+ unadjusted_ty : Ty < ' tcx > ,
299
+ unadjusted_val : ValueRef , // see above (*)
300
+ param_substs : & ' tcx subst:: Substs < ' tcx > )
301
+ -> ValueRef {
311
302
unsized_info (
312
303
bcx. ccx ( ) ,
313
304
kind,
314
305
id,
315
306
unadjusted_ty,
316
307
param_substs,
317
- mk_ty,
318
308
|| Load ( bcx, GEPi ( bcx, unadjusted_val, & [ 0 , abi:: FAT_PTR_EXTRA ] ) ) )
319
309
}
320
310
321
311
// Same as `unsize_info_bcx`, but does not require a bcx -- instead it
322
312
// takes an extra closure to compute the upcast vtable.
323
- pub fn unsized_info < ' ccx , ' tcx , MK_TY , MK_UPCAST_VTABLE > (
313
+ pub fn unsized_info < ' ccx , ' tcx , MK_UPCAST_VTABLE > (
324
314
ccx : & CrateContext < ' ccx , ' tcx > ,
325
315
kind : & ty:: UnsizeKind < ' tcx > ,
326
316
id : ast:: NodeId ,
327
317
unadjusted_ty : Ty < ' tcx > ,
328
318
param_substs : & ' tcx subst:: Substs < ' tcx > ,
329
- mk_ty : MK_TY ,
330
319
mk_upcast_vtable : MK_UPCAST_VTABLE ) // see notes above
331
320
-> ValueRef
332
- where MK_TY : FnOnce ( Ty < ' tcx > ) -> Ty < ' tcx > ,
333
- MK_UPCAST_VTABLE : FnOnce ( ) -> ValueRef ,
321
+ where MK_UPCAST_VTABLE : FnOnce ( ) -> ValueRef
334
322
{
335
- // FIXME(#19596) workaround: `|t| t` causes monomorphization recursion
336
- fn identity < T > ( t : T ) -> T { t }
337
-
338
323
debug ! ( "unsized_info(kind={:?}, id={}, unadjusted_ty={})" ,
339
324
kind, id, unadjusted_ty. repr( ccx. tcx( ) ) ) ;
340
325
match kind {
341
326
& ty:: UnsizeLength ( len) => C_uint ( ccx, len) ,
342
327
& ty:: UnsizeStruct ( box ref k, tp_index) => match unadjusted_ty. sty {
343
328
ty:: ty_struct( _, ref substs) => {
344
329
let ty_substs = substs. types . get_slice ( subst:: TypeSpace ) ;
345
- // The dtor for a field treats it like a value, so mk_ty
346
- // should just be the identity function.
347
330
unsized_info ( ccx, k, id, ty_substs[ tp_index] , param_substs,
348
- identity , mk_upcast_vtable)
331
+ mk_upcast_vtable)
349
332
}
350
333
_ => ccx. sess ( ) . bug ( & format ! ( "UnsizeStruct with bad sty: {}" ,
351
334
unadjusted_ty. repr( ccx. tcx( ) ) ) )
@@ -359,8 +342,7 @@ pub fn unsized_info<'ccx, 'tcx, MK_TY, MK_UPCAST_VTABLE>(
359
342
let trait_ref = monomorphize:: apply_param_substs ( ccx. tcx ( ) ,
360
343
param_substs,
361
344
& trait_ref) ;
362
- let box_ty = mk_ty ( unadjusted_ty) ;
363
- consts:: ptrcast ( meth:: get_vtable ( ccx, box_ty, trait_ref, param_substs) ,
345
+ consts:: ptrcast ( meth:: get_vtable ( ccx, trait_ref, param_substs) ,
364
346
Type :: vtable_ptr ( ccx) )
365
347
}
366
348
& ty:: UnsizeUpcast ( _) => {
@@ -498,8 +480,7 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
498
480
let unsized_ty = ty:: unsize_ty ( tcx, datum_ty, k, expr. span ) ;
499
481
debug ! ( "unsized_ty={}" , unsized_ty. repr( bcx. tcx( ) ) ) ;
500
482
501
- let info = unsized_info_bcx ( bcx, k, expr. id , datum_ty, datum. val , bcx. fcx . param_substs ,
502
- |t| ty:: mk_imm_rptr ( tcx, tcx. mk_region ( ty:: ReStatic ) , t) ) ;
483
+ let info = unsized_info_bcx ( bcx, k, expr. id , datum_ty, datum. val , bcx. fcx . param_substs ) ;
503
484
504
485
// Arrange cleanup
505
486
let lval = unpack_datum ! ( bcx, datum. to_lvalue_datum( bcx, "into_fat_ptr" , expr. id) ) ;
@@ -590,8 +571,7 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
590
571
let base = PointerCast ( bcx, get_dataptr ( bcx, scratch. val ) , llbox_ty. ptr_to ( ) ) ;
591
572
bcx = datum. store_to ( bcx, base) ;
592
573
593
- let info = unsized_info_bcx ( bcx, k, expr. id , unboxed_ty, base, bcx. fcx . param_substs ,
594
- |t| ty:: mk_uniq ( tcx, t) ) ;
574
+ let info = unsized_info_bcx ( bcx, k, expr. id , unboxed_ty, base, bcx. fcx . param_substs ) ;
595
575
Store ( bcx, info, get_len ( bcx, scratch. val ) ) ;
596
576
597
577
DatumBlock :: new ( bcx, scratch. to_expr_datum ( ) )
@@ -888,10 +868,7 @@ fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
888
868
}
889
869
} ;
890
870
891
- let vt =
892
- tvec:: vec_types ( bcx,
893
- ty:: sequence_element_type ( bcx. tcx ( ) ,
894
- base_datum. ty ) ) ;
871
+ let unit_ty = ty:: sequence_element_type ( bcx. tcx ( ) , base_datum. ty ) ;
895
872
896
873
let ( base, len) = base_datum. get_vec_base_and_len ( bcx) ;
897
874
@@ -916,8 +893,8 @@ fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
916
893
len)
917
894
} ) ;
918
895
let elt = InBoundsGEP ( bcx, base, & [ ix_val] ) ;
919
- let elt = PointerCast ( bcx, elt, vt . llunit_ty . ptr_to ( ) ) ;
920
- Datum :: new ( elt, vt . unit_ty , LvalueExpr )
896
+ let elt = PointerCast ( bcx, elt, type_of :: type_of ( ccx , unit_ty ) . ptr_to ( ) ) ;
897
+ Datum :: new ( elt, unit_ty, LvalueExpr )
921
898
}
922
899
} ;
923
900
0 commit comments