@@ -288,64 +288,47 @@ pub fn get_dataptr(bcx: Block, fat_ptr: ValueRef) -> ValueRef {
288288// Retrieve the information we are losing (making dynamic) in an unsizing
289289// adjustment.
290290//
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- //
297291// The `unadjusted_val` argument is a bit funny. It is intended
298292// for use in an upcast, where the new vtable for an object will
299293// be drived from the old one. Hence it is a pointer to the fat
300294// 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 {
311302 unsized_info (
312303 bcx. ccx ( ) ,
313304 kind,
314305 id,
315306 unadjusted_ty,
316307 param_substs,
317- mk_ty,
318308 || Load ( bcx, GEPi ( bcx, unadjusted_val, & [ 0 , abi:: FAT_PTR_EXTRA ] ) ) )
319309}
320310
321311// Same as `unsize_info_bcx`, but does not require a bcx -- instead it
322312// 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 > (
324314 ccx : & CrateContext < ' ccx , ' tcx > ,
325315 kind : & ty:: UnsizeKind < ' tcx > ,
326316 id : ast:: NodeId ,
327317 unadjusted_ty : Ty < ' tcx > ,
328318 param_substs : & ' tcx subst:: Substs < ' tcx > ,
329- mk_ty : MK_TY ,
330319 mk_upcast_vtable : MK_UPCAST_VTABLE ) // see notes above
331320 -> ValueRef
332- where MK_TY : FnOnce ( Ty < ' tcx > ) -> Ty < ' tcx > ,
333- MK_UPCAST_VTABLE : FnOnce ( ) -> ValueRef ,
321+ where MK_UPCAST_VTABLE : FnOnce ( ) -> ValueRef
334322{
335- // FIXME(#19596) workaround: `|t| t` causes monomorphization recursion
336- fn identity < T > ( t : T ) -> T { t }
337-
338323 debug ! ( "unsized_info(kind={:?}, id={}, unadjusted_ty={})" ,
339324 kind, id, unadjusted_ty. repr( ccx. tcx( ) ) ) ;
340325 match kind {
341326 & ty:: UnsizeLength ( len) => C_uint ( ccx, len) ,
342327 & ty:: UnsizeStruct ( box ref k, tp_index) => match unadjusted_ty. sty {
343328 ty:: ty_struct( _, ref substs) => {
344329 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.
347330 unsized_info ( ccx, k, id, ty_substs[ tp_index] , param_substs,
348- identity , mk_upcast_vtable)
331+ mk_upcast_vtable)
349332 }
350333 _ => ccx. sess ( ) . bug ( & format ! ( "UnsizeStruct with bad sty: {}" ,
351334 unadjusted_ty. repr( ccx. tcx( ) ) ) )
@@ -359,8 +342,7 @@ pub fn unsized_info<'ccx, 'tcx, MK_TY, MK_UPCAST_VTABLE>(
359342 let trait_ref = monomorphize:: apply_param_substs ( ccx. tcx ( ) ,
360343 param_substs,
361344 & 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) ,
364346 Type :: vtable_ptr ( ccx) )
365347 }
366348 & ty:: UnsizeUpcast ( _) => {
@@ -498,8 +480,7 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
498480 let unsized_ty = ty:: unsize_ty ( tcx, datum_ty, k, expr. span ) ;
499481 debug ! ( "unsized_ty={}" , unsized_ty. repr( bcx. tcx( ) ) ) ;
500482
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 ) ;
503484
504485 // Arrange cleanup
505486 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>,
590571 let base = PointerCast ( bcx, get_dataptr ( bcx, scratch. val ) , llbox_ty. ptr_to ( ) ) ;
591572 bcx = datum. store_to ( bcx, base) ;
592573
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 ) ;
595575 Store ( bcx, info, get_len ( bcx, scratch. val ) ) ;
596576
597577 DatumBlock :: new ( bcx, scratch. to_expr_datum ( ) )
@@ -888,10 +868,7 @@ fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
888868 }
889869 } ;
890870
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 ) ;
895872
896873 let ( base, len) = base_datum. get_vec_base_and_len ( bcx) ;
897874
@@ -916,8 +893,8 @@ fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
916893 len)
917894 } ) ;
918895 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 )
921898 }
922899 } ;
923900
0 commit comments