Skip to content

Commit

Permalink
Auto merge of rust-lang#13762 - jonas-schievink:underscore-expr-first…
Browse files Browse the repository at this point in the history
…, r=jonas-schievink

fix: Fix parsing of `_ = x` in closure body

Fixes rust-lang/rust-analyzer#13757
  • Loading branch information
bors committed Dec 12, 2022
2 parents 21e61be + ed48bd8 commit 16c70fe
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/parser/src/grammar/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ fn expr_bp(
}

const LHS_FIRST: TokenSet =
atom::ATOM_EXPR_FIRST.union(TokenSet::new(&[T![&], T![*], T![!], T![.], T![-]]));
atom::ATOM_EXPR_FIRST.union(TokenSet::new(&[T![&], T![*], T![!], T![.], T![-], T![_]]));

fn lhs(p: &mut Parser<'_>, r: Restrictions) -> Option<(CompletedMarker, BlockLike)> {
let m;
Expand Down
2 changes: 2 additions & 0 deletions crates/parser/src/grammar/expressions/atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ fn closure_expr(p: &mut Parser<'_>) -> CompletedMarker {
// fn main() { || -> i32 { 92 }(); }
block_expr(p);
} else if p.at_ts(EXPR_FIRST) {
// test closure_body_underscore_assignment
// fn main() { || _ = 0; }
expr(p);
} else {
p.error("expected expression");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
SOURCE_FILE
FN
FN_KW "fn"
WHITESPACE " "
NAME
IDENT "main"
PARAM_LIST
L_PAREN "("
R_PAREN ")"
WHITESPACE " "
BLOCK_EXPR
STMT_LIST
L_CURLY "{"
WHITESPACE " "
EXPR_STMT
CLOSURE_EXPR
PARAM_LIST
PIPE "|"
PIPE "|"
WHITESPACE " "
BIN_EXPR
UNDERSCORE_EXPR
UNDERSCORE "_"
WHITESPACE " "
EQ "="
WHITESPACE " "
LITERAL
INT_NUMBER "0"
SEMICOLON ";"
WHITESPACE " "
R_CURLY "}"
WHITESPACE "\n"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() { || _ = 0; }

0 comments on commit 16c70fe

Please sign in to comment.