Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/librustc_parse/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1832,10 +1832,16 @@ impl<'a> Parser<'a> {
}
}
Err(mut e) => {
e.span_label(struct_sp, "while parsing this struct");
if let Some(f) = recovery_field {
fields.push(f);
e.span_suggestion(
self.prev_span.shrink_to_hi(),
"try adding a comma",
",".into(),
Applicability::MachineApplicable,
);
}
e.span_label(struct_sp, "while parsing this struct");
e.emit();
self.recover_stmt_(SemiColonMode::Comma, BlockMode::Ignore);
self.eat(&token::Comma);
Expand Down
5 changes: 3 additions & 2 deletions src/test/ui/parser/removed-syntax-with-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ error: expected one of `,`, `.`, `?`, `}`, or an operator, found `with`
--> $DIR/removed-syntax-with-1.rs:8:25
|
LL | let b = S { foo: () with a, bar: () };
| - ^^^^ expected one of `,`, `.`, `?`, `}`, or an operator
| |
| - -^^^^ expected one of `,`, `.`, `?`, `}`, or an operator
| | |
| | help: try adding a comma: `,`
| while parsing this struct

error: aborting due to previous error
Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/suggestions/struct-initializer-comma.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
struct Foo {
first: bool,
second: u8,
}

fn main() {
let a = Foo {
//~^ ERROR missing field
first: true
second: 25
//~^ ERROR expected one of
};
}
23 changes: 23 additions & 0 deletions src/test/ui/suggestions/struct-initializer-comma.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
error: expected one of `,`, `.`, `?`, `}`, or an operator, found `second`
--> $DIR/struct-initializer-comma.rs:10:9
|
LL | let a = Foo {
| --- while parsing this struct
LL |
LL | first: true
| -
| |
| expected one of `,`, `.`, `?`, `}`, or an operator
| help: try adding a comma: `,`
LL | second: 25
| ^^^^^^ unexpected token

error[E0063]: missing field `second` in initializer of `Foo`
--> $DIR/struct-initializer-comma.rs:7:13
|
LL | let a = Foo {
| ^^^ missing `second`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0063`.