Skip to content

Commit 8e20c56

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

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
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
}

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)