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

Commit 014d3ef

Browse files
bors[bot]bellau
andauthored
11458: Fix Immovable generator syntax (static ||) not recognized rust-lang#11448 r=Veykril a=bellau Co-authored-by: bellau <[email protected]>
2 parents 0247e50 + 06452cd commit 014d3ef

File tree

4 files changed

+87
-3
lines changed

4 files changed

+87
-3
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
7272
T!['('] => tuple_expr(p),
7373
T!['['] => array_expr(p),
7474
T![|] => closure_expr(p),
75-
T![move] if la == T![|] => closure_expr(p),
76-
T![async] if la == T![|] || (la == T![move] && p.nth(2) == T![|]) => closure_expr(p),
75+
T![static] | T![async] | T![move] if la == T![|] => closure_expr(p),
76+
T![static] | T![async] if la == T![move] && p.nth(2) == T![|] => closure_expr(p),
77+
T![static] if la == T![async] && p.nth(2) == T![|] => closure_expr(p),
78+
T![static] if la == T![async] && p.nth(2) == T![move] && p.nth(3) == T![|] => {
79+
closure_expr(p)
80+
}
7781
T![if] => if_expr(p),
7882

7983
T![loop] => loop_expr(p, None),
@@ -234,15 +238,27 @@ fn array_expr(p: &mut Parser) -> CompletedMarker {
234238
// async || {};
235239
// move || {};
236240
// async move || {};
241+
// static || {};
242+
// static move || {};
243+
// static async || {};
244+
// static async move || {};
237245
// }
238246
fn closure_expr(p: &mut Parser) -> CompletedMarker {
239247
assert!(
240248
p.at(T![|])
241249
|| (p.at(T![move]) && p.nth(1) == T![|])
242250
|| (p.at(T![async]) && p.nth(1) == T![|])
243251
|| (p.at(T![async]) && p.nth(1) == T![move] && p.nth(2) == T![|])
252+
|| (p.at(T![static]) && p.nth(1) == T![|])
253+
|| (p.at(T![static]) && p.nth(1) == T![move] && p.nth(2) == T![|])
254+
|| (p.at(T![static]) && p.nth(1) == T![async] && p.nth(2) == T![|])
255+
|| (p.at(T![static])
256+
&& p.nth(1) == T![async]
257+
&& p.nth(2) == T![move]
258+
&& p.nth(3) == T![|])
244259
);
245260
let m = p.start();
261+
p.eat(T![static]);
246262
p.eat(T![async]);
247263
p.eat(T![move]);
248264
params::param_list_closure(p);

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] => consts::static_(p, m),
233+
T![static] if (la == IDENT || la == T![_] || la == T![mut]) => consts::static_(p, m),
234234

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

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ fn foo() {
66
async || {};
77
move || {};
88
async move || {};
9+
static || {};
10+
static move || {};
11+
static async || {};
12+
static async move || {};
913
}

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,70 @@ SOURCE_FILE
135135
L_CURLY "{"
136136
R_CURLY "}"
137137
SEMICOLON ";"
138+
WHITESPACE "\n "
139+
EXPR_STMT
140+
CLOSURE_EXPR
141+
STATIC_KW "static"
142+
WHITESPACE " "
143+
PARAM_LIST
144+
PIPE "|"
145+
PIPE "|"
146+
WHITESPACE " "
147+
BLOCK_EXPR
148+
STMT_LIST
149+
L_CURLY "{"
150+
R_CURLY "}"
151+
SEMICOLON ";"
152+
WHITESPACE "\n "
153+
EXPR_STMT
154+
CLOSURE_EXPR
155+
STATIC_KW "static"
156+
WHITESPACE " "
157+
MOVE_KW "move"
158+
WHITESPACE " "
159+
PARAM_LIST
160+
PIPE "|"
161+
PIPE "|"
162+
WHITESPACE " "
163+
BLOCK_EXPR
164+
STMT_LIST
165+
L_CURLY "{"
166+
R_CURLY "}"
167+
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 ";"
138202
WHITESPACE "\n"
139203
R_CURLY "}"
140204
WHITESPACE "\n"

0 commit comments

Comments
 (0)