Rollup merge of #101457 - ChayimFriedman2:struct-field-semi, r=fee1-dead

Recover from using `;` as separator between fields

Partially fixes #101440 (only for record structs).

Doing that for tuple structs is harder as their parsing passes through a bunch of helper functions. I don't know how to do that. But [their error message is better anyway](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=cc6ee8bb2593596c0cea89d49e79bcb4) and suggests using a comma, even if it doesn't suggest replacing the semicolon with it.
This commit is contained in:
Guillaume Gomez 2022-09-06 17:00:28 +02:00 committed by GitHub
commit 78968e5959
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 3 deletions

View file

@ -1526,6 +1526,17 @@ impl<'a> Parser<'a> {
if self.token == token::Comma {
seen_comma = true;
}
if self.eat(&token::Semi) {
let sp = self.prev_token.span;
let mut err = self.struct_span_err(sp, format!("{adt_ty} fields are separated by `,`"));
err.span_suggestion_short(
sp,
"replace `;` with `,`",
",",
Applicability::MachineApplicable,
);
return Err(err);
}
match self.token.kind {
token::Comma => {
self.bump();