Suggest a comma if a struct initializer field fails to parse
Currently, we emit a "try adding a comma" suggestion if a comma is missing in a struct definition. However, we emit no such suggestion if a comma is missing in a struct initializer. This commit adds a "try adding a comma" suggestion when we don't find a comma during the parsing of a struct initializer field. The change to `src/test/ui/parser/removed-syntax-with-1.stderr` isn't great, but I don't see a good way of avoiding it.
This commit is contained in:
parent
b92c6ee882
commit
98757f14d0
4 changed files with 46 additions and 3 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue