about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/expr.rs
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2023-10-05 11:30:55 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2023-10-26 06:49:17 +0000
commita61cf673cd10ed24394c3403e03d8f7cf1f50170 (patch)
treedbf3c9adb68cb079695fc7b2e6999f162aeb42dd /compiler/rustc_parse/src/parser/expr.rs
parentccb160d3432dff025ab62696a82e576bf08aa006 (diff)
downloadrust-a61cf673cd10ed24394c3403e03d8f7cf1f50170.tar.gz
rust-a61cf673cd10ed24394c3403e03d8f7cf1f50170.zip
Reserve `gen` keyword for `gen {}` blocks and `gen fn` in 2024 edition
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index 5157106f4e2..e59076acf4c 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -1422,6 +1422,9 @@ impl<'a> Parser<'a> {
             } else if this.is_try_block() {
                 this.expect_keyword(kw::Try)?;
                 this.parse_try_block(lo)
+            } else if this.is_gen_block() {
+                this.expect_keyword(kw::Gen)?;
+                this.parse_gen_block(lo)
             } else if this.eat_keyword(kw::Return) {
                 this.parse_expr_return()
             } else if this.eat_keyword(kw::Continue) {
@@ -3040,6 +3043,14 @@ impl<'a> Parser<'a> {
         }
     }
 
+    /// Parses a `gen {...}` expression (`gen` token already eaten).
+    fn parse_gen_block(&mut self, _span_lo: Span) -> PResult<'a, P<Expr>> {
+        let (_attrs, _body) = self.parse_inner_attrs_and_block()?;
+
+        Err(errors::GenBlock { span: self.prev_token.span }
+            .into_diagnostic(&self.sess.span_diagnostic))
+    }
+
     fn is_do_catch_block(&self) -> bool {
         self.token.is_keyword(kw::Do)
             && self.is_keyword_ahead(1, &[kw::Catch])
@@ -3059,6 +3070,13 @@ impl<'a> Parser<'a> {
             && self.token.uninterpolated_span().at_least_rust_2018()
     }
 
+    fn is_gen_block(&self) -> bool {
+        self.token.is_keyword(kw::Gen)
+            && self
+                .look_ahead(1, |t| *t == token::OpenDelim(Delimiter::Brace) || t.is_whole_block())
+            && self.token.uninterpolated_span().at_least_rust_2024()
+    }
+
     /// Parses an `async move? {...}` expression.
     fn parse_async_block(&mut self) -> PResult<'a, P<Expr>> {
         let lo = self.token.span;