fix: Recover from = in record constructor field assignment

This commit is contained in:
Lukas Wirth 2024-02-13 18:23:28 +01:00
parent 925705e0c9
commit ccccc299c8
4 changed files with 82 additions and 27 deletions

View file

@ -678,27 +678,38 @@ pub(crate) fn record_expr_field_list(p: &mut Parser<'_>) {
attributes::outer_attrs(p);
match p.current() {
IDENT | INT_NUMBER => {
IDENT | INT_NUMBER if p.nth_at(1, T![::]) => {
// test_err record_literal_missing_ellipsis_recovery
// fn main() {
// S { S::default() }
// }
if p.nth_at(1, T![::]) {
m.abandon(p);
p.expect(T![..]);
expr(p);
} else {
m.abandon(p);
p.expect(T![..]);
expr(p);
}
IDENT | INT_NUMBER => {
if p.nth_at(1, T![..]) {
// test_err record_literal_before_ellipsis_recovery
// fn main() {
// S { field ..S::default() }
// }
if p.nth_at(1, T![:]) || p.nth_at(1, T![..]) {
name_ref_or_index(p);
p.error("expected colon");
} else {
// test_err record_literal_field_eq_recovery
// fn main() {
// S { field = foo }
// }
if p.nth_at(1, T![:]) {
name_ref_or_index(p);
p.expect(T![:]);
p.bump(T![:]);
} else if p.nth_at(1, T![=]) {
name_ref_or_index(p);
p.err_and_bump("expected colon");
}
expr(p);
m.complete(p, RECORD_EXPR_FIELD);
}
m.complete(p, RECORD_EXPR_FIELD);
}
T![.] if p.at(T![..]) => {
m.abandon(p);