-
Couldn't load subscription status.
- Fork 13.9k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
Description
Test case: (playground link)
struct S {
foo: u32 // <- missing comma
bar: u32
}
fn main() {
let s = S { foo: 5, bar: 6 };
}Actual result (nightly):
error: expected `,`, or `}`, found `bar`
--> src/main.rs:3:5
|
3 | bar: u32
| ^^^
|
= help: struct fields should be separated by commas
error[E0560]: struct `S` has no field named `foo`
--> src/main.rs:7:17
|
7 | let s = S { foo: 5, bar: 6 };
| ^^^ `S` does not have this field
error[E0560]: struct `S` has no field named `bar`
--> src/main.rs:7:25
|
7 | let s = S { foo: 5, bar: 6 };
| ^^^ `S` does not have this field
Expected result:
Ideally the parser would guess that there was meant to be a comma at the end of the line. Then:
- The "expected comma" error could highlight the line missing a comma (and suggest a fix-it), rather than highlighting the first token in the next line.
- After producing an error, it could recover by pretending the comma was there, adding the
fooandbarfields to the struct to avoid the latter two errors.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.