mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
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
This commit is contained in:
commit
b715d9303e
@ -344,11 +344,18 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
|
||||
kind: hir::ExprKind::Closure(hir::Closure { kind, .. }), ..
|
||||
}) = node
|
||||
{
|
||||
// See `ClosureArgsParts`, `CoroutineArgsParts`, and `CoroutineClosureArgsParts`
|
||||
// for info on the usage of each of these fields.
|
||||
let dummy_args = match kind {
|
||||
ClosureKind::Closure => &["<closure_kind>", "<closure_signature>", "<upvars>"][..],
|
||||
ClosureKind::Coroutine(_) => {
|
||||
&["<resume_ty>", "<yield_ty>", "<return_ty>", "<witness>", "<upvars>"][..]
|
||||
}
|
||||
ClosureKind::Coroutine(_) => &[
|
||||
"<coroutine_kind>",
|
||||
"<resume_ty>",
|
||||
"<yield_ty>",
|
||||
"<return_ty>",
|
||||
"<witness>",
|
||||
"<upvars>",
|
||||
][..],
|
||||
ClosureKind::CoroutineClosure(_) => &[
|
||||
"<closure_kind>",
|
||||
"<closure_signature_parts>",
|
||||
|
@ -765,7 +765,14 @@ fn polymorphize<'tcx>(
|
||||
let def_id = instance.def_id();
|
||||
let upvars_ty = match tcx.type_of(def_id).skip_binder().kind() {
|
||||
ty::Closure(..) => Some(args.as_closure().tupled_upvars_ty()),
|
||||
ty::Coroutine(..) => Some(args.as_coroutine().tupled_upvars_ty()),
|
||||
ty::Coroutine(..) => {
|
||||
assert_eq!(
|
||||
args.as_coroutine().kind_ty(),
|
||||
tcx.types.unit,
|
||||
"polymorphization does not support coroutines from async closures"
|
||||
);
|
||||
Some(args.as_coroutine().tupled_upvars_ty())
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
let has_upvars = upvars_ty.is_some_and(|ty| !ty.tuple_fields().is_empty());
|
||||
|
17
tests/ui/coroutine/polymorphize-args.rs
Normal file
17
tests/ui/coroutine/polymorphize-args.rs
Normal file
@ -0,0 +1,17 @@
|
||||
// compile-flags: -Zpolymorphize=on
|
||||
// build-pass
|
||||
|
||||
#![feature(coroutines, coroutine_trait)]
|
||||
|
||||
use std::ops::Coroutine;
|
||||
use std::pin::Pin;
|
||||
use std::thread;
|
||||
|
||||
fn main() {
|
||||
let mut foo = || yield;
|
||||
thread::spawn(move || match Pin::new(&mut foo).resume(()) {
|
||||
s => panic!("bad state: {:?}", s),
|
||||
})
|
||||
.join()
|
||||
.unwrap();
|
||||
}
|
Loading…
Reference in New Issue
Block a user