about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/errors.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_parse/src/errors.rs')
-rw-r--r--compiler/rustc_parse/src/errors.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs
index 3b86dd15747..07785b7344f 100644
--- a/compiler/rustc_parse/src/errors.rs
+++ b/compiler/rustc_parse/src/errors.rs
@@ -963,3 +963,54 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedIdentifier {
         diag
     }
 }
+
+pub(crate) struct ExpectedSemi {
+    pub span: Span,
+    pub token_descr: TokenDescription,
+
+    pub unexpected_token_label: Option<Span>,
+    pub sugg: ExpectedSemiSugg,
+}
+
+impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedSemi {
+    fn into_diagnostic(
+        self,
+        handler: &'a rustc_errors::Handler,
+    ) -> rustc_errors::DiagnosticBuilder<'a, G> {
+        let mut diag = handler.struct_diagnostic(match self.token_descr.kind {
+            Some(TokenDescriptionKind::ReservedIdentifier) => {
+                fluent::parser::expected_semi_found_reserved_identifier_str
+            }
+            Some(TokenDescriptionKind::Keyword) => fluent::parser::expected_semi_found_keyword_str,
+            Some(TokenDescriptionKind::ReservedKeyword) => {
+                fluent::parser::expected_semi_found_reserved_keyword_str
+            }
+            Some(TokenDescriptionKind::DocComment) => {
+                fluent::parser::expected_semi_found_doc_comment_str
+            }
+            None => fluent::parser::expected_semi_found_str,
+        });
+        diag.set_span(self.span);
+        diag.set_arg("token_str", self.token_descr.name);
+
+        if let Some(unexpected_token_label) = self.unexpected_token_label {
+            diag.span_label(unexpected_token_label, fluent::parser::label_unexpected_token);
+        }
+
+        self.sugg.add_to_diagnostic(&mut diag);
+
+        diag
+    }
+}
+
+#[derive(Subdiagnostic)]
+pub(crate) enum ExpectedSemiSugg {
+    #[suggestion(
+        parser::sugg_change_this_to_semi,
+        code = ";",
+        applicability = "machine-applicable"
+    )]
+    ChangeToSemi(#[primary_span] Span),
+    #[suggestion_short(parser::sugg_add_semi, code = ";", applicability = "machine-applicable")]
+    AddSemi(#[primary_span] Span),
+}