Skip to content

Commit 062ff4d

Browse files
Encode coroutine_by_move_body_def_id in crate metadata
1 parent c52c23b commit 062ff4d

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ provide! { tcx, def_id, other, cdata,
290290
fn_arg_names => { table }
291291
coroutine_kind => { table_direct }
292292
coroutine_for_closure => { table }
293+
coroutine_by_move_body_def_id => { table }
293294
eval_static_initializer => {
294295
Ok(cdata
295296
.root

compiler/rustc_metadata/src/rmeta/encoder.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1488,9 +1488,18 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14881488
if def_kind == DefKind::Closure
14891489
&& tcx.type_of(def_id).skip_binder().is_coroutine_closure()
14901490
{
1491+
let coroutine_for_closure = self.tcx.coroutine_for_closure(def_id);
14911492
self.tables
14921493
.coroutine_for_closure
1493-
.set_some(def_id.index, self.tcx.coroutine_for_closure(def_id).into());
1494+
.set_some(def_id.index, coroutine_for_closure.into());
1495+
1496+
// If this async closure has a by-move body, record it too.
1497+
if tcx.needs_coroutine_by_move_body_def_id(coroutine_for_closure) {
1498+
self.tables.coroutine_by_move_body_def_id.set_some(
1499+
coroutine_for_closure.index,
1500+
self.tcx.coroutine_by_move_body_def_id(coroutine_for_closure).into(),
1501+
);
1502+
}
14941503
}
14951504
if let DefKind::Static { .. } = def_kind {
14961505
if !self.tcx.is_foreign_item(def_id) {

compiler/rustc_metadata/src/rmeta/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ define_tables! {
446446
fn_arg_names: Table<DefIndex, LazyArray<Ident>>,
447447
coroutine_kind: Table<DefIndex, hir::CoroutineKind>,
448448
coroutine_for_closure: Table<DefIndex, RawDefId>,
449+
coroutine_by_move_body_def_id: Table<DefIndex, RawDefId>,
449450
eval_static_initializer: Table<DefIndex, LazyValue<mir::interpret::ConstAllocation<'static>>>,
450451
trait_def: Table<DefIndex, LazyValue<ty::TraitDef>>,
451452
trait_item_def_id: Table<DefIndex, RawDefId>,

tests/ui/async-await/async-closures/foreign.rs

+5
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ extern crate foreign;
1212

1313
struct NoCopy;
1414

15+
async fn call_once(f: impl async FnOnce()) {
16+
f().await;
17+
}
18+
1519
fn main() {
1620
block_on::block_on(async {
1721
foreign::closure()().await;
22+
call_once(foreign::closure()).await;
1823
});
1924
}

0 commit comments

Comments
 (0)