Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 0a18a05

Browse files
committed
fix handle static async and static async move
1 parent 3ed19d5 commit 0a18a05

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

crates/parser/src/grammar/expressions/atom.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,14 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
7474
T![|] => closure_expr(p),
7575
T![move] if la == T![|] => closure_expr(p),
7676
T![async] if la == T![|] || (la == T![move] && p.nth(2) == T![|]) => closure_expr(p),
77-
T![static] if la == T![|] || (la == T![move] && p.nth(2) == T![|]) => closure_expr(p),
77+
T![static]
78+
if la == T![|]
79+
|| (la == T![move] && p.nth(2) == T![|])
80+
|| (la == T![async] && p.nth(2) == T![|])
81+
|| (la == T![async] && p.nth(2) == T![move] && p.nth(3) == T![|]) =>
82+
{
83+
closure_expr(p)
84+
}
7885
T![if] => if_expr(p),
7986

8087
T![loop] => loop_expr(p, None),
@@ -237,6 +244,8 @@ fn array_expr(p: &mut Parser) -> CompletedMarker {
237244
// async move || {};
238245
// static || {};
239246
// static move || {};
247+
// static async || {};
248+
// static async move || {};
240249
// }
241250
fn closure_expr(p: &mut Parser) -> CompletedMarker {
242251
assert!(
@@ -246,17 +255,23 @@ fn closure_expr(p: &mut Parser) -> CompletedMarker {
246255
|| (p.at(T![async]) && p.nth(1) == T![move] && p.nth(2) == T![|])
247256
|| (p.at(T![static]) && p.nth(1) == T![|])
248257
|| (p.at(T![static]) && p.nth(1) == T![move] && p.nth(2) == T![|])
258+
|| (p.at(T![static]) && p.nth(1) == T![async] && p.nth(2) == T![|])
259+
|| (p.at(T![static])
260+
&& p.nth(1) == T![async]
261+
&& p.nth(2) == T![move]
262+
&& p.nth(3) == T![|])
249263
);
250264
let m = p.start();
251-
p.eat(T![async]);
252265
p.eat(T![static]);
266+
p.eat(T![async]);
253267
p.eat(T![move]);
254268
params::param_list_closure(p);
255269
if opt_ret_type(p) {
256270
// test lambda_ret_block
257271
// fn main() { || -> i32 { 92 }(); }
258272
block_expr(p);
259273
} else if p.at_ts(EXPR_FIRST) {
274+
println!("gg");
260275
expr(p);
261276
} else {
262277
p.error("expected expression");

crates/parser/src/grammar/items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ fn opt_item_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
230230
IDENT if p.at_contextual_kw(T![macro_rules]) && p.nth(1) == BANG => macro_rules(p, m),
231231

232232
T![const] if (la == IDENT || la == T![_] || la == T![mut]) => consts::konst(p, m),
233-
T![static] if (la != PIPE && la != T![move]) => consts::static_(p, m),
233+
T![static] if (la != PIPE && la != T![move] && la != T![async]) => consts::static_(p, m),
234234

235235
_ => return Err(m),
236236
};

crates/parser/test_data/parser/inline/ok/0106_lambda_expr.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ fn foo() {
88
async move || {};
99
static || {};
1010
static move || {};
11+
static async || {};
12+
static async move || {};
1113
}

crates/parser/test_data/parser/inline/ok/0106_lambda_expr.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,40 @@ SOURCE_FILE
165165
L_CURLY "{"
166166
R_CURLY "}"
167167
SEMICOLON ";"
168+
WHITESPACE "\n "
169+
EXPR_STMT
170+
CLOSURE_EXPR
171+
STATIC_KW "static"
172+
WHITESPACE " "
173+
ASYNC_KW "async"
174+
WHITESPACE " "
175+
PARAM_LIST
176+
PIPE "|"
177+
PIPE "|"
178+
WHITESPACE " "
179+
BLOCK_EXPR
180+
STMT_LIST
181+
L_CURLY "{"
182+
R_CURLY "}"
183+
SEMICOLON ";"
184+
WHITESPACE "\n "
185+
EXPR_STMT
186+
CLOSURE_EXPR
187+
STATIC_KW "static"
188+
WHITESPACE " "
189+
ASYNC_KW "async"
190+
WHITESPACE " "
191+
MOVE_KW "move"
192+
WHITESPACE " "
193+
PARAM_LIST
194+
PIPE "|"
195+
PIPE "|"
196+
WHITESPACE " "
197+
BLOCK_EXPR
198+
STMT_LIST
199+
L_CURLY "{"
200+
R_CURLY "}"
201+
SEMICOLON ";"
168202
WHITESPACE "\n"
169203
R_CURLY "}"
170204
WHITESPACE "\n"

0 commit comments

Comments
 (0)