Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions crates/parser/src/grammar/expressions/atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -234,15 +238,27 @@ 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!(
p.at(T![|])
|| (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);
Expand Down
2 changes: 1 addition & 1 deletion crates/parser/src/grammar/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
T![static] if (la == IDENT || la == T![_] || la == T![mut]) => consts::static_(p, m),
T![static] if (la == IDENT || la == T![mut]) => consts::static_(p, m),

underscore as name is not valid for statics

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without test '_' i have a regression on tests :
tests::parse_inline_err for the file 0013_anonymous_static.rs
the error is not the expected one

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah we recover in static_ from this, ye I guess this is fine then.


_ => return Err(m),
};
Expand Down
4 changes: 4 additions & 0 deletions crates/parser/test_data/parser/inline/ok/0106_lambda_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ fn foo() {
async || {};
move || {};
async move || {};
static || {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also include static move || {};?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I am going to had it too

static move || {};
static async || {};
static async move || {};
}
64 changes: 64 additions & 0 deletions crates/parser/test_data/parser/inline/ok/0106_lambda_expr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"