Skip to content

Commit 55c64f0

Browse files
authored
Unrolled build for rust-lang#120897
Rollup merge of rust-lang#120897 - compiler-errors:foreign-async-closure, r=oli-obk Encode `coroutine_for_closure` for foreign crates Async closures (and "coroutine closures" in general) need to have their child coroutine encoded. This PR does that. r? oli-obk
2 parents 520b0b2 + c210fec commit 55c64f0

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ provide! { tcx, def_id, other, cdata,
250250
asyncness => { table_direct }
251251
fn_arg_names => { table }
252252
coroutine_kind => { table_direct }
253+
coroutine_for_closure => { table }
253254
trait_def => { table }
254255
deduced_param_attrs => { table }
255256
is_type_alias_impl_trait => {

compiler/rustc_metadata/src/rmeta/encoder.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14471447
{
14481448
self.tables.coroutine_kind.set(def_id.index, Some(coroutine_kind))
14491449
}
1450+
if def_kind == DefKind::Closure
1451+
&& tcx.type_of(def_id).skip_binder().is_coroutine_closure()
1452+
{
1453+
self.tables
1454+
.coroutine_for_closure
1455+
.set_some(def_id.index, self.tcx.coroutine_for_closure(def_id).into());
1456+
}
14501457
if let DefKind::Enum | DefKind::Struct | DefKind::Union = def_kind {
14511458
self.encode_info_for_adt(local_id);
14521459
}

compiler/rustc_metadata/src/rmeta/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ define_tables! {
443443
asyncness: Table<DefIndex, ty::Asyncness>,
444444
fn_arg_names: Table<DefIndex, LazyArray<Ident>>,
445445
coroutine_kind: Table<DefIndex, hir::CoroutineKind>,
446+
coroutine_for_closure: Table<DefIndex, RawDefId>,
446447
trait_def: Table<DefIndex, LazyValue<ty::TraitDef>>,
447448
trait_item_def_id: Table<DefIndex, RawDefId>,
448449
expn_that_defined: Table<DefIndex, LazyValue<ExpnId>>,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// edition:2021
2+
3+
#![feature(async_closure)]
4+
5+
pub fn closure() -> impl async Fn() {
6+
async || { /* Don't really need to do anything here. */ }
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// aux-build:block-on.rs
2+
// aux-build:foreign.rs
3+
// edition:2021
4+
// build-pass
5+
6+
#![feature(async_closure)]
7+
8+
use std::future::Future;
9+
10+
extern crate block_on;
11+
extern crate foreign;
12+
13+
struct NoCopy;
14+
15+
fn main() {
16+
block_on::block_on(async {
17+
foreign::closure()().await;
18+
});
19+
}

0 commit comments

Comments
 (0)