mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
fix: Recover from =
in record constructor field assignment
This commit is contained in:
parent
925705e0c9
commit
ccccc299c8
4 changed files with 82 additions and 27 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue