Auto merge of #119258 - compiler-errors:closure-kind, r=eholk
Make closures carry their own ClosureKind Right now, we use the "`movability`" field of `hir::Closure` to distinguish a closure and a coroutine. This is paired together with the `CoroutineKind`, which is located not in the `hir::Closure`, but the `hir::Body`. This is strange and redundant. This PR introduces `ClosureKind` with two variants -- `Closure` and `Coroutine`, which is put into `hir::Closure`. The `CoroutineKind` is thus removed from `hir::Body`, and `Option<Movability>` no longer needs to be a stand-in for "is this a closure or a coroutine". r? eholk
This commit is contained in:
commit
1ab783112a
47 changed files with 573 additions and 491 deletions
|
@ -824,10 +824,6 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
|
|||
resolve_local(self, None, Some(body.value));
|
||||
}
|
||||
|
||||
if body.coroutine_kind.is_some() {
|
||||
self.scope_tree.body_expr_count.insert(body_id, self.expr_and_pat_count);
|
||||
}
|
||||
|
||||
// Restore context we had at the start.
|
||||
self.expr_and_pat_count = outer_ec;
|
||||
self.cx = outer_cx;
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue