diff options
Diffstat (limited to 'compiler/rustc_ast/src')
| -rw-r--r-- | compiler/rustc_ast/src/ast.rs | 25 | ||||
| -rw-r--r-- | compiler/rustc_ast/src/mut_visit.rs | 5 |
2 files changed, 10 insertions, 20 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index bf648388f4e..d6c2bfacf66 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 coro_kind: CoroutineKind, + pub coro_kind: Option<CoroutineKind>, pub movability: Movability, pub fn_decl: P<FnDecl>, pub body: P<Expr>, @@ -2417,8 +2417,6 @@ pub enum CoroutineKind { 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 CoroutineKind { @@ -2430,14 +2428,12 @@ impl CoroutineKind { 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)> { + /// In this case this is an `async` or `gen` return, the `NodeId` for the generated `impl Trait` + /// item. + pub fn return_id(self) -> (NodeId, Span) { match self { CoroutineKind::Async { return_impl_trait_id, span, .. } - | CoroutineKind::Gen { return_impl_trait_id, span, .. } => { - Some((return_impl_trait_id, span)) - } - CoroutineKind::None => None, + | CoroutineKind::Gen { return_impl_trait_id, span, .. } => (return_impl_trait_id, span), } } } @@ -2842,7 +2838,7 @@ pub struct FnHeader { /// The `unsafe` keyword, if any pub unsafety: Unsafe, /// Whether this is `async`, `gen`, or nothing. - pub coro_kind: CoroutineKind, + pub coro_kind: Option<CoroutineKind>, /// The `const` keyword, if any pub constness: Const, /// The `extern` keyword and corresponding ABI string, if any @@ -2854,7 +2850,7 @@ impl FnHeader { pub fn has_qualifiers(&self) -> bool { let Self { unsafety, coro_kind, constness, ext } = self; matches!(unsafety, Unsafe::Yes(_)) - || !matches!(coro_kind, CoroutineKind::None) + || coro_kind.is_some() || matches!(constness, Const::Yes(_)) || !matches!(ext, Extern::None) } @@ -2862,12 +2858,7 @@ impl FnHeader { impl Default for FnHeader { fn default() -> FnHeader { - FnHeader { - unsafety: Unsafe::No, - coro_kind: CoroutineKind::None, - constness: Const::No, - ext: Extern::None, - } + FnHeader { unsafety: Unsafe::No, coro_kind: None, constness: Const::No, ext: Extern::None } } } diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index f9f767862f5..c6aa7a6ae37 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -878,7 +878,6 @@ pub fn noop_visit_coro_kind<T: MutVisitor>(coro_kind: &mut CoroutineKind, vis: & vis.visit_id(closure_id); vis.visit_id(return_impl_trait_id); } - CoroutineKind::None => {} } } @@ -1173,7 +1172,7 @@ fn visit_const_item<T: MutVisitor>( pub fn noop_visit_fn_header<T: MutVisitor>(header: &mut FnHeader, vis: &mut T) { let FnHeader { unsafety, coro_kind, constness, ext: _ } = header; visit_constness(constness, vis); - vis.visit_coro_kind(coro_kind); + coro_kind.as_mut().map(|coro_kind| vis.visit_coro_kind(coro_kind)); visit_unsafety(unsafety, vis); } @@ -1416,7 +1415,7 @@ pub fn noop_visit_expr<T: MutVisitor>( }) => { vis.visit_closure_binder(binder); visit_constness(constness, vis); - vis.visit_coro_kind(coro_kind); + coro_kind.as_mut().map(|coro_kind| vis.visit_coro_kind(coro_kind)); vis.visit_capture_by(capture_clause); vis.visit_fn_decl(fn_decl); vis.visit_expr(body); |
