diff options
Diffstat (limited to 'compiler/rustc_ast/src')
| -rw-r--r-- | compiler/rustc_ast/src/ast.rs | 54 | ||||
| -rw-r--r-- | compiler/rustc_ast/src/mut_visit.rs | 36 | ||||
| -rw-r--r-- | compiler/rustc_ast/src/visit.rs | 2 | 
3 files changed, 42 insertions, 50 deletions
| diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 4ef8d64c4c0..bf648388f4e 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -1311,7 +1311,7 @@ pub struct Closure { pub binder: ClosureBinder, pub capture_clause: CaptureBy, pub constness: Const, - pub asyncness: Async, + pub coro_kind: CoroutineKind, pub movability: Movability, pub fn_decl: P<FnDecl>, pub body: P<Expr>, @@ -2406,28 +2406,38 @@ pub enum Unsafe { No, } +/// Describes what kind of coroutine markers, if any, a function has. +/// +/// Coroutine markers are things that cause the function to generate a coroutine, such as `async`, +/// which makes the function return `impl Future`, or `gen`, which makes the function return `impl +/// Iterator`. #[derive(Copy, Clone, Encodable, Decodable, Debug)] -pub enum Async { - Yes { span: Span, closure_id: NodeId, return_impl_trait_id: NodeId }, - No, -} - -#[derive(Copy, Clone, Encodable, Decodable, Debug)] -pub enum Gen { - Yes { span: Span, closure_id: NodeId, return_impl_trait_id: NodeId }, - No, +pub enum CoroutineKind { + /// `async`, which evaluates to `impl Future` + Async { span: Span, closure_id: NodeId, return_impl_trait_id: NodeId }, + /// `gen`, which evaluates to `impl Iterator` + Gen { span: Span, closure_id: NodeId, return_impl_trait_id: NodeId }, + /// Neither `async` nor `gen` + None, } -impl Async { +impl CoroutineKind { pub fn is_async(self) -> bool { - matches!(self, Async::Yes { .. }) + matches!(self, CoroutineKind::Async { .. }) + } + + pub fn is_gen(self) -> bool { + matches!(self, CoroutineKind::Gen { .. }) } /// In this case this is an `async` return, the `NodeId` for the generated `impl Trait` item. pub fn opt_return_id(self) -> Option<(NodeId, Span)> { match self { - Async::Yes { return_impl_trait_id, span, .. } => Some((return_impl_trait_id, span)), - Async::No => None, + CoroutineKind::Async { return_impl_trait_id, span, .. } + | CoroutineKind::Gen { return_impl_trait_id, span, .. } => { + Some((return_impl_trait_id, span)) + } + CoroutineKind::None => None, } } } @@ -2831,25 +2841,22 @@ impl Extern { pub struct FnHeader { /// The `unsafe` keyword, if any pub unsafety: Unsafe, - /// The `async` keyword, if any - pub asyncness: Async, + /// Whether this is `async`, `gen`, or nothing. + pub coro_kind: CoroutineKind, /// The `const` keyword, if any pub constness: Const, /// The `extern` keyword and corresponding ABI string, if any pub ext: Extern, - /// The `gen` keyword, if any - pub genness: Gen, } impl FnHeader { /// Does this function header have any qualifiers or is it empty? pub fn has_qualifiers(&self) -> bool { - let Self { unsafety, asyncness, constness, ext, genness } = self; + let Self { unsafety, coro_kind, constness, ext } = self; matches!(unsafety, Unsafe::Yes(_)) - || asyncness.is_async() + || !matches!(coro_kind, CoroutineKind::None) || matches!(constness, Const::Yes(_)) || !matches!(ext, Extern::None) - || matches!(genness, Gen::Yes { .. }) } } @@ -2857,10 +2864,9 @@ impl Default for FnHeader { fn default() -> FnHeader { FnHeader { unsafety: Unsafe::No, - asyncness: Async::No, + coro_kind: CoroutineKind::None, constness: Const::No, ext: Extern::None, - genness: Gen::No, } } } @@ -3181,7 +3187,7 @@ mod size_asserts { static_assert_size!(Block, 32); static_assert_size!(Expr, 72); static_assert_size!(ExprKind, 40); - static_assert_size!(Fn, 168); + static_assert_size!(Fn, 160); static_assert_size!(ForeignItem, 96); static_assert_size!(ForeignItemKind, 24); static_assert_size!(GenericArg, 24); diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 7cdbb1a8c61..f9f767862f5 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -121,12 +121,8 @@ pub trait MutVisitor: Sized { noop_visit_fn_decl(d, self); } - fn visit_asyncness(&mut self, a: &mut Async) { - noop_visit_asyncness(a, self); - } - - fn visit_genness(&mut self, a: &mut Gen) { - noop_visit_genness(a, self); + fn visit_coro_kind(&mut self, a: &mut CoroutineKind) { + noop_visit_coro_kind(a, self); } fn visit_closure_binder(&mut self, b: &mut ClosureBinder) { @@ -875,23 +871,14 @@ pub fn noop_visit_closure_binder<T: MutVisitor>(binder: &mut ClosureBinder, vis: } } -pub fn noop_visit_asyncness<T: MutVisitor>(asyncness: &mut Async, vis: &mut T) { - match asyncness { - Async::Yes { span: _, closure_id, return_impl_trait_id } => { - vis.visit_id(closure_id); - vis.visit_id(return_impl_trait_id); - } - Async::No => {} - } -} - -pub fn noop_visit_genness<T: MutVisitor>(genness: &mut Gen, vis: &mut T) { - match genness { - Gen::Yes { span: _, closure_id, return_impl_trait_id } => { +pub fn noop_visit_coro_kind<T: MutVisitor>(coro_kind: &mut CoroutineKind, vis: &mut T) { + match coro_kind { + CoroutineKind::Async { span: _, closure_id, return_impl_trait_id } + | CoroutineKind::Gen { span: _, closure_id, return_impl_trait_id } => { vis.visit_id(closure_id); vis.visit_id(return_impl_trait_id); } - Gen::No => {} + CoroutineKind::None => {} } } @@ -1184,10 +1171,9 @@ fn visit_const_item<T: MutVisitor>( } pub fn noop_visit_fn_header<T: MutVisitor>(header: &mut FnHeader, vis: &mut T) { - let FnHeader { unsafety, asyncness, constness, ext: _, genness } = header; + let FnHeader { unsafety, coro_kind, constness, ext: _ } = header; visit_constness(constness, vis); - vis.visit_asyncness(asyncness); - vis.visit_genness(genness); + vis.visit_coro_kind(coro_kind); visit_unsafety(unsafety, vis); } @@ -1421,7 +1407,7 @@ pub fn noop_visit_expr<T: MutVisitor>( binder, capture_clause, constness, - asyncness, + coro_kind, movability: _, fn_decl, body, @@ -1430,7 +1416,7 @@ pub fn noop_visit_expr<T: MutVisitor>( }) => { vis.visit_closure_binder(binder); visit_constness(constness, vis); - vis.visit_asyncness(asyncness); + vis.visit_coro_kind(coro_kind); vis.visit_capture_by(capture_clause); vis.visit_fn_decl(fn_decl); vis.visit_expr(body); diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 9dbadcb49d3..a303d6584f4 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -861,7 +861,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) { ExprKind::Closure(box Closure { binder, capture_clause, - asyncness: _, + coro_kind: _, constness: _, movability: _, fn_decl, | 
