Support async gen fn

This commit is contained in:
Michael Goulet 2023-12-05 21:45:01 +00:00
parent 2806c2df7b
commit a208bae00e
16 changed files with 115 additions and 104 deletions

View file

@ -1125,23 +1125,30 @@ impl<'a> Parser<'a> {
}
/// Parses asyncness: `async` or nothing.
fn parse_asyncness(&mut self, case: Case) -> Option<CoroutineKind> {
fn parse_coroutine_kind(&mut self, case: Case) -> Option<CoroutineKind> {
let span = self.token.uninterpolated_span();
if self.eat_keyword_case(kw::Async, case) {
let span = self.prev_token.uninterpolated_span();
Some(CoroutineKind::Async {
span,
closure_id: DUMMY_NODE_ID,
return_impl_trait_id: DUMMY_NODE_ID,
})
} else {
None
}
}
/// Parses genness: `gen` or nothing.
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();
// FIXME(gen_blocks): Do we want to unconditionally parse `gen` and then
// error if edition <= 2024, like we do with async and edition <= 2018?
if self.token.uninterpolated_span().at_least_rust_2024()
&& self.eat_keyword_case(kw::Gen, case)
{
let gen_span = self.prev_token.uninterpolated_span();
Some(CoroutineKind::AsyncGen {
span: span.to(gen_span),
closure_id: DUMMY_NODE_ID,
return_impl_trait_id: DUMMY_NODE_ID,
})
} else {
Some(CoroutineKind::Async {
span,
closure_id: DUMMY_NODE_ID,
return_impl_trait_id: DUMMY_NODE_ID,
})
}
} else if self.token.uninterpolated_span().at_least_rust_2024()
&& self.eat_keyword_case(kw::Gen, case)
{
Some(CoroutineKind::Gen {
span,
closure_id: DUMMY_NODE_ID,