Reserve gen keyword for gen {} blocks and gen fn in 2024 edition

This commit is contained in:
Oli Scherer 2023-10-05 11:30:55 +00:00
parent ccb160d343
commit a61cf673cd
14 changed files with 138 additions and 4 deletions

View file

@ -11,6 +11,7 @@ mod stmt;
mod ty;
use crate::lexer::UnmatchedDelim;
use ast::Gen;
pub use attr_wrapper::AttrWrapper;
pub use diagnostics::AttemptLocalParseRecovery;
pub(crate) use expr::ForbiddenLetReason;
@ -1126,6 +1127,16 @@ impl<'a> Parser<'a> {
}
}
/// Parses genness: `gen` or nothing.
fn parse_genness(&mut self, case: Case) -> Gen {
if self.token.span.at_least_rust_2024() && self.eat_keyword_case(kw::Gen, case) {
let span = self.prev_token.uninterpolated_span();
Gen::Yes { span, closure_id: DUMMY_NODE_ID, return_impl_trait_id: DUMMY_NODE_ID }
} else {
Gen::No
}
}
/// Parses unsafety: `unsafe` or nothing.
fn parse_unsafety(&mut self, case: Case) -> Unsafe {
if self.eat_keyword_case(kw::Unsafe, case) {