diff options
| author | Aaron Hill <aa1ronham@gmail.com> | 2020-02-14 22:28:13 -0500 |
|---|---|---|
| committer | Aaron Hill <aa1ronham@gmail.com> | 2020-02-14 22:28:13 -0500 |
| commit | 98757f14d0242e6dcae258df8aeb7e17580702ef (patch) | |
| tree | fad7a75a98cf274d2f1d0803461c25cb4d8affa8 /src/librustc_parse | |
| parent | b92c6ee882853313698f1148512e8e992ba36b2d (diff) | |
| download | rust-98757f14d0242e6dcae258df8aeb7e17580702ef.tar.gz rust-98757f14d0242e6dcae258df8aeb7e17580702ef.zip | |
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.
Diffstat (limited to 'src/librustc_parse')
| -rw-r--r-- | src/librustc_parse/parser/expr.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs index 5a4225ece65..20b9df0a2d9 100644 --- a/src/librustc_parse/parser/expr.rs +++ b/src/librustc_parse/parser/expr.rs @@ -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); |
