Skip to content

Commit a323f18

Browse files
authored
Unrolled build for #141932
Rollup merge of #141932 - azhogin:azhogin/async-drop-inside-asyncgen-fix, r=oli-obk Fix for async drop inside async gen fn Return value (for yield) is corrected for async drop inside async gen function. In CFG, when internal async drop future is polled and returned `Poll<()>::Pending`, then async gen resume function returns `Poll<(OptRet)>::Pending`. Fixes #140530
2 parents ff223d3 + d5a9a00 commit a323f18

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

compiler/rustc_mir_transform/src/coroutine/drop.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,12 +382,34 @@ pub(super) fn expand_async_drops<'tcx>(
382382
dropline_call_bb = Some(drop_call_bb);
383383
}
384384

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+
391413
use rustc_middle::mir::AssertKind::ResumedAfterDrop;
392414
let panic_bb = insert_panic_block(tcx, body, ResumedAfterDrop(coroutine_kind));
393415

tests/crashes/140530.rs renamed to tests/ui/async-await/async-drop/assign-incompatible-types.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
//@ known-bug: #140530
1+
// ex-ice: #140530
22
//@ edition: 2024
3-
3+
//@ build-pass
44
#![feature(async_drop, gen_blocks)]
5+
#![allow(incomplete_features)]
56
async gen fn a() {
67
_ = async {}
78
}

0 commit comments

Comments
 (0)