@@ -9,7 +9,7 @@ use rustc_index::{Idx, IndexVec};
9
9
use rustc_middle:: mir:: {
10
10
BasicBlock , BasicBlockData , Body , CallSource , CastKind , Const , ConstOperand , ConstValue , Local ,
11
11
LocalDecl , MirSource , Operand , Place , PlaceElem , Rvalue , SourceInfo , Statement , StatementKind ,
12
- Terminator , TerminatorKind , UnwindAction , UnwindTerminateReason ,
12
+ Terminator , TerminatorKind , UnwindAction , UnwindTerminateReason , RETURN_PLACE ,
13
13
} ;
14
14
use rustc_middle:: ty:: adjustment:: PointerCoercion ;
15
15
use rustc_middle:: ty:: util:: Discr ;
@@ -67,9 +67,12 @@ impl<'tcx> AsyncDestructorCtorShimBuilder<'tcx> {
67
67
const MAX_STACK_LEN : usize = 2 ;
68
68
69
69
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) ;
73
76
let sig = tcx. instantiate_bound_regions_with_erased ( sig) ;
74
77
let span = tcx. def_span ( def_id) ;
75
78
@@ -113,7 +116,7 @@ impl<'tcx> AsyncDestructorCtorShimBuilder<'tcx> {
113
116
114
117
fn build ( self ) -> Body < ' tcx > {
115
118
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 ( ) ;
117
120
} ;
118
121
119
122
let surface_drop_kind = || {
@@ -258,8 +261,8 @@ impl<'tcx> AsyncDestructorCtorShimBuilder<'tcx> {
258
261
self . return_ ( )
259
262
}
260
263
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 ( ) ;
263
266
self . return_ ( )
264
267
}
265
268
@@ -288,6 +291,15 @@ impl<'tcx> AsyncDestructorCtorShimBuilder<'tcx> {
288
291
self . return_ ( )
289
292
}
290
293
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
+
291
303
/// Puts `to_drop: *mut Self` on top of the stack.
292
304
fn put_self ( & mut self ) {
293
305
self . put_operand ( Operand :: Copy ( Self :: SELF_PTR . into ( ) ) )
@@ -464,23 +476,15 @@ impl<'tcx> AsyncDestructorCtorShimBuilder<'tcx> {
464
476
self . stack. len( ) ,
465
477
)
466
478
} ;
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
+
484
488
let dead_storage = match & output {
485
489
Operand :: Move ( place) => Some ( Statement {
486
490
source_info,
@@ -492,7 +496,7 @@ impl<'tcx> AsyncDestructorCtorShimBuilder<'tcx> {
492
496
last_bb. statements . extend (
493
497
iter:: once ( Statement {
494
498
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) ) ) ) ,
496
500
} )
497
501
. chain ( dead_storage) ,
498
502
) ;
0 commit comments