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
|
@ -3,7 +3,7 @@ use Context::*;
|
|||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::{LocalDefId, LocalModDefId};
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_hir::{Destination, Movability, Node};
|
||||
use rustc_hir::{Destination, Node};
|
||||
use rustc_middle::hir::nested_filter;
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
|
@ -86,16 +86,15 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
|
|||
self.with_context(Loop(source), |v| v.visit_block(b));
|
||||
}
|
||||
hir::ExprKind::Closure(&hir::Closure {
|
||||
ref fn_decl,
|
||||
body,
|
||||
fn_decl_span,
|
||||
movability,
|
||||
..
|
||||
ref fn_decl, body, fn_decl_span, kind, ..
|
||||
}) => {
|
||||
let cx = if let Some(Movability::Static) = movability {
|
||||
AsyncClosure(fn_decl_span)
|
||||
} else {
|
||||
Closure(fn_decl_span)
|
||||
// FIXME(coroutines): This doesn't handle coroutines correctly
|
||||
let cx = match kind {
|
||||
hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(
|
||||
hir::CoroutineDesugaring::Async,
|
||||
hir::CoroutineSource::Block,
|
||||
)) => AsyncClosure(fn_decl_span),
|
||||
_ => Closure(fn_decl_span),
|
||||
};
|
||||
self.visit_fn_decl(fn_decl);
|
||||
self.with_context(cx, |v| v.visit_nested_body(body));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue