Option<CoroutineKind>
This commit is contained in:
parent
48d5f1f0f2
commit
f9d1f922dc
22 changed files with 117 additions and 122 deletions
|
@ -10,7 +10,7 @@ use super::{
|
|||
use crate::errors;
|
||||
use crate::maybe_recover_from_interpolated_ty_qpath;
|
||||
use ast::mut_visit::{noop_visit_expr, MutVisitor};
|
||||
use ast::{GenBlockKind, Pat, Path, PathSegment};
|
||||
use ast::{CoroutineKind, GenBlockKind, Pat, Path, PathSegment};
|
||||
use core::mem;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
|
||||
|
@ -21,9 +21,7 @@ use rustc_ast::util::parser::{prec_let_scrutinee_needs_par, AssocOp, Fixity};
|
|||
use rustc_ast::visit::Visitor;
|
||||
use rustc_ast::{self as ast, AttrStyle, AttrVec, CaptureBy, ExprField, UnOp, DUMMY_NODE_ID};
|
||||
use rustc_ast::{AnonConst, BinOp, BinOpKind, FnDecl, FnRetTy, MacCall, Param, Ty, TyKind};
|
||||
use rustc_ast::{
|
||||
Arm, BlockCheckMode, CoroutineKind, Expr, ExprKind, Label, Movability, RangeLimits,
|
||||
};
|
||||
use rustc_ast::{Arm, BlockCheckMode, Expr, ExprKind, Label, Movability, RangeLimits};
|
||||
use rustc_ast::{ClosureBinder, MetaItemLit, StmtKind};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
|
@ -2239,7 +2237,7 @@ impl<'a> Parser<'a> {
|
|||
let asyncness = if self.token.uninterpolated_span().at_least_rust_2018() {
|
||||
self.parse_asyncness(Case::Sensitive)
|
||||
} else {
|
||||
CoroutineKind::None
|
||||
None
|
||||
};
|
||||
|
||||
let capture_clause = self.parse_capture_clause()?;
|
||||
|
@ -2263,7 +2261,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
};
|
||||
|
||||
if let CoroutineKind::Async { span, .. } = asyncness {
|
||||
if let Some(CoroutineKind::Async { span, .. }) = asyncness {
|
||||
// Feature-gate `async ||` closures.
|
||||
self.sess.gated_spans.gate(sym::async_closure, span);
|
||||
}
|
||||
|
|
|
@ -2401,7 +2401,7 @@ impl<'a> Parser<'a> {
|
|||
let ext_start_sp = self.token.span;
|
||||
let ext = self.parse_extern(case);
|
||||
|
||||
if let CoroutineKind::Async { span, .. } = asyncness {
|
||||
if let Some(CoroutineKind::Async { span, .. }) = asyncness {
|
||||
if span.is_rust_2015() {
|
||||
self.sess.emit_err(errors::AsyncFnIn2015 {
|
||||
span,
|
||||
|
@ -2410,13 +2410,13 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
if let CoroutineKind::Gen { span, .. } = genness {
|
||||
if let Some(CoroutineKind::Gen { span, .. }) = genness {
|
||||
self.sess.gated_spans.gate(sym::gen_blocks, span);
|
||||
}
|
||||
|
||||
if let (
|
||||
CoroutineKind::Async { span: async_span, .. },
|
||||
CoroutineKind::Gen { span: gen_span, .. },
|
||||
Some(CoroutineKind::Async { span: async_span, .. }),
|
||||
Some(CoroutineKind::Gen { span: gen_span, .. }),
|
||||
) = (asyncness, genness)
|
||||
{
|
||||
self.sess.emit_err(errors::AsyncGenFn { span: async_span.to(gen_span) });
|
||||
|
@ -2452,16 +2452,18 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
} else if self.check_keyword(kw::Async) {
|
||||
match asyncness {
|
||||
CoroutineKind::Async { span, .. } => Some(WrongKw::Duplicated(span)),
|
||||
CoroutineKind::Gen { .. } => {
|
||||
Some(CoroutineKind::Async { span, .. }) => {
|
||||
Some(WrongKw::Duplicated(span))
|
||||
}
|
||||
Some(CoroutineKind::Gen { .. }) => {
|
||||
panic!("not sure how to recover here")
|
||||
}
|
||||
CoroutineKind::None => {
|
||||
recover_asyncness = CoroutineKind::Async {
|
||||
None => {
|
||||
recover_asyncness = Some(CoroutineKind::Async {
|
||||
span: self.token.span,
|
||||
closure_id: DUMMY_NODE_ID,
|
||||
return_impl_trait_id: DUMMY_NODE_ID,
|
||||
};
|
||||
});
|
||||
Some(WrongKw::Misplaced(unsafe_start_sp))
|
||||
}
|
||||
}
|
||||
|
@ -2566,9 +2568,9 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
let coro_kind = match asyncness {
|
||||
CoroutineKind::Async { .. } => asyncness,
|
||||
CoroutineKind::Gen { .. } => unreachable!("asycness cannot be Gen"),
|
||||
CoroutineKind::None => genness,
|
||||
Some(CoroutineKind::Async { .. }) => asyncness,
|
||||
Some(CoroutineKind::Gen { .. }) => unreachable!("asycness cannot be Gen"),
|
||||
None => genness,
|
||||
};
|
||||
|
||||
Ok(FnHeader { constness, unsafety, coro_kind, ext })
|
||||
|
|
|
@ -1125,30 +1125,30 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
/// Parses asyncness: `async` or nothing.
|
||||
fn parse_asyncness(&mut self, case: Case) -> CoroutineKind {
|
||||
fn parse_asyncness(&mut self, case: Case) -> Option<CoroutineKind> {
|
||||
if self.eat_keyword_case(kw::Async, case) {
|
||||
let span = self.prev_token.uninterpolated_span();
|
||||
CoroutineKind::Async {
|
||||
Some(CoroutineKind::Async {
|
||||
span,
|
||||
closure_id: DUMMY_NODE_ID,
|
||||
return_impl_trait_id: DUMMY_NODE_ID,
|
||||
}
|
||||
})
|
||||
} else {
|
||||
CoroutineKind::None
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses genness: `gen` or nothing.
|
||||
fn parse_genness(&mut self, case: Case) -> CoroutineKind {
|
||||
fn parse_genness(&mut self, case: Case) -> Option<CoroutineKind> {
|
||||
if self.token.span.at_least_rust_2024() && self.eat_keyword_case(kw::Gen, case) {
|
||||
let span = self.prev_token.uninterpolated_span();
|
||||
CoroutineKind::Gen {
|
||||
Some(CoroutineKind::Gen {
|
||||
span,
|
||||
closure_id: DUMMY_NODE_ID,
|
||||
return_impl_trait_id: DUMMY_NODE_ID,
|
||||
}
|
||||
})
|
||||
} else {
|
||||
CoroutineKind::None
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -609,7 +609,7 @@ impl<'a> Parser<'a> {
|
|||
// cover it.
|
||||
self.sess.emit_err(FnPointerCannotBeConst { span: whole_span, qualifier: span });
|
||||
}
|
||||
if let ast::CoroutineKind::Async { span, .. } = coro_kind {
|
||||
if let Some(ast::CoroutineKind::Async { span, .. }) = coro_kind {
|
||||
self.sess.emit_err(FnPointerCannotBeAsync { span: whole_span, qualifier: span });
|
||||
}
|
||||
// FIXME(eholk): emit a similar error for `gen fn()`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue