@@ -9,7 +9,7 @@ use rustc_index::{Idx, IndexVec};
99use rustc_middle:: mir:: {
1010 BasicBlock , BasicBlockData , Body , CallSource , CastKind , Const , ConstOperand , ConstValue , Local ,
1111 LocalDecl , MirSource , Operand , Place , PlaceElem , Rvalue , SourceInfo , Statement , StatementKind ,
12- Terminator , TerminatorKind , UnwindAction , UnwindTerminateReason ,
12+ Terminator , TerminatorKind , UnwindAction , UnwindTerminateReason , RETURN_PLACE ,
1313} ;
1414use rustc_middle:: ty:: adjustment:: PointerCoercion ;
1515use rustc_middle:: ty:: util:: Discr ;
@@ -67,9 +67,12 @@ impl<'tcx> AsyncDestructorCtorShimBuilder<'tcx> {
6767 const MAX_STACK_LEN : usize = 2 ;
6868
6969 fn new ( tcx : TyCtxt < ' tcx > , def_id : DefId , self_ty : Option < Ty < ' tcx > > ) -> Self {
70- // Assuming `async_drop_in_place::<()>` is the same as for any type with noop async destructor
71- let arg_ty = if let Some ( ty) = self_ty { ty } else { tcx. types . unit } ;
72- let sig = tcx. fn_sig ( def_id) . instantiate ( tcx, & [ arg_ty. into ( ) ] ) ;
70+ let args = if let Some ( ty) = self_ty {
71+ tcx. mk_args ( & [ ty. into ( ) ] )
72+ } else {
73+ ty:: GenericArgs :: identity_for_item ( tcx, def_id)
74+ } ;
75+ let sig = tcx. fn_sig ( def_id) . instantiate ( tcx, args) ;
7376 let sig = tcx. instantiate_bound_regions_with_erased ( sig) ;
7477 let span = tcx. def_span ( def_id) ;
7578
@@ -113,7 +116,7 @@ impl<'tcx> AsyncDestructorCtorShimBuilder<'tcx> {
113116
114117 fn build ( self ) -> Body < ' tcx > {
115118 let ( tcx, def_id, Some ( self_ty) ) = ( self . tcx , self . def_id , self . self_ty ) else {
116- return self . build_noop ( ) ;
119+ return self . build_zst_output ( ) ;
117120 } ;
118121
119122 let surface_drop_kind = || {
@@ -258,8 +261,8 @@ impl<'tcx> AsyncDestructorCtorShimBuilder<'tcx> {
258261 self . return_ ( )
259262 }
260263
261- fn build_noop ( mut self ) -> Body < ' tcx > {
262- self . put_noop ( ) ;
264+ fn build_zst_output ( mut self ) -> Body < ' tcx > {
265+ self . put_zst_output ( ) ;
263266 self . return_ ( )
264267 }
265268
@@ -288,6 +291,15 @@ impl<'tcx> AsyncDestructorCtorShimBuilder<'tcx> {
288291 self . return_ ( )
289292 }
290293
294+ fn put_zst_output ( & mut self ) {
295+ let return_ty = self . locals [ RETURN_PLACE ] . ty ;
296+ self . put_operand ( Operand :: Constant ( Box :: new ( ConstOperand {
297+ span : self . span ,
298+ user_ty : None ,
299+ const_ : Const :: zero_sized ( return_ty) ,
300+ } ) ) ) ;
301+ }
302+
291303 /// Puts `to_drop: *mut Self` on top of the stack.
292304 fn put_self ( & mut self ) {
293305 self . put_operand ( Operand :: Copy ( Self :: SELF_PTR . into ( ) ) )
@@ -464,23 +476,15 @@ impl<'tcx> AsyncDestructorCtorShimBuilder<'tcx> {
464476 self . stack. len( ) ,
465477 )
466478 } ;
467- const RETURN_LOCAL : Local = Local :: from_u32 ( 0 ) ;
468-
469- debug_assert_eq ! (
470- output. ty( & self . locals, self . tcx) ,
471- self . self_ty. map( |ty| ty. async_destructor_ty( self . tcx, self . param_env) ) . unwrap_or_else(
472- || {
473- self . tcx
474- . fn_sig(
475- self . tcx. require_lang_item( LangItem :: AsyncDropNoop , Some ( self . span) ) ,
476- )
477- . instantiate_identity( )
478- . output( )
479- . no_bound_vars( )
480- . unwrap( )
481- }
482- ) ,
483- ) ;
479+ #[ cfg( debug_assertions) ]
480+ if let Some ( ty) = self . self_ty {
481+ debug_assert_eq ! (
482+ output. ty( & self . locals, self . tcx) ,
483+ ty. async_destructor_ty( self . tcx, self . param_env) ,
484+ "output async destructor types did not match for type: {ty:?}" ,
485+ ) ;
486+ }
487+
484488 let dead_storage = match & output {
485489 Operand :: Move ( place) => Some ( Statement {
486490 source_info,
@@ -492,7 +496,7 @@ impl<'tcx> AsyncDestructorCtorShimBuilder<'tcx> {
492496 last_bb. statements . extend (
493497 iter:: once ( Statement {
494498 source_info,
495- kind : StatementKind :: Assign ( Box :: new ( ( RETURN_LOCAL . into ( ) , Rvalue :: Use ( output) ) ) ) ,
499+ kind : StatementKind :: Assign ( Box :: new ( ( RETURN_PLACE . into ( ) , Rvalue :: Use ( output) ) ) ) ,
496500 } )
497501 . chain ( dead_storage) ,
498502 ) ;
0 commit comments