1
Fork 0

Make closures carry their own ClosureKind, rather than deducing what it is from movability

This commit is contained in:
Michael Goulet 2023-12-22 21:29:12 +00:00
parent 981fc6e174
commit 909dd864f1
20 changed files with 338 additions and 326 deletions

View file

@ -1551,10 +1551,14 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
fn coroutine_kind(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<hir::CoroutineKind> {
match tcx.hir_node_by_def_id(def_id) {
Node::Expr(&rustc_hir::Expr {
kind: rustc_hir::ExprKind::Closure(&rustc_hir::Closure { body, .. }),
Node::Expr(&hir::Expr {
kind:
hir::ExprKind::Closure(&rustc_hir::Closure {
kind: hir::ClosureKind::Coroutine(kind, _),
..
}),
..
}) => tcx.hir().body(body).coroutine_kind(),
}) => Some(kind),
_ => None,
}
}

View file

@ -338,14 +338,14 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
// cares about anything but the length is instantiation,
// and we don't do that for closures.
if let Node::Expr(&hir::Expr {
kind: hir::ExprKind::Closure(hir::Closure { movability: gen, .. }),
..
kind: hir::ExprKind::Closure(hir::Closure { kind, .. }), ..
}) = node
{
let dummy_args = if gen.is_some() {
&["<resume_ty>", "<yield_ty>", "<return_ty>", "<witness>", "<upvars>"][..]
} else {
&["<closure_kind>", "<closure_signature>", "<upvars>"][..]
let dummy_args = match kind {
ClosureKind::Closure => &["<closure_kind>", "<closure_signature>", "<upvars>"][..],
ClosureKind::Coroutine(_, _) => {
&["<resume_ty>", "<yield_ty>", "<return_ty>", "<witness>", "<upvars>"][..]
}
};
params.extend(dummy_args.iter().map(|&arg| ty::GenericParamDef {