1 use rustc_ast::token::Token;
3 use rustc_errors::{fluent, AddToDiagnostic, Applicability, EmissionGuarantee, IntoDiagnostic};
4 use rustc_macros::{Diagnostic, Subdiagnostic};
5 use rustc_session::errors::ExprParenthesesNeeded;
6 use rustc_span::symbol::Ident;
7 use rustc_span::{Span, Symbol};
9 use crate::parser::TokenDescription;
12 #[diag(parse_maybe_report_ambiguous_plus)]
13 pub(crate) struct AmbiguousPlus {
16 #[suggestion(code = "({sum_ty})")]
21 #[diag(parse_maybe_recover_from_bad_type_plus, code = "E0178")]
22 pub(crate) struct BadTypePlus {
27 pub sub: BadTypePlusSub,
30 #[derive(Subdiagnostic)]
31 pub(crate) enum BadTypePlusSub {
34 code = "{sum_with_parens}",
35 applicability = "machine-applicable"
38 sum_with_parens: String,
42 #[label(parse_forgot_paren)]
47 #[label(parse_expect_path)]
55 #[diag(parse_maybe_recover_from_bad_qpath_stage_2)]
56 pub(crate) struct BadQPathStage2 {
58 #[suggestion(code = "", applicability = "maybe-incorrect")]
64 #[diag(parse_incorrect_semicolon)]
65 pub(crate) struct IncorrectSemicolon<'a> {
67 #[suggestion(style = "short", code = "", applicability = "machine-applicable")]
70 pub opt_help: Option<()>,
75 #[diag(parse_incorrect_use_of_await)]
76 pub(crate) struct IncorrectUseOfAwait {
78 #[suggestion(parentheses_suggestion, code = "", applicability = "machine-applicable")]
83 #[diag(parse_incorrect_use_of_await)]
84 pub(crate) struct IncorrectAwait {
87 #[suggestion(postfix_suggestion, code = "{expr}.await{question_mark}")]
88 pub sugg_span: (Span, Applicability),
90 pub question_mark: &'static str,
94 #[diag(parse_in_in_typo)]
95 pub(crate) struct InInTypo {
98 #[suggestion(code = "", applicability = "machine-applicable")]
102 #[derive(Diagnostic)]
103 #[diag(parse_invalid_variable_declaration)]
104 pub(crate) struct InvalidVariableDeclaration {
108 pub sub: InvalidVariableDeclarationSub,
111 #[derive(Subdiagnostic)]
112 pub(crate) enum InvalidVariableDeclarationSub {
113 #[suggestion(parse_switch_mut_let_order, applicability = "maybe-incorrect", code = "let mut")]
114 SwitchMutLetOrder(#[primary_span] Span),
116 parse_missing_let_before_mut,
117 applicability = "machine-applicable",
120 MissingLet(#[primary_span] Span),
121 #[suggestion(parse_use_let_not_auto, applicability = "machine-applicable", code = "let")]
122 UseLetNotAuto(#[primary_span] Span),
123 #[suggestion(parse_use_let_not_var, applicability = "machine-applicable", code = "let")]
124 UseLetNotVar(#[primary_span] Span),
127 #[derive(Diagnostic)]
128 #[diag(parse_invalid_comparison_operator)]
129 pub(crate) struct InvalidComparisonOperator {
134 pub sub: InvalidComparisonOperatorSub,
137 #[derive(Subdiagnostic)]
138 pub(crate) enum InvalidComparisonOperatorSub {
142 applicability = "machine-applicable",
151 #[label(spaceship_operator_invalid)]
152 Spaceship(#[primary_span] Span),
155 #[derive(Diagnostic)]
156 #[diag(parse_invalid_logical_operator)]
158 pub(crate) struct InvalidLogicalOperator {
161 pub incorrect: String,
163 pub sub: InvalidLogicalOperatorSub,
166 #[derive(Subdiagnostic)]
167 pub(crate) enum InvalidLogicalOperatorSub {
169 use_amp_amp_for_conjunction,
171 applicability = "machine-applicable",
174 Conjunction(#[primary_span] Span),
176 use_pipe_pipe_for_disjunction,
178 applicability = "machine-applicable",
181 Disjunction(#[primary_span] Span),
184 #[derive(Diagnostic)]
185 #[diag(parse_tilde_is_not_unary_operator)]
186 pub(crate) struct TildeAsUnaryOperator(
188 #[suggestion(style = "short", applicability = "machine-applicable", code = "!")]
192 #[derive(Diagnostic)]
193 #[diag(parse_unexpected_token_after_not)]
194 pub(crate) struct NotAsNegationOperator {
197 pub negated_desc: String,
199 pub sub: NotAsNegationOperatorSub,
202 #[derive(Subdiagnostic)]
203 pub enum NotAsNegationOperatorSub {
205 parse_unexpected_token_after_not_default,
207 applicability = "machine-applicable",
210 SuggestNotDefault(#[primary_span] Span),
213 parse_unexpected_token_after_not_bitwise,
215 applicability = "machine-applicable",
218 SuggestNotBitwise(#[primary_span] Span),
221 parse_unexpected_token_after_not_logical,
223 applicability = "machine-applicable",
226 SuggestNotLogical(#[primary_span] Span),
229 #[derive(Diagnostic)]
230 #[diag(parse_malformed_loop_label)]
231 pub(crate) struct MalformedLoopLabel {
233 #[suggestion(applicability = "machine-applicable", code = "{correct_label}")]
235 pub correct_label: Ident,
238 #[derive(Diagnostic)]
239 #[diag(parse_lifetime_in_borrow_expression)]
240 pub(crate) struct LifetimeInBorrowExpression {
243 #[suggestion(applicability = "machine-applicable", code = "")]
245 pub lifetime_span: Span,
248 #[derive(Diagnostic)]
249 #[diag(parse_field_expression_with_generic)]
250 pub(crate) struct FieldExpressionWithGeneric(#[primary_span] pub Span);
252 #[derive(Diagnostic)]
253 #[diag(parse_macro_invocation_with_qualified_path)]
254 pub(crate) struct MacroInvocationWithQualifiedPath(#[primary_span] pub Span);
256 #[derive(Diagnostic)]
257 #[diag(parse_unexpected_token_after_label)]
258 pub(crate) struct UnexpectedTokenAfterLabel {
260 #[label(parse_unexpected_token_after_label)]
262 #[suggestion(suggestion_remove_label, style = "verbose", code = "")]
263 pub remove_label: Option<Span>,
265 pub enclose_in_block: Option<UnexpectedTokenAfterLabelSugg>,
268 #[derive(Subdiagnostic)]
269 #[multipart_suggestion(suggestion_enclose_in_block, applicability = "machine-applicable")]
270 pub(crate) struct UnexpectedTokenAfterLabelSugg {
271 #[suggestion_part(code = "{{ ")]
273 #[suggestion_part(code = " }}")]
277 #[derive(Diagnostic)]
278 #[diag(parse_require_colon_after_labeled_expression)]
280 pub(crate) struct RequireColonAfterLabeledExpression {
285 #[suggestion(style = "short", applicability = "machine-applicable", code = ": ")]
289 #[derive(Diagnostic)]
290 #[diag(parse_do_catch_syntax_removed)]
292 pub(crate) struct DoCatchSyntaxRemoved {
294 #[suggestion(applicability = "machine-applicable", code = "try")]
298 #[derive(Diagnostic)]
299 #[diag(parse_float_literal_requires_integer_part)]
300 pub(crate) struct FloatLiteralRequiresIntegerPart {
302 #[suggestion(applicability = "machine-applicable", code = "{correct}")]
307 #[derive(Diagnostic)]
308 #[diag(parse_missing_semicolon_before_array)]
309 pub(crate) struct MissingSemicolonBeforeArray {
311 pub open_delim: Span,
312 #[suggestion(style = "verbose", applicability = "maybe-incorrect", code = ";")]
316 #[derive(Diagnostic)]
317 #[diag(parse_expect_dotdot_not_dotdotdot)]
318 pub(crate) struct MissingDotDot {
320 pub token_span: Span,
321 #[suggestion(applicability = "maybe-incorrect", code = "..", style = "verbose")]
325 #[derive(Diagnostic)]
326 #[diag(parse_invalid_block_macro_segment)]
327 pub(crate) struct InvalidBlockMacroSegment {
334 #[derive(Diagnostic)]
335 #[diag(parse_if_expression_missing_then_block)]
336 pub(crate) struct IfExpressionMissingThenBlock {
340 pub missing_then_block_sub: IfExpressionMissingThenBlockSub,
342 pub let_else_sub: Option<IfExpressionLetSomeSub>,
345 #[derive(Subdiagnostic)]
346 pub(crate) enum IfExpressionMissingThenBlockSub {
347 #[help(condition_possibly_unfinished)]
348 UnfinishedCondition(#[primary_span] Span),
349 #[help(add_then_block)]
350 AddThenBlock(#[primary_span] Span),
353 #[derive(Subdiagnostic)]
354 #[suggestion(parse_extra_if_in_let_else, applicability = "maybe-incorrect", code = "")]
355 pub(crate) struct IfExpressionLetSomeSub {
360 #[derive(Diagnostic)]
361 #[diag(parse_if_expression_missing_condition)]
362 pub(crate) struct IfExpressionMissingCondition {
364 #[label(condition_label)]
366 #[label(block_label)]
367 pub block_span: Span,
370 #[derive(Diagnostic)]
371 #[diag(parse_expected_expression_found_let)]
372 pub(crate) struct ExpectedExpressionFoundLet {
377 #[derive(Diagnostic)]
378 #[diag(parse_expect_eq_instead_of_eqeq)]
379 pub(crate) struct ExpectedEqForLetExpr {
382 #[suggestion(applicability = "maybe-incorrect", code = "=", style = "verbose")]
386 #[derive(Diagnostic)]
387 #[diag(parse_expected_else_block)]
388 pub(crate) struct ExpectedElseBlock {
390 pub first_tok_span: Span,
391 pub first_tok: String,
394 #[suggestion(applicability = "maybe-incorrect", code = "if ")]
395 pub condition_start: Span,
398 #[derive(Diagnostic)]
399 #[diag(parse_outer_attribute_not_allowed_on_if_else)]
400 pub(crate) struct OuterAttributeNotAllowedOnIfElse {
404 #[label(branch_label)]
405 pub branch_span: Span,
411 #[suggestion(applicability = "machine-applicable", code = "")]
412 pub attributes: Span,
415 #[derive(Diagnostic)]
416 #[diag(parse_missing_in_in_for_loop)]
417 pub(crate) struct MissingInInForLoop {
421 pub sub: MissingInInForLoopSub,
424 #[derive(Subdiagnostic)]
425 pub(crate) enum MissingInInForLoopSub {
426 // Has been misleading, at least in the past (closed Issue #48492), thus maybe-incorrect
427 #[suggestion(use_in_not_of, style = "short", applicability = "maybe-incorrect", code = "in")]
428 InNotOf(#[primary_span] Span),
429 #[suggestion(add_in, style = "short", applicability = "maybe-incorrect", code = " in ")]
430 AddIn(#[primary_span] Span),
433 #[derive(Diagnostic)]
434 #[diag(parse_missing_comma_after_match_arm)]
435 pub(crate) struct MissingCommaAfterMatchArm {
437 #[suggestion(applicability = "machine-applicable", code = ",")]
441 #[derive(Diagnostic)]
442 #[diag(parse_catch_after_try)]
444 pub(crate) struct CatchAfterTry {
449 #[derive(Diagnostic)]
450 #[diag(parse_comma_after_base_struct)]
452 pub(crate) struct CommaAfterBaseStruct {
455 #[suggestion(style = "short", applicability = "machine-applicable", code = "")]
459 #[derive(Diagnostic)]
460 #[diag(parse_eq_field_init)]
461 pub(crate) struct EqFieldInit {
464 #[suggestion(applicability = "machine-applicable", code = ":")]
468 #[derive(Diagnostic)]
469 #[diag(parse_dotdotdot)]
470 pub(crate) struct DotDotDot {
472 #[suggestion(suggest_exclusive_range, applicability = "maybe-incorrect", code = "..")]
473 #[suggestion(suggest_inclusive_range, applicability = "maybe-incorrect", code = "..=")]
477 #[derive(Diagnostic)]
478 #[diag(parse_left_arrow_operator)]
479 pub(crate) struct LeftArrowOperator {
481 #[suggestion(applicability = "maybe-incorrect", code = "< -")]
485 #[derive(Diagnostic)]
486 #[diag(parse_remove_let)]
487 pub(crate) struct RemoveLet {
489 #[suggestion(applicability = "machine-applicable", code = "")]
493 #[derive(Diagnostic)]
494 #[diag(parse_use_eq_instead)]
495 pub(crate) struct UseEqInstead {
497 #[suggestion(style = "short", applicability = "machine-applicable", code = "=")]
501 #[derive(Diagnostic)]
502 #[diag(parse_use_empty_block_not_semi)]
503 pub(crate) struct UseEmptyBlockNotSemi {
505 #[suggestion(style = "hidden", applicability = "machine-applicable", code = "{{}}")]
509 #[derive(Diagnostic)]
510 #[diag(parse_comparison_interpreted_as_generic)]
511 pub(crate) struct ComparisonInterpretedAsGeneric {
513 #[label(label_comparison)]
514 pub comparison: Span,
519 pub suggestion: ComparisonOrShiftInterpretedAsGenericSugg,
522 #[derive(Diagnostic)]
523 #[diag(parse_shift_interpreted_as_generic)]
524 pub(crate) struct ShiftInterpretedAsGeneric {
526 #[label(label_comparison)]
532 pub suggestion: ComparisonOrShiftInterpretedAsGenericSugg,
535 #[derive(Subdiagnostic)]
536 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
537 pub(crate) struct ComparisonOrShiftInterpretedAsGenericSugg {
538 #[suggestion_part(code = "(")]
540 #[suggestion_part(code = ")")]
544 #[derive(Diagnostic)]
545 #[diag(parse_found_expr_would_be_stmt)]
546 pub(crate) struct FoundExprWouldBeStmt {
552 pub suggestion: ExprParenthesesNeeded,
555 #[derive(Diagnostic)]
556 #[diag(parse_leading_plus_not_supported)]
557 pub(crate) struct LeadingPlusNotSupported {
562 suggestion_remove_plus,
565 applicability = "machine-applicable"
567 pub remove_plus: Option<Span>,
569 pub add_parentheses: Option<ExprParenthesesNeeded>,
572 #[derive(Diagnostic)]
573 #[diag(parse_parentheses_with_struct_fields)]
574 pub(crate) struct ParenthesesWithStructFields {
579 pub braces_for_struct: BracesForStructLiteral,
581 pub no_fields_for_fn: NoFieldsForFnCall,
584 #[derive(Subdiagnostic)]
585 #[multipart_suggestion(suggestion_braces_for_struct, applicability = "maybe-incorrect")]
586 pub(crate) struct BracesForStructLiteral {
587 #[suggestion_part(code = " {{ ")]
589 #[suggestion_part(code = " }}")]
593 #[derive(Subdiagnostic)]
594 #[multipart_suggestion(suggestion_no_fields_for_fn, applicability = "maybe-incorrect")]
595 pub(crate) struct NoFieldsForFnCall {
596 #[suggestion_part(code = "")]
597 pub fields: Vec<Span>,
600 #[derive(Diagnostic)]
601 #[diag(parse_labeled_loop_in_break)]
602 pub(crate) struct LabeledLoopInBreak {
606 pub sub: WrapExpressionInParentheses,
609 #[derive(Subdiagnostic)]
610 #[multipart_suggestion(
611 parse_sugg_wrap_expression_in_parentheses,
612 applicability = "machine-applicable"
614 pub(crate) struct WrapExpressionInParentheses {
615 #[suggestion_part(code = "(")]
617 #[suggestion_part(code = ")")]
621 #[derive(Diagnostic)]
622 #[diag(parse_array_brackets_instead_of_braces)]
623 pub(crate) struct ArrayBracketsInsteadOfSpaces {
627 pub sub: ArrayBracketsInsteadOfSpacesSugg,
630 #[derive(Subdiagnostic)]
631 #[multipart_suggestion(suggestion, applicability = "maybe-incorrect")]
632 pub(crate) struct ArrayBracketsInsteadOfSpacesSugg {
633 #[suggestion_part(code = "[")]
635 #[suggestion_part(code = "]")]
639 #[derive(Diagnostic)]
640 #[diag(parse_match_arm_body_without_braces)]
641 pub(crate) struct MatchArmBodyWithoutBraces {
643 #[label(label_statements)]
644 pub statements: Span,
645 #[label(label_arrow)]
647 pub num_statements: usize,
649 pub sub: MatchArmBodyWithoutBracesSugg,
652 #[derive(Diagnostic)]
653 #[diag(parse_inclusive_range_extra_equals)]
655 pub(crate) struct InclusiveRangeExtraEquals {
658 suggestion_remove_eq,
661 applicability = "maybe-incorrect"
666 #[derive(Diagnostic)]
667 #[diag(parse_inclusive_range_match_arrow)]
668 pub(crate) struct InclusiveRangeMatchArrow {
672 suggestion_add_space,
675 applicability = "machine-applicable"
680 #[derive(Diagnostic)]
681 #[diag(parse_inclusive_range_no_end, code = "E0586")]
683 pub(crate) struct InclusiveRangeNoEnd {
686 suggestion_open_range,
688 applicability = "machine-applicable",
694 #[derive(Subdiagnostic)]
695 pub(crate) enum MatchArmBodyWithoutBracesSugg {
696 #[multipart_suggestion(suggestion_add_braces, applicability = "machine-applicable")]
698 #[suggestion_part(code = "{{ ")]
700 #[suggestion_part(code = " }}")]
704 suggestion_use_comma_not_semicolon,
706 applicability = "machine-applicable"
714 #[derive(Diagnostic)]
715 #[diag(parse_struct_literal_not_allowed_here)]
716 pub(crate) struct StructLiteralNotAllowedHere {
720 pub sub: StructLiteralNotAllowedHereSugg,
723 #[derive(Subdiagnostic)]
724 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
725 pub(crate) struct StructLiteralNotAllowedHereSugg {
726 #[suggestion_part(code = "(")]
728 #[suggestion_part(code = ")")]
732 #[derive(Diagnostic)]
733 #[diag(parse_invalid_interpolated_expression)]
734 pub(crate) struct InvalidInterpolatedExpression {
739 #[derive(Diagnostic)]
740 #[diag(parse_invalid_literal_suffix_on_tuple_index)]
741 pub(crate) struct InvalidLiteralSuffixOnTupleIndex {
746 #[help(tuple_exception_line_1)]
747 #[help(tuple_exception_line_2)]
748 #[help(tuple_exception_line_3)]
749 pub exception: Option<()>,
752 #[derive(Diagnostic)]
753 #[diag(parse_non_string_abi_literal)]
754 pub(crate) struct NonStringAbiLiteral {
756 #[suggestion(code = "\"C\"", applicability = "maybe-incorrect")]
760 #[derive(Diagnostic)]
761 #[diag(parse_mismatched_closing_delimiter)]
762 pub(crate) struct MismatchedClosingDelimiter {
764 pub spans: Vec<Span>,
765 pub delimiter: String,
766 #[label(label_unmatched)]
768 #[label(label_opening_candidate)]
769 pub opening_candidate: Option<Span>,
770 #[label(label_unclosed)]
771 pub unclosed: Option<Span>,
774 #[derive(Diagnostic)]
775 #[diag(parse_incorrect_visibility_restriction, code = "E0704")]
777 pub(crate) struct IncorrectVisibilityRestriction {
779 #[suggestion(code = "in {inner_str}", applicability = "machine-applicable")]
781 pub inner_str: String,
784 #[derive(Diagnostic)]
785 #[diag(parse_assignment_else_not_allowed)]
786 pub(crate) struct AssignmentElseNotAllowed {
791 #[derive(Diagnostic)]
792 #[diag(parse_expected_statement_after_outer_attr)]
793 pub(crate) struct ExpectedStatementAfterOuterAttr {
798 #[derive(Diagnostic)]
799 #[diag(parse_doc_comment_does_not_document_anything, code = "E0585")]
801 pub(crate) struct DocCommentDoesNotDocumentAnything {
804 #[suggestion(code = ",", applicability = "machine-applicable")]
805 pub missing_comma: Option<Span>,
808 #[derive(Diagnostic)]
809 #[diag(parse_const_let_mutually_exclusive)]
810 pub(crate) struct ConstLetMutuallyExclusive {
812 #[suggestion(code = "const", applicability = "maybe-incorrect")]
816 #[derive(Diagnostic)]
817 #[diag(parse_invalid_expression_in_let_else)]
818 pub(crate) struct InvalidExpressionInLetElse {
821 pub operator: &'static str,
823 pub sugg: WrapExpressionInParentheses,
826 #[derive(Diagnostic)]
827 #[diag(parse_invalid_curly_in_let_else)]
828 pub(crate) struct InvalidCurlyInLetElse {
832 pub sugg: WrapExpressionInParentheses,
835 #[derive(Diagnostic)]
836 #[diag(parse_compound_assignment_expression_in_let)]
838 pub(crate) struct CompoundAssignmentExpressionInLet {
840 #[suggestion(style = "short", code = "=", applicability = "maybe-incorrect")]
844 #[derive(Diagnostic)]
845 #[diag(parse_suffixed_literal_in_attribute)]
847 pub(crate) struct SuffixedLiteralInAttribute {
852 #[derive(Diagnostic)]
853 #[diag(parse_invalid_meta_item)]
854 pub(crate) struct InvalidMetaItem {
860 #[derive(Subdiagnostic)]
862 parse_sugg_escape_to_use_as_identifier,
864 applicability = "maybe-incorrect",
867 pub(crate) struct SuggEscapeToUseAsIdentifier {
870 pub ident_name: String,
873 #[derive(Subdiagnostic)]
874 #[suggestion(parse_sugg_remove_comma, applicability = "machine-applicable", code = "")]
875 pub(crate) struct SuggRemoveComma {
880 #[derive(Subdiagnostic)]
881 pub(crate) enum ExpectedIdentifierFound {
882 #[label(parse_expected_identifier_found_reserved_identifier)]
883 ReservedIdentifier(#[primary_span] Span),
884 #[label(parse_expected_identifier_found_keyword)]
885 Keyword(#[primary_span] Span),
886 #[label(parse_expected_identifier_found_reserved_keyword)]
887 ReservedKeyword(#[primary_span] Span),
888 #[label(parse_expected_identifier_found_doc_comment)]
889 DocComment(#[primary_span] Span),
890 #[label(parse_expected_identifier)]
891 Other(#[primary_span] Span),
894 impl ExpectedIdentifierFound {
895 pub fn new(token_descr: Option<TokenDescription>, span: Span) -> Self {
897 Some(TokenDescription::ReservedIdentifier) => {
898 ExpectedIdentifierFound::ReservedIdentifier
900 Some(TokenDescription::Keyword) => ExpectedIdentifierFound::Keyword,
901 Some(TokenDescription::ReservedKeyword) => ExpectedIdentifierFound::ReservedKeyword,
902 Some(TokenDescription::DocComment) => ExpectedIdentifierFound::DocComment,
903 None => ExpectedIdentifierFound::Other,
908 pub(crate) struct ExpectedIdentifier {
911 pub suggest_raw: Option<SuggEscapeToUseAsIdentifier>,
912 pub suggest_remove_comma: Option<SuggRemoveComma>,
915 impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedIdentifier {
919 handler: &'a rustc_errors::Handler,
920 ) -> rustc_errors::DiagnosticBuilder<'a, G> {
921 let token_descr = super::parser::TokenDescription::from_token(&self.token);
923 let mut diag = handler.struct_diagnostic(match token_descr {
924 Some(TokenDescription::ReservedIdentifier) => {
925 fluent::parse_expected_identifier_found_reserved_identifier_str
927 Some(TokenDescription::Keyword) => fluent::parse_expected_identifier_found_keyword_str,
928 Some(TokenDescription::ReservedKeyword) => {
929 fluent::parse_expected_identifier_found_reserved_keyword_str
931 Some(TokenDescription::DocComment) => {
932 fluent::parse_expected_identifier_found_doc_comment_str
934 None => fluent::parse_expected_identifier_found_str,
936 diag.set_span(self.span);
937 diag.set_arg("token", self.token);
939 if let Some(sugg) = self.suggest_raw {
940 sugg.add_to_diagnostic(&mut diag);
943 ExpectedIdentifierFound::new(token_descr, self.span).add_to_diagnostic(&mut diag);
945 if let Some(sugg) = self.suggest_remove_comma {
946 sugg.add_to_diagnostic(&mut diag);
953 pub(crate) struct ExpectedSemi {
957 pub unexpected_token_label: Option<Span>,
958 pub sugg: ExpectedSemiSugg,
961 impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedSemi {
965 handler: &'a rustc_errors::Handler,
966 ) -> rustc_errors::DiagnosticBuilder<'a, G> {
967 let token_descr = super::parser::TokenDescription::from_token(&self.token);
969 let mut diag = handler.struct_diagnostic(match token_descr {
970 Some(TokenDescription::ReservedIdentifier) => {
971 fluent::parse_expected_semi_found_reserved_identifier_str
973 Some(TokenDescription::Keyword) => fluent::parse_expected_semi_found_keyword_str,
974 Some(TokenDescription::ReservedKeyword) => {
975 fluent::parse_expected_semi_found_reserved_keyword_str
977 Some(TokenDescription::DocComment) => fluent::parse_expected_semi_found_doc_comment_str,
978 None => fluent::parse_expected_semi_found_str,
980 diag.set_span(self.span);
981 diag.set_arg("token", self.token);
983 if let Some(unexpected_token_label) = self.unexpected_token_label {
984 diag.span_label(unexpected_token_label, fluent::parse_label_unexpected_token);
987 self.sugg.add_to_diagnostic(&mut diag);
993 #[derive(Subdiagnostic)]
994 pub(crate) enum ExpectedSemiSugg {
995 #[suggestion(parse_sugg_change_this_to_semi, code = ";", applicability = "machine-applicable")]
996 ChangeToSemi(#[primary_span] Span),
1001 applicability = "machine-applicable"
1003 AddSemi(#[primary_span] Span),
1006 #[derive(Diagnostic)]
1007 #[diag(parse_struct_literal_body_without_path)]
1008 pub(crate) struct StructLiteralBodyWithoutPath {
1012 pub sugg: StructLiteralBodyWithoutPathSugg,
1015 #[derive(Subdiagnostic)]
1016 #[multipart_suggestion(suggestion, applicability = "has-placeholders")]
1017 pub(crate) struct StructLiteralBodyWithoutPathSugg {
1018 #[suggestion_part(code = "{{ SomeStruct ")]
1020 #[suggestion_part(code = " }}")]
1024 #[derive(Diagnostic)]
1025 #[diag(parse_struct_literal_needing_parens)]
1026 pub(crate) struct StructLiteralNeedingParens {
1030 pub sugg: StructLiteralNeedingParensSugg,
1033 #[derive(Subdiagnostic)]
1034 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1035 pub(crate) struct StructLiteralNeedingParensSugg {
1036 #[suggestion_part(code = "(")]
1038 #[suggestion_part(code = ")")]
1042 #[derive(Diagnostic)]
1043 #[diag(parse_unmatched_angle_brackets)]
1044 pub(crate) struct UnmatchedAngleBrackets {
1046 #[suggestion(code = "", applicability = "machine-applicable")]
1048 pub num_extra_brackets: usize,
1051 #[derive(Diagnostic)]
1052 #[diag(parse_generic_parameters_without_angle_brackets)]
1053 pub(crate) struct GenericParamsWithoutAngleBrackets {
1057 pub sugg: GenericParamsWithoutAngleBracketsSugg,
1060 #[derive(Subdiagnostic)]
1061 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1062 pub(crate) struct GenericParamsWithoutAngleBracketsSugg {
1063 #[suggestion_part(code = "<")]
1065 #[suggestion_part(code = ">")]
1069 #[derive(Diagnostic)]
1070 #[diag(parse_comparison_operators_cannot_be_chained)]
1071 pub(crate) struct ComparisonOperatorsCannotBeChained {
1073 pub span: Vec<Span>,
1075 parse_sugg_turbofish_syntax,
1078 applicability = "maybe-incorrect"
1080 pub suggest_turbofish: Option<Span>,
1081 #[help(parse_sugg_turbofish_syntax)]
1082 #[help(sugg_parentheses_for_function_args)]
1083 pub help_turbofish: Option<()>,
1085 pub chaining_sugg: Option<ComparisonOperatorsCannotBeChainedSugg>,
1088 #[derive(Subdiagnostic)]
1089 pub(crate) enum ComparisonOperatorsCannotBeChainedSugg {
1091 sugg_split_comparison,
1093 code = " && {middle_term}",
1094 applicability = "maybe-incorrect"
1099 middle_term: String,
1101 #[multipart_suggestion(sugg_parenthesize, applicability = "maybe-incorrect")]
1103 #[suggestion_part(code = "(")]
1105 #[suggestion_part(code = ")")]
1110 #[derive(Diagnostic)]
1111 #[diag(parse_question_mark_in_type)]
1112 pub(crate) struct QuestionMarkInType {
1117 pub sugg: QuestionMarkInTypeSugg,
1120 #[derive(Subdiagnostic)]
1121 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1122 pub(crate) struct QuestionMarkInTypeSugg {
1123 #[suggestion_part(code = "Option<")]
1125 #[suggestion_part(code = ">")]
1129 #[derive(Diagnostic)]
1130 #[diag(parse_unexpected_parentheses_in_for_head)]
1131 pub(crate) struct ParenthesesInForHead {
1133 pub span: Vec<Span>,
1135 pub sugg: ParenthesesInForHeadSugg,
1138 #[derive(Subdiagnostic)]
1139 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1140 pub(crate) struct ParenthesesInForHeadSugg {
1141 #[suggestion_part(code = "{left_snippet}")]
1143 pub left_snippet: String,
1144 #[suggestion_part(code = "{right_snippet}")]
1146 pub right_snippet: String,
1149 #[derive(Diagnostic)]
1150 #[diag(parse_doc_comment_on_param_type)]
1151 pub(crate) struct DocCommentOnParamType {
1157 #[derive(Diagnostic)]
1158 #[diag(parse_attribute_on_param_type)]
1159 pub(crate) struct AttributeOnParamType {
1165 #[derive(Diagnostic)]
1166 #[diag(parse_pattern_method_param_without_body, code = "E0642")]
1167 pub(crate) struct PatternMethodParamWithoutBody {
1169 #[suggestion(code = "_", applicability = "machine-applicable")]
1173 #[derive(Diagnostic)]
1174 #[diag(parse_self_param_not_first)]
1175 pub(crate) struct SelfParamNotFirst {
1181 #[derive(Diagnostic)]
1182 #[diag(parse_invalid_identifier_with_leading_number)]
1183 pub(crate) struct InvalidIdentiferStartsWithNumber {
1189 #[derive(Diagnostic)]
1190 #[diag(parse_const_generic_without_braces)]
1191 pub(crate) struct ConstGenericWithoutBraces {
1195 pub sugg: ConstGenericWithoutBracesSugg,
1198 #[derive(Subdiagnostic)]
1199 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1200 pub(crate) struct ConstGenericWithoutBracesSugg {
1201 #[suggestion_part(code = "{{ ")]
1203 #[suggestion_part(code = " }}")]
1207 #[derive(Diagnostic)]
1208 #[diag(parse_unexpected_const_param_declaration)]
1209 pub(crate) struct UnexpectedConstParamDeclaration {
1214 pub sugg: Option<UnexpectedConstParamDeclarationSugg>,
1217 #[derive(Subdiagnostic)]
1218 pub(crate) enum UnexpectedConstParamDeclarationSugg {
1219 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1221 #[suggestion_part(code = "<{snippet}>")]
1222 impl_generics: Span,
1223 #[suggestion_part(code = "{ident}")]
1224 incorrect_decl: Span,
1228 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1230 #[suggestion_part(code = ", {snippet}")]
1231 impl_generics_end: Span,
1232 #[suggestion_part(code = "{ident}")]
1233 incorrect_decl: Span,
1239 #[derive(Diagnostic)]
1240 #[diag(parse_unexpected_const_in_generic_param)]
1241 pub(crate) struct UnexpectedConstInGenericParam {
1244 #[suggestion(style = "verbose", code = "", applicability = "maybe-incorrect")]
1245 pub to_remove: Option<Span>,
1248 #[derive(Diagnostic)]
1249 #[diag(parse_async_move_order_incorrect)]
1250 pub(crate) struct AsyncMoveOrderIncorrect {
1252 #[suggestion(style = "verbose", code = "async move", applicability = "maybe-incorrect")]
1256 #[derive(Diagnostic)]
1257 #[diag(parse_double_colon_in_bound)]
1258 pub(crate) struct DoubleColonInBound {
1261 #[suggestion(code = ": ", applicability = "machine-applicable")]
1265 #[derive(Diagnostic)]
1266 #[diag(parse_fn_ptr_with_generics)]
1267 pub(crate) struct FnPtrWithGenerics {
1271 pub sugg: Option<FnPtrWithGenericsSugg>,
1274 #[derive(Subdiagnostic)]
1275 #[multipart_suggestion(suggestion, applicability = "maybe-incorrect")]
1276 pub(crate) struct FnPtrWithGenericsSugg {
1277 #[suggestion_part(code = "{snippet}")]
1279 pub snippet: String,
1280 #[suggestion_part(code = "")]
1283 pub for_param_list_exists: bool,
1286 #[derive(Diagnostic)]
1287 #[diag(parse_unexpected_if_with_if)]
1288 pub(crate) struct UnexpectedIfWithIf(
1290 #[suggestion(applicability = "machine-applicable", code = " ", style = "verbose")]
1294 #[derive(Diagnostic)]
1295 #[diag(parse_maybe_fn_typo_with_impl)]
1296 pub(crate) struct FnTypoWithImpl {
1298 #[suggestion(applicability = "maybe-incorrect", code = "impl", style = "verbose")]
1302 #[derive(Diagnostic)]
1303 #[diag(parse_expected_fn_path_found_fn_keyword)]
1304 pub(crate) struct ExpectedFnPathFoundFnKeyword {
1306 #[suggestion(applicability = "machine-applicable", code = "Fn", style = "verbose")]
1307 pub fn_token_span: Span,
1310 #[derive(Diagnostic)]
1311 #[diag(parse_where_clause_before_tuple_struct_body)]
1312 pub(crate) struct WhereClauseBeforeTupleStructBody {
1316 #[label(name_label)]
1318 #[label(body_label)]
1321 pub sugg: Option<WhereClauseBeforeTupleStructBodySugg>,
1324 #[derive(Subdiagnostic)]
1325 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1326 pub(crate) struct WhereClauseBeforeTupleStructBodySugg {
1327 #[suggestion_part(code = "{snippet}")]
1329 pub snippet: String,
1330 #[suggestion_part(code = "")]