Skip to content

Commit 29ed9a5

Browse files
committed
migrate maybe_consume_incorrect_semicolon diagnostic
1 parent bd4d1cd commit 29ed9a5

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

compiler/rustc_error_messages/locales/en-US/parser.ftl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ parser-expect-path = expected a path
1818
parser-maybe-recover-from-bad-qpath-stage-2 =
1919
missing angle brackets in associated item path
2020
.suggestion = try: `{$ty}`
21+
22+
parser-incorrect-semicolon =
23+
expected item, found `;`
24+
.suggestion = remove this semicolon
25+
.help = {$name} declarations are not followed by a semicolon

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,17 @@ struct BadQPathStage2 {
295295
ty: String,
296296
}
297297

298+
#[derive(SessionDiagnostic)]
299+
#[error(slug = "parser-incorrect-semicolon")]
300+
struct IncorrectSemicolon<'a> {
301+
#[primary_span]
302+
#[suggestion(applicability = "machine-applicable")]
303+
span: Span,
304+
#[help]
305+
opt_help: Option<()>,
306+
name: &'a str,
307+
}
308+
298309
// SnapshotParser is used to create a snapshot of the parser
299310
// without causing duplicate errors being emitted when the `Parser`
300311
// is dropped.
@@ -1490,13 +1501,10 @@ impl<'a> Parser<'a> {
14901501
pub fn maybe_consume_incorrect_semicolon(&mut self, items: &[P<Item>]) -> bool {
14911502
if self.token.kind == TokenKind::Semi {
14921503
self.bump();
1493-
let mut err = self.struct_span_err(self.prev_token.span, "expected item, found `;`");
1494-
err.span_suggestion_short(
1495-
self.prev_token.span,
1496-
"remove this semicolon",
1497-
String::new(),
1498-
Applicability::MachineApplicable,
1499-
);
1504+
1505+
let mut err =
1506+
IncorrectSemicolon { span: self.prev_token.span, opt_help: None, name: "" };
1507+
15001508
if !items.is_empty() {
15011509
let previous_item = &items[items.len() - 1];
15021510
let previous_item_kind_name = match previous_item.kind {
@@ -1509,10 +1517,11 @@ impl<'a> Parser<'a> {
15091517
_ => None,
15101518
};
15111519
if let Some(name) = previous_item_kind_name {
1512-
err.help(&format!("{name} declarations are not followed by a semicolon"));
1520+
err.opt_help = Some(());
1521+
err.name = name;
15131522
}
15141523
}
1515-
err.emit();
1524+
self.sess.emit_err(err);
15161525
true
15171526
} else {
15181527
false

0 commit comments

Comments
 (0)