@@ -465,7 +465,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
465465 let sig = clif_sig_from_fn_abi ( fx. tcx , fx. target_config . default_call_conv , & fn_abi) ;
466466 let sig = fx. bcx . import_signature ( sig) ;
467467
468- ( CallTarget :: Indirect ( sig, method) , Some ( ptr) )
468+ ( CallTarget :: Indirect ( sig, method) , Some ( ptr. get_addr ( fx ) ) )
469469 }
470470
471471 // Normal call
@@ -560,7 +560,19 @@ pub(crate) fn codegen_drop<'tcx>(
560560 // we don't actually need to drop anything
561561 } else {
562562 match ty. kind ( ) {
563- ty:: Dynamic ( ..) => {
563+ ty:: Dynamic ( _, _, ty:: Dyn ) => {
564+ // IN THIS ARM, WE HAVE:
565+ // ty = *mut (dyn Trait)
566+ // which is: exists<T> ( *mut T, Vtable<T: Trait> )
567+ // args[0] args[1]
568+ //
569+ // args = ( Data, Vtable )
570+ // |
571+ // v
572+ // /-------\
573+ // | ... |
574+ // \-------/
575+ //
564576 let ( ptr, vtable) = drop_place. to_ptr_maybe_unsized ( ) ;
565577 let ptr = ptr. get_addr ( fx) ;
566578 let drop_fn = crate :: vtable:: drop_fn_of_obj ( fx, vtable. unwrap ( ) ) ;
@@ -578,6 +590,44 @@ pub(crate) fn codegen_drop<'tcx>(
578590 let sig = fx. bcx . import_signature ( sig) ;
579591 fx. bcx . ins ( ) . call_indirect ( sig, drop_fn, & [ ptr] ) ;
580592 }
593+ ty:: Dynamic ( _, _, ty:: DynStar ) => {
594+ // IN THIS ARM, WE HAVE:
595+ // ty = *mut (dyn* Trait)
596+ // which is: *mut exists<T: sizeof(T) == sizeof(usize)> (T, Vtable<T: Trait>)
597+ //
598+ // args = [ * ]
599+ // |
600+ // v
601+ // ( Data, Vtable )
602+ // |
603+ // v
604+ // /-------\
605+ // | ... |
606+ // \-------/
607+ //
608+ //
609+ // WE CAN CONVERT THIS INTO THE ABOVE LOGIC BY DOING
610+ //
611+ // data = &(*args[0]).0 // gives a pointer to Data above (really the same pointer)
612+ // vtable = (*args[0]).1 // loads the vtable out
613+ // (data, vtable) // an equivalent Rust `*mut dyn Trait`
614+ //
615+ // SO THEN WE CAN USE THE ABOVE CODE.
616+ let dyn_star = drop_place. to_cvalue ( fx) ;
617+ let ( data, vtable) = dyn_star. load_scalar_pair ( fx) ;
618+ let drop_fn = crate :: vtable:: drop_fn_of_obj ( fx, vtable) ;
619+
620+ let virtual_drop = Instance {
621+ def : ty:: InstanceDef :: Virtual ( drop_instance. def_id ( ) , 0 ) ,
622+ substs : drop_instance. substs ,
623+ } ;
624+ let fn_abi =
625+ RevealAllLayoutCx ( fx. tcx ) . fn_abi_of_instance ( virtual_drop, ty:: List :: empty ( ) ) ;
626+
627+ let sig = clif_sig_from_fn_abi ( fx. tcx , fx. target_config . default_call_conv , & fn_abi) ;
628+ let sig = fx. bcx . import_signature ( sig) ;
629+ fx. bcx . ins ( ) . call_indirect ( sig, drop_fn, & [ data] ) ;
630+ }
581631 _ => {
582632 assert ! ( !matches!( drop_instance. def, InstanceDef :: Virtual ( _, _) ) ) ;
583633
0 commit comments