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 #[help(parse_extra_if_in_let_else)]
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(Subdiagnostic)]
653 pub(crate) enum MatchArmBodyWithoutBracesSugg {
654 #[multipart_suggestion(suggestion_add_braces, applicability = "machine-applicable")]
656 #[suggestion_part(code = "{{ ")]
658 #[suggestion_part(code = " }}")]
662 suggestion_use_comma_not_semicolon,
664 applicability = "machine-applicable"
672 #[derive(Diagnostic)]
673 #[diag(parse_struct_literal_not_allowed_here)]
674 pub(crate) struct StructLiteralNotAllowedHere {
678 pub sub: StructLiteralNotAllowedHereSugg,
681 #[derive(Subdiagnostic)]
682 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
683 pub(crate) struct StructLiteralNotAllowedHereSugg {
684 #[suggestion_part(code = "(")]
686 #[suggestion_part(code = ")")]
690 #[derive(Diagnostic)]
691 #[diag(parse_invalid_interpolated_expression)]
692 pub(crate) struct InvalidInterpolatedExpression {
697 #[derive(Diagnostic)]
698 #[diag(parse_invalid_literal_suffix_on_tuple_index)]
699 pub(crate) struct InvalidLiteralSuffixOnTupleIndex {
704 #[help(tuple_exception_line_1)]
705 #[help(tuple_exception_line_2)]
706 #[help(tuple_exception_line_3)]
707 pub exception: Option<()>,
710 #[derive(Diagnostic)]
711 #[diag(parse_non_string_abi_literal)]
712 pub(crate) struct NonStringAbiLiteral {
714 #[suggestion(code = "\"C\"", applicability = "maybe-incorrect")]
718 #[derive(Diagnostic)]
719 #[diag(parse_mismatched_closing_delimiter)]
720 pub(crate) struct MismatchedClosingDelimiter {
722 pub spans: Vec<Span>,
723 pub delimiter: String,
724 #[label(label_unmatched)]
726 #[label(label_opening_candidate)]
727 pub opening_candidate: Option<Span>,
728 #[label(label_unclosed)]
729 pub unclosed: Option<Span>,
732 #[derive(Diagnostic)]
733 #[diag(parse_incorrect_visibility_restriction, code = "E0704")]
735 pub(crate) struct IncorrectVisibilityRestriction {
737 #[suggestion(code = "in {inner_str}", applicability = "machine-applicable")]
739 pub inner_str: String,
742 #[derive(Diagnostic)]
743 #[diag(parse_assignment_else_not_allowed)]
744 pub(crate) struct AssignmentElseNotAllowed {
749 #[derive(Diagnostic)]
750 #[diag(parse_expected_statement_after_outer_attr)]
751 pub(crate) struct ExpectedStatementAfterOuterAttr {
756 #[derive(Diagnostic)]
757 #[diag(parse_doc_comment_does_not_document_anything, code = "E0585")]
759 pub(crate) struct DocCommentDoesNotDocumentAnything {
762 #[suggestion(code = ",", applicability = "machine-applicable")]
763 pub missing_comma: Option<Span>,
766 #[derive(Diagnostic)]
767 #[diag(parse_const_let_mutually_exclusive)]
768 pub(crate) struct ConstLetMutuallyExclusive {
770 #[suggestion(code = "const", applicability = "maybe-incorrect")]
774 #[derive(Diagnostic)]
775 #[diag(parse_invalid_expression_in_let_else)]
776 pub(crate) struct InvalidExpressionInLetElse {
779 pub operator: &'static str,
781 pub sugg: WrapExpressionInParentheses,
784 #[derive(Diagnostic)]
785 #[diag(parse_invalid_curly_in_let_else)]
786 pub(crate) struct InvalidCurlyInLetElse {
790 pub sugg: WrapExpressionInParentheses,
793 #[derive(Diagnostic)]
794 #[diag(parse_compound_assignment_expression_in_let)]
796 pub(crate) struct CompoundAssignmentExpressionInLet {
798 #[suggestion(style = "short", code = "=", applicability = "maybe-incorrect")]
802 #[derive(Diagnostic)]
803 #[diag(parse_suffixed_literal_in_attribute)]
805 pub(crate) struct SuffixedLiteralInAttribute {
810 #[derive(Diagnostic)]
811 #[diag(parse_invalid_meta_item)]
812 pub(crate) struct InvalidMetaItem {
818 #[derive(Subdiagnostic)]
820 parse_sugg_escape_to_use_as_identifier,
822 applicability = "maybe-incorrect",
825 pub(crate) struct SuggEscapeToUseAsIdentifier {
828 pub ident_name: String,
831 #[derive(Subdiagnostic)]
832 #[suggestion(parse_sugg_remove_comma, applicability = "machine-applicable", code = "")]
833 pub(crate) struct SuggRemoveComma {
838 #[derive(Subdiagnostic)]
839 pub(crate) enum ExpectedIdentifierFound {
840 #[label(parse_expected_identifier_found_reserved_identifier)]
841 ReservedIdentifier(#[primary_span] Span),
842 #[label(parse_expected_identifier_found_keyword)]
843 Keyword(#[primary_span] Span),
844 #[label(parse_expected_identifier_found_reserved_keyword)]
845 ReservedKeyword(#[primary_span] Span),
846 #[label(parse_expected_identifier_found_doc_comment)]
847 DocComment(#[primary_span] Span),
848 #[label(parse_expected_identifier)]
849 Other(#[primary_span] Span),
852 impl ExpectedIdentifierFound {
853 pub fn new(token_descr: Option<TokenDescription>, span: Span) -> Self {
855 Some(TokenDescription::ReservedIdentifier) => {
856 ExpectedIdentifierFound::ReservedIdentifier
858 Some(TokenDescription::Keyword) => ExpectedIdentifierFound::Keyword,
859 Some(TokenDescription::ReservedKeyword) => ExpectedIdentifierFound::ReservedKeyword,
860 Some(TokenDescription::DocComment) => ExpectedIdentifierFound::DocComment,
861 None => ExpectedIdentifierFound::Other,
866 pub(crate) struct ExpectedIdentifier {
869 pub suggest_raw: Option<SuggEscapeToUseAsIdentifier>,
870 pub suggest_remove_comma: Option<SuggRemoveComma>,
873 impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedIdentifier {
877 handler: &'a rustc_errors::Handler,
878 ) -> rustc_errors::DiagnosticBuilder<'a, G> {
879 let token_descr = super::parser::TokenDescription::from_token(&self.token);
881 let mut diag = handler.struct_diagnostic(match token_descr {
882 Some(TokenDescription::ReservedIdentifier) => {
883 fluent::parse_expected_identifier_found_reserved_identifier_str
885 Some(TokenDescription::Keyword) => fluent::parse_expected_identifier_found_keyword_str,
886 Some(TokenDescription::ReservedKeyword) => {
887 fluent::parse_expected_identifier_found_reserved_keyword_str
889 Some(TokenDescription::DocComment) => {
890 fluent::parse_expected_identifier_found_doc_comment_str
892 None => fluent::parse_expected_identifier_found_str,
894 diag.set_span(self.span);
895 diag.set_arg("token", self.token);
897 if let Some(sugg) = self.suggest_raw {
898 sugg.add_to_diagnostic(&mut diag);
901 ExpectedIdentifierFound::new(token_descr, self.span).add_to_diagnostic(&mut diag);
903 if let Some(sugg) = self.suggest_remove_comma {
904 sugg.add_to_diagnostic(&mut diag);
911 pub(crate) struct ExpectedSemi {
915 pub unexpected_token_label: Option<Span>,
916 pub sugg: ExpectedSemiSugg,
919 impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedSemi {
923 handler: &'a rustc_errors::Handler,
924 ) -> rustc_errors::DiagnosticBuilder<'a, G> {
925 let token_descr = super::parser::TokenDescription::from_token(&self.token);
927 let mut diag = handler.struct_diagnostic(match token_descr {
928 Some(TokenDescription::ReservedIdentifier) => {
929 fluent::parse_expected_semi_found_reserved_identifier_str
931 Some(TokenDescription::Keyword) => fluent::parse_expected_semi_found_keyword_str,
932 Some(TokenDescription::ReservedKeyword) => {
933 fluent::parse_expected_semi_found_reserved_keyword_str
935 Some(TokenDescription::DocComment) => fluent::parse_expected_semi_found_doc_comment_str,
936 None => fluent::parse_expected_semi_found_str,
938 diag.set_span(self.span);
939 diag.set_arg("token", self.token);
941 if let Some(unexpected_token_label) = self.unexpected_token_label {
942 diag.span_label(unexpected_token_label, fluent::parse_label_unexpected_token);
945 self.sugg.add_to_diagnostic(&mut diag);
951 #[derive(Subdiagnostic)]
952 pub(crate) enum ExpectedSemiSugg {
953 #[suggestion(parse_sugg_change_this_to_semi, code = ";", applicability = "machine-applicable")]
954 ChangeToSemi(#[primary_span] Span),
959 applicability = "machine-applicable"
961 AddSemi(#[primary_span] Span),
964 #[derive(Diagnostic)]
965 #[diag(parse_struct_literal_body_without_path)]
966 pub(crate) struct StructLiteralBodyWithoutPath {
970 pub sugg: StructLiteralBodyWithoutPathSugg,
973 #[derive(Subdiagnostic)]
974 #[multipart_suggestion(suggestion, applicability = "has-placeholders")]
975 pub(crate) struct StructLiteralBodyWithoutPathSugg {
976 #[suggestion_part(code = "{{ SomeStruct ")]
978 #[suggestion_part(code = " }}")]
982 #[derive(Diagnostic)]
983 #[diag(parse_struct_literal_needing_parens)]
984 pub(crate) struct StructLiteralNeedingParens {
988 pub sugg: StructLiteralNeedingParensSugg,
991 #[derive(Subdiagnostic)]
992 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
993 pub(crate) struct StructLiteralNeedingParensSugg {
994 #[suggestion_part(code = "(")]
996 #[suggestion_part(code = ")")]
1000 #[derive(Diagnostic)]
1001 #[diag(parse_unmatched_angle_brackets)]
1002 pub(crate) struct UnmatchedAngleBrackets {
1004 #[suggestion(code = "", applicability = "machine-applicable")]
1006 pub num_extra_brackets: usize,
1009 #[derive(Diagnostic)]
1010 #[diag(parse_generic_parameters_without_angle_brackets)]
1011 pub(crate) struct GenericParamsWithoutAngleBrackets {
1015 pub sugg: GenericParamsWithoutAngleBracketsSugg,
1018 #[derive(Subdiagnostic)]
1019 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1020 pub(crate) struct GenericParamsWithoutAngleBracketsSugg {
1021 #[suggestion_part(code = "<")]
1023 #[suggestion_part(code = ">")]
1027 #[derive(Diagnostic)]
1028 #[diag(parse_comparison_operators_cannot_be_chained)]
1029 pub(crate) struct ComparisonOperatorsCannotBeChained {
1031 pub span: Vec<Span>,
1033 parse_sugg_turbofish_syntax,
1036 applicability = "maybe-incorrect"
1038 pub suggest_turbofish: Option<Span>,
1039 #[help(parse_sugg_turbofish_syntax)]
1040 #[help(sugg_parentheses_for_function_args)]
1041 pub help_turbofish: Option<()>,
1043 pub chaining_sugg: Option<ComparisonOperatorsCannotBeChainedSugg>,
1046 #[derive(Subdiagnostic)]
1047 pub(crate) enum ComparisonOperatorsCannotBeChainedSugg {
1049 sugg_split_comparison,
1051 code = " && {middle_term}",
1052 applicability = "maybe-incorrect"
1057 middle_term: String,
1059 #[multipart_suggestion(sugg_parenthesize, applicability = "maybe-incorrect")]
1061 #[suggestion_part(code = "(")]
1063 #[suggestion_part(code = ")")]
1068 #[derive(Diagnostic)]
1069 #[diag(parse_question_mark_in_type)]
1070 pub(crate) struct QuestionMarkInType {
1075 pub sugg: QuestionMarkInTypeSugg,
1078 #[derive(Subdiagnostic)]
1079 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1080 pub(crate) struct QuestionMarkInTypeSugg {
1081 #[suggestion_part(code = "Option<")]
1083 #[suggestion_part(code = ">")]
1087 #[derive(Diagnostic)]
1088 #[diag(parse_unexpected_parentheses_in_for_head)]
1089 pub(crate) struct ParenthesesInForHead {
1091 pub span: Vec<Span>,
1093 pub sugg: ParenthesesInForHeadSugg,
1096 #[derive(Subdiagnostic)]
1097 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1098 pub(crate) struct ParenthesesInForHeadSugg {
1099 #[suggestion_part(code = "{left_snippet}")]
1101 pub left_snippet: String,
1102 #[suggestion_part(code = "{right_snippet}")]
1104 pub right_snippet: String,
1107 #[derive(Diagnostic)]
1108 #[diag(parse_doc_comment_on_param_type)]
1109 pub(crate) struct DocCommentOnParamType {
1115 #[derive(Diagnostic)]
1116 #[diag(parse_attribute_on_param_type)]
1117 pub(crate) struct AttributeOnParamType {
1123 #[derive(Diagnostic)]
1124 #[diag(parse_pattern_method_param_without_body, code = "E0642")]
1125 pub(crate) struct PatternMethodParamWithoutBody {
1127 #[suggestion(code = "_", applicability = "machine-applicable")]
1131 #[derive(Diagnostic)]
1132 #[diag(parse_self_param_not_first)]
1133 pub(crate) struct SelfParamNotFirst {
1139 #[derive(Diagnostic)]
1140 #[diag(parse_invalid_identifier_with_leading_number)]
1141 pub(crate) struct InvalidIdentiferStartsWithNumber {
1147 #[derive(Diagnostic)]
1148 #[diag(parse_const_generic_without_braces)]
1149 pub(crate) struct ConstGenericWithoutBraces {
1153 pub sugg: ConstGenericWithoutBracesSugg,
1156 #[derive(Subdiagnostic)]
1157 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1158 pub(crate) struct ConstGenericWithoutBracesSugg {
1159 #[suggestion_part(code = "{{ ")]
1161 #[suggestion_part(code = " }}")]
1165 #[derive(Diagnostic)]
1166 #[diag(parse_unexpected_const_param_declaration)]
1167 pub(crate) struct UnexpectedConstParamDeclaration {
1172 pub sugg: Option<UnexpectedConstParamDeclarationSugg>,
1175 #[derive(Subdiagnostic)]
1176 pub(crate) enum UnexpectedConstParamDeclarationSugg {
1177 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1179 #[suggestion_part(code = "<{snippet}>")]
1180 impl_generics: Span,
1181 #[suggestion_part(code = "{ident}")]
1182 incorrect_decl: Span,
1186 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1188 #[suggestion_part(code = ", {snippet}")]
1189 impl_generics_end: Span,
1190 #[suggestion_part(code = "{ident}")]
1191 incorrect_decl: Span,
1197 #[derive(Diagnostic)]
1198 #[diag(parse_unexpected_const_in_generic_param)]
1199 pub(crate) struct UnexpectedConstInGenericParam {
1202 #[suggestion(style = "verbose", code = "", applicability = "maybe-incorrect")]
1203 pub to_remove: Option<Span>,
1206 #[derive(Diagnostic)]
1207 #[diag(parse_async_move_order_incorrect)]
1208 pub(crate) struct AsyncMoveOrderIncorrect {
1210 #[suggestion(style = "verbose", code = "async move", applicability = "maybe-incorrect")]
1214 #[derive(Diagnostic)]
1215 #[diag(parse_double_colon_in_bound)]
1216 pub(crate) struct DoubleColonInBound {
1219 #[suggestion(code = ": ", applicability = "machine-applicable")]
1223 #[derive(Diagnostic)]
1224 #[diag(parse_fn_ptr_with_generics)]
1225 pub(crate) struct FnPtrWithGenerics {
1229 pub sugg: Option<FnPtrWithGenericsSugg>,
1232 #[derive(Subdiagnostic)]
1233 #[multipart_suggestion(suggestion, applicability = "maybe-incorrect")]
1234 pub(crate) struct FnPtrWithGenericsSugg {
1235 #[suggestion_part(code = "{snippet}")]
1237 pub snippet: String,
1238 #[suggestion_part(code = "")]
1241 pub for_param_list_exists: bool,
1244 #[derive(Diagnostic)]
1245 #[diag(parse_unexpected_if_with_if)]
1246 pub(crate) struct UnexpectedIfWithIf(
1248 #[suggestion(applicability = "machine-applicable", code = " ", style = "verbose")]
1252 #[derive(Diagnostic)]
1253 #[diag(parse_maybe_fn_typo_with_impl)]
1254 pub(crate) struct FnTypoWithImpl {
1256 #[suggestion(applicability = "maybe-incorrect", code = "impl", style = "verbose")]
1260 #[derive(Diagnostic)]
1261 #[diag(parse_expected_fn_path_found_fn_keyword)]
1262 pub(crate) struct ExpectedFnPathFoundFnKeyword {
1264 #[suggestion(applicability = "machine-applicable", code = "Fn", style = "verbose")]
1265 pub fn_token_span: Span,
1268 #[derive(Diagnostic)]
1269 #[diag(parse_where_clause_before_tuple_struct_body)]
1270 pub(crate) struct WhereClauseBeforeTupleStructBody {
1274 #[label(name_label)]
1276 #[label(body_label)]
1279 pub sugg: Option<WhereClauseBeforeTupleStructBodySugg>,
1282 #[derive(Subdiagnostic)]
1283 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1284 pub(crate) struct WhereClauseBeforeTupleStructBodySugg {
1285 #[suggestion_part(code = "{snippet}")]
1287 pub snippet: String,
1288 #[suggestion_part(code = "")]