Recover from using ;
as separator between fields
This commit is contained in:
parent
6e4a9ab650
commit
fbf11cfc13
@ -1526,6 +1526,17 @@ fn parse_single_struct_field(
|
||||
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();
|
||||
|
16
src/test/ui/parser/recover-field-semi.rs
Normal file
16
src/test/ui/parser/recover-field-semi.rs
Normal file
@ -0,0 +1,16 @@
|
||||
struct Foo {
|
||||
foo: i32;
|
||||
//~^ ERROR struct fields are separated by `,`
|
||||
}
|
||||
|
||||
union Bar { //~ ERROR
|
||||
foo: i32;
|
||||
//~^ ERROR union fields are separated by `,`
|
||||
}
|
||||
|
||||
enum Baz {
|
||||
Qux { foo: i32; }
|
||||
//~^ ERROR struct fields are separated by `,`
|
||||
}
|
||||
|
||||
fn main() {}
|
29
src/test/ui/parser/recover-field-semi.stderr
Normal file
29
src/test/ui/parser/recover-field-semi.stderr
Normal file
@ -0,0 +1,29 @@
|
||||
error: struct fields are separated by `,`
|
||||
--> $DIR/recover-field-semi.rs:2:13
|
||||
|
|
||||
LL | foo: i32;
|
||||
| ^ help: replace `;` with `,`
|
||||
|
||||
error: union fields are separated by `,`
|
||||
--> $DIR/recover-field-semi.rs:7:13
|
||||
|
|
||||
LL | foo: i32;
|
||||
| ^ help: replace `;` with `,`
|
||||
|
||||
error: struct fields are separated by `,`
|
||||
--> $DIR/recover-field-semi.rs:12:19
|
||||
|
|
||||
LL | Qux { foo: i32; }
|
||||
| ^ help: replace `;` with `,`
|
||||
|
||||
error: unions cannot have zero fields
|
||||
--> $DIR/recover-field-semi.rs:6:1
|
||||
|
|
||||
LL | / union Bar {
|
||||
LL | | foo: i32;
|
||||
LL | |
|
||||
LL | | }
|
||||
| |_^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
@ -1,6 +1,6 @@
|
||||
struct S {
|
||||
bar: ();
|
||||
//~^ ERROR expected `,`, or `}`, found `;`
|
||||
//~^ ERROR struct fields are separated by `,`
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: expected `,`, or `}`, found `;`
|
||||
error: struct fields are separated by `,`
|
||||
--> $DIR/removed-syntax-field-semicolon.rs:2:12
|
||||
|
|
||||
LL | bar: ();
|
||||
| ^
|
||||
| ^ help: replace `;` with `,`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user