Skip to content

Commit b715d93

Browse files
authored
Rollup merge of #120746 - compiler-errors:kind-ty, r=oli-obk
Record coroutine kind in coroutine generics Oops, added a new substitution (the "kind" ty) to coroutines but forgot to record it in the `generics_of`. I'm surprised I left this out of the coroutine-closure PR -- I thought I made this change; I possibly rebased it out by accident. Fixes #120732 r? oli-obk
2 parents cb040f5 + dcca9a1 commit b715d93

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

compiler/rustc_hir_analysis/src/collect/generics_of.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,18 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
344344
kind: hir::ExprKind::Closure(hir::Closure { kind, .. }), ..
345345
}) = node
346346
{
347+
// See `ClosureArgsParts`, `CoroutineArgsParts`, and `CoroutineClosureArgsParts`
348+
// for info on the usage of each of these fields.
347349
let dummy_args = match kind {
348350
ClosureKind::Closure => &["<closure_kind>", "<closure_signature>", "<upvars>"][..],
349-
ClosureKind::Coroutine(_) => {
350-
&["<resume_ty>", "<yield_ty>", "<return_ty>", "<witness>", "<upvars>"][..]
351-
}
351+
ClosureKind::Coroutine(_) => &[
352+
"<coroutine_kind>",
353+
"<resume_ty>",
354+
"<yield_ty>",
355+
"<return_ty>",
356+
"<witness>",
357+
"<upvars>",
358+
][..],
352359
ClosureKind::CoroutineClosure(_) => &[
353360
"<closure_kind>",
354361
"<closure_signature_parts>",

compiler/rustc_middle/src/ty/instance.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,14 @@ fn polymorphize<'tcx>(
765765
let def_id = instance.def_id();
766766
let upvars_ty = match tcx.type_of(def_id).skip_binder().kind() {
767767
ty::Closure(..) => Some(args.as_closure().tupled_upvars_ty()),
768-
ty::Coroutine(..) => Some(args.as_coroutine().tupled_upvars_ty()),
768+
ty::Coroutine(..) => {
769+
assert_eq!(
770+
args.as_coroutine().kind_ty(),
771+
tcx.types.unit,
772+
"polymorphization does not support coroutines from async closures"
773+
);
774+
Some(args.as_coroutine().tupled_upvars_ty())
775+
}
769776
_ => None,
770777
};
771778
let has_upvars = upvars_ty.is_some_and(|ty| !ty.tuple_fields().is_empty());
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// compile-flags: -Zpolymorphize=on
2+
// build-pass
3+
4+
#![feature(coroutines, coroutine_trait)]
5+
6+
use std::ops::Coroutine;
7+
use std::pin::Pin;
8+
use std::thread;
9+
10+
fn main() {
11+
let mut foo = || yield;
12+
thread::spawn(move || match Pin::new(&mut foo).resume(()) {
13+
s => panic!("bad state: {:?}", s),
14+
})
15+
.join()
16+
.unwrap();
17+
}

0 commit comments

Comments
 (0)