Skip to content

Commit

Permalink
more updates on parser
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Nov 14, 2023
1 parent 714a940 commit 4286151
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,21 +1262,28 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedSemi {
let token_descr = TokenDescription::from_token(&self.token);

let mut diag = handler.struct_diagnostic(match token_descr {
Some(TokenDescription::ReservedIdentifier) => {
fluent::parse_expected_semi_found_reserved_identifier_str
Some(TokenDescription::ReservedIdentifier) => DiagnosticMessage::Str(Cow::from(
"expected `;`, found reserved identifier `{$token}`",
)),
Some(TokenDescription::Keyword) => {
DiagnosticMessage::Str(Cow::from("expected `;`, found keyword `{$token}`"))
}
Some(TokenDescription::Keyword) => fluent::parse_expected_semi_found_keyword_str,
Some(TokenDescription::ReservedKeyword) => {
fluent::parse_expected_semi_found_reserved_keyword_str
DiagnosticMessage::Str(Cow::from("expected `;`, found reserved keyword `{$token}`"))
}
Some(TokenDescription::DocComment) => {
DiagnosticMessage::Str(Cow::from("expected `;`, found doc comment `{$token}`"))
}
Some(TokenDescription::DocComment) => fluent::parse_expected_semi_found_doc_comment_str,
None => fluent::parse_expected_semi_found_str,
None => DiagnosticMessage::Str(Cow::from("expected `;`, found `{$token}`")),
});
diag.set_span(self.span);
diag.set_arg("token", self.token);

if let Some(unexpected_token_label) = self.unexpected_token_label {
diag.span_label(unexpected_token_label, fluent::parse_label_unexpected_token);
diag.span_label(
unexpected_token_label,
DiagnosticMessage::Str(Cow::from("unexpected token")),
);
}

self.sugg.add_to_diagnostic(&mut diag);
Expand Down

0 comments on commit 4286151

Please sign in to comment.