diff options
Diffstat (limited to 'compiler/rustc_hir/src/hir.rs')
| -rw-r--r-- | compiler/rustc_hir/src/hir.rs | 35 | 
1 files changed, 26 insertions, 9 deletions
| diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 452f5d0b7ac..2b840860166 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -945,7 +945,18 @@ 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). + Coroutine(CoroutineKind), } /// A block of statements `{ .. }`, which may have a label (in this case the @@ -1335,17 +1346,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. @@ -1355,7 +1361,18 @@ pub enum CoroutineKind { Desugared(CoroutineDesugaring, CoroutineSource), /// A coroutine literal created via a `yield` inside a closure. - Coroutine, + Coroutine(Movability), +} + +impl CoroutineKind { + pub fn movability(self) -> Movability { + match self { + CoroutineKind::Desugared(CoroutineDesugaring::Async, _) + | CoroutineKind::Desugared(CoroutineDesugaring::AsyncGen, _) => Movability::Static, + CoroutineKind::Desugared(CoroutineDesugaring::Gen, _) => Movability::Movable, + CoroutineKind::Coroutine(mov) => mov, + } + } } impl fmt::Display for CoroutineKind { @@ -1365,7 +1382,7 @@ impl fmt::Display for CoroutineKind { d.fmt(f)?; k.fmt(f) } - CoroutineKind::Coroutine => f.write_str("coroutine"), + CoroutineKind::Coroutine(_) => f.write_str("coroutine"), } } } @@ -3661,7 +3678,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); | 
