Skip to content

Commit 8e0c3d0

Browse files
committed
Fix for async drop inside async gen fn
1 parent 52882f6 commit 8e0c3d0

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

compiler/rustc_mir_transform/src/coroutine.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,23 @@ impl<'tcx> TransformVisitor<'tcx> {
317317
),
318318
user_ty: None,
319319
})))
320+
} else if matches!(
321+
val,
322+
Operand::Constant(box ConstOperand {
323+
const_: Const::Val(ConstValue::Scalar(_), _),
324+
..
325+
})
326+
) {
327+
// yield (const false) is used for async drop yields inside AsyncGen
328+
// We need to convert value to Poll<OptRet>::Pending
329+
let poll_def_id = self.tcx.require_lang_item(LangItem::Poll, None);
330+
let ty::Adt(_poll_adt, args) = *self.old_yield_ty.kind() else { bug!() };
331+
make_aggregate_adt(
332+
poll_def_id,
333+
VariantIdx::from_usize(1),
334+
args,
335+
IndexVec::new(),
336+
)
320337
} else {
321338
Rvalue::Use(val)
322339
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// ex-ice: #140530
2+
//@ edition: 2024
3+
//@ build-pass
4+
#![feature(async_drop, gen_blocks)]
5+
#![allow(incomplete_features)]
6+
async gen fn a() {
7+
_ = async {}
8+
}
9+
fn main() {}

0 commit comments

Comments
 (0)