]> git.lizzy.rs Git - rust.git/blobdiff - crates/parser/src/grammar/expressions/atom.rs
parameters.split_last()
[rust.git] / crates / parser / src / grammar / expressions / atom.rs
index bb70c0d93224101fac81aab8fb7b9fc7dd1e5489..4b7a1b31fbdfc6ee78df6ee330ef73515f0453bd 100644 (file)
@@ -39,7 +39,6 @@ pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> {
         T!['('],
         T!['{'],
         T!['['],
-        L_DOLLAR,
         T![|],
         T![move],
         T![box],
@@ -59,7 +58,7 @@ pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> {
         LIFETIME_IDENT,
     ]));
 
-const EXPR_RECOVERY_SET: TokenSet = TokenSet::new(&[LET_KW, R_DOLLAR]);
+const EXPR_RECOVERY_SET: TokenSet = TokenSet::new(&[T![let]]);
 
 pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)> {
     if let Some(m) = literal(p) {
@@ -72,10 +71,13 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
     let done = match p.current() {
         T!['('] => tuple_expr(p),
         T!['['] => array_expr(p),
-        L_DOLLAR => meta_var_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),
@@ -236,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!(
@@ -243,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);
@@ -374,7 +388,7 @@ fn match_expr(p: &mut Parser) -> CompletedMarker {
     if p.at(T!['{']) {
         match_arm_list(p);
     } else {
-        p.error("expected `{`")
+        p.error("expected `{`");
     }
     m.complete(p, MATCH_EXPR)
 }
@@ -602,7 +616,7 @@ fn try_block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
     if p.at(T!['{']) {
         stmt_list(p);
     } else {
-        p.error("expected a block")
+        p.error("expected a block");
     }
     m.complete(p, BLOCK_EXPR)
 }
@@ -622,27 +636,3 @@ fn box_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
     }
     m.complete(p, BOX_EXPR)
 }
-
-/// Expression from `$var` macro expansion, wrapped in dollars
-fn meta_var_expr(p: &mut Parser) -> CompletedMarker {
-    assert!(p.at(L_DOLLAR));
-    let m = p.start();
-    p.bump(L_DOLLAR);
-    let expr = expr_bp(p, None, Restrictions { forbid_structs: false, prefer_stmt: false }, 1);
-
-    match (expr, p.current()) {
-        (Some((cm, _)), R_DOLLAR) => {
-            p.bump(R_DOLLAR);
-            // FIXME: this leaves the dollar hanging in the air...
-            m.abandon(p);
-            cm
-        }
-        _ => {
-            while !p.at(R_DOLLAR) {
-                p.bump_any()
-            }
-            p.bump(R_DOLLAR);
-            m.complete(p, ERROR)
-        }
-    }
-}