about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-02-14 17:35:12 +0000
committerGitHub <noreply@github.com>2022-02-14 17:35:12 +0000
commit014d3ef1a4b69c4329aba9e0c27cd7a8649e33c2 (patch)
tree399a87abc5e75887618ae502c68f6b4ba1ab7d9d
parent0247e5067606a0b642fcfa463a26acfaf8a26557 (diff)
parent06452cd102dc78df4e26eeacfb8d0e3cf8a2b711 (diff)
downloadrust-014d3ef1a4b69c4329aba9e0c27cd7a8649e33c2.tar.gz
rust-014d3ef1a4b69c4329aba9e0c27cd7a8649e33c2.zip
Merge #11458
11458: Fix  Immovable generator syntax (static ||) not recognized #11448 r=Veykril a=bellau



Co-authored-by: bellau <laurent.belmonte@gmail.com>
-rw-r--r--crates/parser/src/grammar/expressions/atom.rs20
-rw-r--r--crates/parser/src/grammar/items.rs2
-rw-r--r--crates/parser/test_data/parser/inline/ok/0106_lambda_expr.rs4
-rw-r--r--crates/parser/test_data/parser/inline/ok/0106_lambda_expr.txt64
4 files changed, 87 insertions, 3 deletions
diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs
index 640caa07780..4b7a1b31fbd 100644
--- a/crates/parser/src/grammar/expressions/atom.rs
+++ b/crates/parser/src/grammar/expressions/atom.rs
@@ -72,8 +72,12 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
         T!['('] => tuple_expr(p),
         T!['['] => array_expr(p),
         T![|] => closure_expr(p),
-        T![move] if la == T![|] => closure_expr(p),
-        T![async] if la == T![|] || (la == T![move] && p.nth(2) == T![|]) => closure_expr(p),
+        T![static] | T![async] | T![move] if la == T![|] => closure_expr(p),
+        T![static] | T![async] if la == T![move] && p.nth(2) == T![|] => closure_expr(p),
+        T![static] if la == T![async] && p.nth(2) == T![|] => closure_expr(p),
+        T![static] if la == T![async] && p.nth(2) == T![move] && p.nth(3) == T![|] => {
+            closure_expr(p)
+        }
         T![if] => if_expr(p),
 
         T![loop] => loop_expr(p, None),
@@ -234,6 +238,10 @@ fn array_expr(p: &mut Parser) -> CompletedMarker {
 //     async || {};
 //     move || {};
 //     async move || {};
+//     static || {};
+//     static move || {};
+//     static async || {};
+//     static async move || {};
 // }
 fn closure_expr(p: &mut Parser) -> CompletedMarker {
     assert!(
@@ -241,8 +249,16 @@ fn closure_expr(p: &mut Parser) -> CompletedMarker {
             || (p.at(T![move]) && p.nth(1) == T![|])
             || (p.at(T![async]) && p.nth(1) == T![|])
             || (p.at(T![async]) && p.nth(1) == T![move] && p.nth(2) == T![|])
+            || (p.at(T![static]) && p.nth(1) == T![|])
+            || (p.at(T![static]) && p.nth(1) == T![move] && p.nth(2) == T![|])
+            || (p.at(T![static]) && p.nth(1) == T![async] && p.nth(2) == T![|])
+            || (p.at(T![static])
+                && p.nth(1) == T![async]
+                && p.nth(2) == T![move]
+                && p.nth(3) == T![|])
     );
     let m = p.start();
+    p.eat(T![static]);
     p.eat(T![async]);
     p.eat(T![move]);
     params::param_list_closure(p);
diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs
index 896efaf3757..36d13cc9773 100644
--- a/crates/parser/src/grammar/items.rs
+++ b/crates/parser/src/grammar/items.rs
@@ -230,7 +230,7 @@ fn opt_item_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
         IDENT if p.at_contextual_kw(T![macro_rules]) && p.nth(1) == BANG => macro_rules(p, m),
 
         T![const] if (la == IDENT || la == T![_] || la == T![mut]) => consts::konst(p, m),
-        T![static] => consts::static_(p, m),
+        T![static] if (la == IDENT || la == T![_] || la == T![mut]) => consts::static_(p, m),
 
         _ => return Err(m),
     };
diff --git a/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.rs b/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.rs
index 0757178239d..d01f9216642 100644
--- a/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.rs
+++ b/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.rs
@@ -6,4 +6,8 @@ fn foo() {
     async || {};
     move || {};
     async move || {};
+    static || {};
+    static move || {};
+    static async || {};
+    static async move || {};
 }
diff --git a/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.txt b/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.txt
index 45717889486..bc54b018697 100644
--- a/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.txt
+++ b/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.txt
@@ -135,6 +135,70 @@ SOURCE_FILE
                 L_CURLY "{"
                 R_CURLY "}"
           SEMICOLON ";"
+        WHITESPACE "\n    "
+        EXPR_STMT
+          CLOSURE_EXPR
+            STATIC_KW "static"
+            WHITESPACE " "
+            PARAM_LIST
+              PIPE "|"
+              PIPE "|"
+            WHITESPACE " "
+            BLOCK_EXPR
+              STMT_LIST
+                L_CURLY "{"
+                R_CURLY "}"
+          SEMICOLON ";"
+        WHITESPACE "\n    "
+        EXPR_STMT
+          CLOSURE_EXPR
+            STATIC_KW "static"
+            WHITESPACE " "
+            MOVE_KW "move"
+            WHITESPACE " "
+            PARAM_LIST
+              PIPE "|"
+              PIPE "|"
+            WHITESPACE " "
+            BLOCK_EXPR
+              STMT_LIST
+                L_CURLY "{"
+                R_CURLY "}"
+          SEMICOLON ";"
+        WHITESPACE "\n    "
+        EXPR_STMT
+          CLOSURE_EXPR
+            STATIC_KW "static"
+            WHITESPACE " "
+            ASYNC_KW "async"
+            WHITESPACE " "
+            PARAM_LIST
+              PIPE "|"
+              PIPE "|"
+            WHITESPACE " "
+            BLOCK_EXPR
+              STMT_LIST
+                L_CURLY "{"
+                R_CURLY "}"
+          SEMICOLON ";"
+        WHITESPACE "\n    "
+        EXPR_STMT
+          CLOSURE_EXPR
+            STATIC_KW "static"
+            WHITESPACE " "
+            ASYNC_KW "async"
+            WHITESPACE " "
+            MOVE_KW "move"
+            WHITESPACE " "
+            PARAM_LIST
+              PIPE "|"
+              PIPE "|"
+            WHITESPACE " "
+            BLOCK_EXPR
+              STMT_LIST
+                L_CURLY "{"
+                R_CURLY "}"
+          SEMICOLON ";"
         WHITESPACE "\n"
         R_CURLY "}"
   WHITESPACE "\n"