Skip to content

Commit

Permalink
Auto merge of rust-lang#15994 - ChayimFriedman2:err-comma-after-fus, …
Browse files Browse the repository at this point in the history
…r=Veykril

fix: Err for comma after functional update syntax

Error message copied from rustc, https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=20aeedb2db504c4e4ced54b665e761d6.

Fixes rust-lang#15989.
  • Loading branch information
bors committed Nov 30, 2023
2 parents 56abc0a + 2fd19ed commit 1c51e25
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/parser/src/grammar/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,17 @@ pub(crate) fn record_expr_field_list(p: &mut Parser<'_>) {
// We permit `.. }` on the left-hand side of a destructuring assignment.
if !p.at(T!['}']) {
expr(p);

if p.at(T![,]) {
// test_err comma_after_functional_update_syntax
// fn foo() {
// S { ..x, };
// S { ..x, a: 0 }
// }

// Do not bump, so we can support additional fields after this comma.
p.error("cannot use a comma after the base struct");
}
}
}
T!['{'] => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
SOURCE_FILE
FN
FN_KW "fn"
WHITESPACE " "
NAME
IDENT "foo"
PARAM_LIST
L_PAREN "("
R_PAREN ")"
WHITESPACE " "
BLOCK_EXPR
STMT_LIST
L_CURLY "{"
WHITESPACE "\n "
EXPR_STMT
RECORD_EXPR
PATH
PATH_SEGMENT
NAME_REF
IDENT "S"
WHITESPACE " "
RECORD_EXPR_FIELD_LIST
L_CURLY "{"
WHITESPACE " "
DOT2 ".."
PATH_EXPR
PATH
PATH_SEGMENT
NAME_REF
IDENT "x"
COMMA ","
WHITESPACE " "
R_CURLY "}"
SEMICOLON ";"
WHITESPACE "\n "
RECORD_EXPR
PATH
PATH_SEGMENT
NAME_REF
IDENT "S"
WHITESPACE " "
RECORD_EXPR_FIELD_LIST
L_CURLY "{"
WHITESPACE " "
DOT2 ".."
PATH_EXPR
PATH
PATH_SEGMENT
NAME_REF
IDENT "x"
COMMA ","
WHITESPACE " "
RECORD_EXPR_FIELD
NAME_REF
IDENT "a"
COLON ":"
WHITESPACE " "
LITERAL
INT_NUMBER "0"
WHITESPACE " "
R_CURLY "}"
WHITESPACE "\n"
R_CURLY "}"
WHITESPACE "\n"
error 22: cannot use a comma after the base struct
error 38: cannot use a comma after the base struct
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn foo() {
S { ..x, };
S { ..x, a: 0 }
}

0 comments on commit 1c51e25

Please sign in to comment.