Skip to content

Commit 1c51e25

Browse files
committed
Auto merge of #15994 - ChayimFriedman2:err-comma-after-fus, 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 #15989.
2 parents 56abc0a + 2fd19ed commit 1c51e25

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

crates/parser/src/grammar/expressions.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,17 @@ pub(crate) fn record_expr_field_list(p: &mut Parser<'_>) {
693693
// We permit `.. }` on the left-hand side of a destructuring assignment.
694694
if !p.at(T!['}']) {
695695
expr(p);
696+
697+
if p.at(T![,]) {
698+
// test_err comma_after_functional_update_syntax
699+
// fn foo() {
700+
// S { ..x, };
701+
// S { ..x, a: 0 }
702+
// }
703+
704+
// Do not bump, so we can support additional fields after this comma.
705+
p.error("cannot use a comma after the base struct");
706+
}
696707
}
697708
}
698709
T!['{'] => {
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
SOURCE_FILE
2+
FN
3+
FN_KW "fn"
4+
WHITESPACE " "
5+
NAME
6+
IDENT "foo"
7+
PARAM_LIST
8+
L_PAREN "("
9+
R_PAREN ")"
10+
WHITESPACE " "
11+
BLOCK_EXPR
12+
STMT_LIST
13+
L_CURLY "{"
14+
WHITESPACE "\n "
15+
EXPR_STMT
16+
RECORD_EXPR
17+
PATH
18+
PATH_SEGMENT
19+
NAME_REF
20+
IDENT "S"
21+
WHITESPACE " "
22+
RECORD_EXPR_FIELD_LIST
23+
L_CURLY "{"
24+
WHITESPACE " "
25+
DOT2 ".."
26+
PATH_EXPR
27+
PATH
28+
PATH_SEGMENT
29+
NAME_REF
30+
IDENT "x"
31+
COMMA ","
32+
WHITESPACE " "
33+
R_CURLY "}"
34+
SEMICOLON ";"
35+
WHITESPACE "\n "
36+
RECORD_EXPR
37+
PATH
38+
PATH_SEGMENT
39+
NAME_REF
40+
IDENT "S"
41+
WHITESPACE " "
42+
RECORD_EXPR_FIELD_LIST
43+
L_CURLY "{"
44+
WHITESPACE " "
45+
DOT2 ".."
46+
PATH_EXPR
47+
PATH
48+
PATH_SEGMENT
49+
NAME_REF
50+
IDENT "x"
51+
COMMA ","
52+
WHITESPACE " "
53+
RECORD_EXPR_FIELD
54+
NAME_REF
55+
IDENT "a"
56+
COLON ":"
57+
WHITESPACE " "
58+
LITERAL
59+
INT_NUMBER "0"
60+
WHITESPACE " "
61+
R_CURLY "}"
62+
WHITESPACE "\n"
63+
R_CURLY "}"
64+
WHITESPACE "\n"
65+
error 22: cannot use a comma after the base struct
66+
error 38: cannot use a comma after the base struct
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn foo() {
2+
S { ..x, };
3+
S { ..x, a: 0 }
4+
}

0 commit comments

Comments
 (0)