@@ -382,12 +382,34 @@ pub(super) fn expand_async_drops<'tcx>(
382
382
dropline_call_bb = Some ( drop_call_bb) ;
383
383
}
384
384
385
- // value needed only for return-yields or gen-coroutines, so just const here
386
- let value = Operand :: Constant ( Box :: new ( ConstOperand {
387
- span : body. span ,
388
- user_ty : None ,
389
- const_ : Const :: from_bool ( tcx, false ) ,
390
- } ) ) ;
385
+ let value =
386
+ if matches ! ( coroutine_kind, CoroutineKind :: Desugared ( CoroutineDesugaring :: AsyncGen , _) )
387
+ {
388
+ // For AsyncGen we need `yield Poll<OptRet>::Pending`
389
+ let full_yield_ty = body. yield_ty ( ) . unwrap ( ) ;
390
+ let ty:: Adt ( _poll_adt, args) = * full_yield_ty. kind ( ) else { bug ! ( ) } ;
391
+ let ty:: Adt ( _option_adt, args) = * args. type_at ( 0 ) . kind ( ) else { bug ! ( ) } ;
392
+ let yield_ty = args. type_at ( 0 ) ;
393
+ Operand :: Constant ( Box :: new ( ConstOperand {
394
+ span : source_info. span ,
395
+ const_ : Const :: Unevaluated (
396
+ UnevaluatedConst :: new (
397
+ tcx. require_lang_item ( LangItem :: AsyncGenPending , None ) ,
398
+ tcx. mk_args ( & [ yield_ty. into ( ) ] ) ,
399
+ ) ,
400
+ full_yield_ty,
401
+ ) ,
402
+ user_ty : None ,
403
+ } ) )
404
+ } else {
405
+ // value needed only for return-yields or gen-coroutines, so just const here
406
+ Operand :: Constant ( Box :: new ( ConstOperand {
407
+ span : body. span ,
408
+ user_ty : None ,
409
+ const_ : Const :: from_bool ( tcx, false ) ,
410
+ } ) )
411
+ } ;
412
+
391
413
use rustc_middle:: mir:: AssertKind :: ResumedAfterDrop ;
392
414
let panic_bb = insert_panic_block ( tcx, body, ResumedAfterDrop ( coroutine_kind) ) ;
393
415
0 commit comments