Make closures carry their own ClosureKind, rather than deducing what it is from movability
This commit is contained in:
parent
981fc6e174
commit
909dd864f1
20 changed files with 338 additions and 326 deletions
|
@ -945,7 +945,21 @@ pub struct Closure<'hir> {
|
|||
pub fn_decl_span: Span,
|
||||
/// The span of the argument block `|...|`
|
||||
pub fn_arg_span: Option<Span>,
|
||||
pub movability: Option<Movability>,
|
||||
pub kind: ClosureKind,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Copy, Hash, HashStable_Generic, Encodable, Decodable)]
|
||||
pub enum ClosureKind {
|
||||
/// This is a plain closure expression.
|
||||
Closure,
|
||||
/// This is a coroutine expression -- i.e. a closure expression in which
|
||||
/// we've found a `yield`. These can arise either from "plain" coroutine
|
||||
/// usage (e.g. `let x = || { yield (); }`) or from a desugared expression
|
||||
/// (e.g. `async` and `gen` blocks).
|
||||
// FIXME(coroutines): We could probably remove movability here -- it can be deduced
|
||||
// from the `CoroutineKind` in all cases (except for "plain" coroutines, which could
|
||||
// carry the movability in the variant).
|
||||
Coroutine(CoroutineKind, Movability),
|
||||
}
|
||||
|
||||
/// A block of statements `{ .. }`, which may have a label (in this case the
|
||||
|
@ -1335,17 +1349,12 @@ pub struct BodyId {
|
|||
pub struct Body<'hir> {
|
||||
pub params: &'hir [Param<'hir>],
|
||||
pub value: &'hir Expr<'hir>,
|
||||
pub coroutine_kind: Option<CoroutineKind>,
|
||||
}
|
||||
|
||||
impl<'hir> Body<'hir> {
|
||||
pub fn id(&self) -> BodyId {
|
||||
BodyId { hir_id: self.value.hir_id }
|
||||
}
|
||||
|
||||
pub fn coroutine_kind(&self) -> Option<CoroutineKind> {
|
||||
self.coroutine_kind
|
||||
}
|
||||
}
|
||||
|
||||
/// The type of source expression that caused this coroutine to be created.
|
||||
|
@ -3661,7 +3670,7 @@ mod size_asserts {
|
|||
use super::*;
|
||||
// tidy-alphabetical-start
|
||||
static_assert_size!(Block<'_>, 48);
|
||||
static_assert_size!(Body<'_>, 32);
|
||||
static_assert_size!(Body<'_>, 24);
|
||||
static_assert_size!(Expr<'_>, 64);
|
||||
static_assert_size!(ExprKind<'_>, 48);
|
||||
static_assert_size!(FnDecl<'_>, 40);
|
||||
|
|
|
@ -757,7 +757,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
|
|||
capture_clause: _,
|
||||
fn_decl_span: _,
|
||||
fn_arg_span: _,
|
||||
movability: _,
|
||||
kind: _,
|
||||
constness: _,
|
||||
}) => {
|
||||
walk_list!(visitor, visit_generic_param, bound_generic_params);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue