Skip to content

Commit 7969b78

Browse files
lambtowolfpietroalbini
authored andcommitted
Issue rust-lang#50974: Suboptimal error in case of duplicate , in struct constructor
1 parent 7dae5c0 commit 7969b78

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,9 @@ impl<'a> Parser<'a> {
776776
err.span_label(self.span, format!("expected identifier, found {}", token_descr));
777777
} else {
778778
err.span_label(self.span, "expected identifier");
779+
if self.token == token::Comma {
780+
err.span_suggestion(self.span, "try removing a comma", ",".into());
781+
}
779782
}
780783
err
781784
}
@@ -2446,8 +2449,11 @@ impl<'a> Parser<'a> {
24462449
Err(mut e) => {
24472450
e.span_label(struct_sp, "while parsing this struct");
24482451
e.emit();
2449-
self.recover_stmt();
2450-
break;
2452+
2453+
if self.token != token::Comma {
2454+
self.recover_stmt();
2455+
break;
2456+
}
24512457
}
24522458
}
24532459

0 commit comments

Comments
 (0)