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 sub: IfExpressionMissingThenBlockSub,
343 #[derive(Subdiagnostic)]
344 pub(crate) enum IfExpressionMissingThenBlockSub {
345 #[help(condition_possibly_unfinished)]
346 UnfinishedCondition(#[primary_span] Span),
347 #[help(add_then_block)]
348 AddThenBlock(#[primary_span] Span),
351 #[derive(Diagnostic)]
352 #[diag(parse_if_expression_missing_condition)]
353 pub(crate) struct IfExpressionMissingCondition {
355 #[label(condition_label)]
357 #[label(block_label)]
358 pub block_span: Span,
361 #[derive(Diagnostic)]
362 #[diag(parse_expected_expression_found_let)]
363 pub(crate) struct ExpectedExpressionFoundLet {
368 #[derive(Diagnostic)]
369 #[diag(parse_expect_eq_instead_of_eqeq)]
370 pub(crate) struct ExpectedEqForLetExpr {
373 #[suggestion(applicability = "maybe-incorrect", code = "=", style = "verbose")]
377 #[derive(Diagnostic)]
378 #[diag(parse_expected_else_block)]
379 pub(crate) struct ExpectedElseBlock {
381 pub first_tok_span: Span,
382 pub first_tok: String,
385 #[suggestion(applicability = "maybe-incorrect", code = "if ")]
386 pub condition_start: Span,
389 #[derive(Diagnostic)]
390 #[diag(parse_outer_attribute_not_allowed_on_if_else)]
391 pub(crate) struct OuterAttributeNotAllowedOnIfElse {
395 #[label(branch_label)]
396 pub branch_span: Span,
402 #[suggestion(applicability = "machine-applicable", code = "")]
403 pub attributes: Span,
406 #[derive(Diagnostic)]
407 #[diag(parse_missing_in_in_for_loop)]
408 pub(crate) struct MissingInInForLoop {
412 pub sub: MissingInInForLoopSub,
415 #[derive(Subdiagnostic)]
416 pub(crate) enum MissingInInForLoopSub {
417 // Has been misleading, at least in the past (closed Issue #48492), thus maybe-incorrect
418 #[suggestion(use_in_not_of, style = "short", applicability = "maybe-incorrect", code = "in")]
419 InNotOf(#[primary_span] Span),
420 #[suggestion(add_in, style = "short", applicability = "maybe-incorrect", code = " in ")]
421 AddIn(#[primary_span] Span),
424 #[derive(Diagnostic)]
425 #[diag(parse_missing_comma_after_match_arm)]
426 pub(crate) struct MissingCommaAfterMatchArm {
428 #[suggestion(applicability = "machine-applicable", code = ",")]
432 #[derive(Diagnostic)]
433 #[diag(parse_catch_after_try)]
435 pub(crate) struct CatchAfterTry {
440 #[derive(Diagnostic)]
441 #[diag(parse_comma_after_base_struct)]
443 pub(crate) struct CommaAfterBaseStruct {
446 #[suggestion(style = "short", applicability = "machine-applicable", code = "")]
450 #[derive(Diagnostic)]
451 #[diag(parse_eq_field_init)]
452 pub(crate) struct EqFieldInit {
455 #[suggestion(applicability = "machine-applicable", code = ":")]
459 #[derive(Diagnostic)]
460 #[diag(parse_dotdotdot)]
461 pub(crate) struct DotDotDot {
463 #[suggestion(suggest_exclusive_range, applicability = "maybe-incorrect", code = "..")]
464 #[suggestion(suggest_inclusive_range, applicability = "maybe-incorrect", code = "..=")]
468 #[derive(Diagnostic)]
469 #[diag(parse_left_arrow_operator)]
470 pub(crate) struct LeftArrowOperator {
472 #[suggestion(applicability = "maybe-incorrect", code = "< -")]
476 #[derive(Diagnostic)]
477 #[diag(parse_remove_let)]
478 pub(crate) struct RemoveLet {
480 #[suggestion(applicability = "machine-applicable", code = "")]
484 #[derive(Diagnostic)]
485 #[diag(parse_use_eq_instead)]
486 pub(crate) struct UseEqInstead {
488 #[suggestion(style = "short", applicability = "machine-applicable", code = "=")]
492 #[derive(Diagnostic)]
493 #[diag(parse_use_empty_block_not_semi)]
494 pub(crate) struct UseEmptyBlockNotSemi {
496 #[suggestion(style = "hidden", applicability = "machine-applicable", code = "{{}}")]
500 #[derive(Diagnostic)]
501 #[diag(parse_comparison_interpreted_as_generic)]
502 pub(crate) struct ComparisonInterpretedAsGeneric {
504 #[label(label_comparison)]
505 pub comparison: Span,
510 pub suggestion: ComparisonOrShiftInterpretedAsGenericSugg,
513 #[derive(Diagnostic)]
514 #[diag(parse_shift_interpreted_as_generic)]
515 pub(crate) struct ShiftInterpretedAsGeneric {
517 #[label(label_comparison)]
523 pub suggestion: ComparisonOrShiftInterpretedAsGenericSugg,
526 #[derive(Subdiagnostic)]
527 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
528 pub(crate) struct ComparisonOrShiftInterpretedAsGenericSugg {
529 #[suggestion_part(code = "(")]
531 #[suggestion_part(code = ")")]
535 #[derive(Diagnostic)]
536 #[diag(parse_found_expr_would_be_stmt)]
537 pub(crate) struct FoundExprWouldBeStmt {
543 pub suggestion: ExprParenthesesNeeded,
546 #[derive(Diagnostic)]
547 #[diag(parse_leading_plus_not_supported)]
548 pub(crate) struct LeadingPlusNotSupported {
553 suggestion_remove_plus,
556 applicability = "machine-applicable"
558 pub remove_plus: Option<Span>,
560 pub add_parentheses: Option<ExprParenthesesNeeded>,
563 #[derive(Diagnostic)]
564 #[diag(parse_parentheses_with_struct_fields)]
565 pub(crate) struct ParenthesesWithStructFields {
570 pub braces_for_struct: BracesForStructLiteral,
572 pub no_fields_for_fn: NoFieldsForFnCall,
575 #[derive(Subdiagnostic)]
576 #[multipart_suggestion(suggestion_braces_for_struct, applicability = "maybe-incorrect")]
577 pub(crate) struct BracesForStructLiteral {
578 #[suggestion_part(code = " {{ ")]
580 #[suggestion_part(code = " }}")]
584 #[derive(Subdiagnostic)]
585 #[multipart_suggestion(suggestion_no_fields_for_fn, applicability = "maybe-incorrect")]
586 pub(crate) struct NoFieldsForFnCall {
587 #[suggestion_part(code = "")]
588 pub fields: Vec<Span>,
591 #[derive(Diagnostic)]
592 #[diag(parse_labeled_loop_in_break)]
593 pub(crate) struct LabeledLoopInBreak {
597 pub sub: WrapExpressionInParentheses,
600 #[derive(Subdiagnostic)]
601 #[multipart_suggestion(
602 parse_sugg_wrap_expression_in_parentheses,
603 applicability = "machine-applicable"
605 pub(crate) struct WrapExpressionInParentheses {
606 #[suggestion_part(code = "(")]
608 #[suggestion_part(code = ")")]
612 #[derive(Diagnostic)]
613 #[diag(parse_array_brackets_instead_of_braces)]
614 pub(crate) struct ArrayBracketsInsteadOfSpaces {
618 pub sub: ArrayBracketsInsteadOfSpacesSugg,
621 #[derive(Subdiagnostic)]
622 #[multipart_suggestion(suggestion, applicability = "maybe-incorrect")]
623 pub(crate) struct ArrayBracketsInsteadOfSpacesSugg {
624 #[suggestion_part(code = "[")]
626 #[suggestion_part(code = "]")]
630 #[derive(Diagnostic)]
631 #[diag(parse_match_arm_body_without_braces)]
632 pub(crate) struct MatchArmBodyWithoutBraces {
634 #[label(label_statements)]
635 pub statements: Span,
636 #[label(label_arrow)]
638 pub num_statements: usize,
640 pub sub: MatchArmBodyWithoutBracesSugg,
643 #[derive(Subdiagnostic)]
644 pub(crate) enum MatchArmBodyWithoutBracesSugg {
645 #[multipart_suggestion(suggestion_add_braces, applicability = "machine-applicable")]
647 #[suggestion_part(code = "{{ ")]
649 #[suggestion_part(code = " }}")]
653 suggestion_use_comma_not_semicolon,
655 applicability = "machine-applicable"
663 #[derive(Diagnostic)]
664 #[diag(parse_struct_literal_not_allowed_here)]
665 pub(crate) struct StructLiteralNotAllowedHere {
669 pub sub: StructLiteralNotAllowedHereSugg,
672 #[derive(Subdiagnostic)]
673 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
674 pub(crate) struct StructLiteralNotAllowedHereSugg {
675 #[suggestion_part(code = "(")]
677 #[suggestion_part(code = ")")]
681 #[derive(Diagnostic)]
682 #[diag(parse_invalid_interpolated_expression)]
683 pub(crate) struct InvalidInterpolatedExpression {
688 #[derive(Diagnostic)]
689 #[diag(parse_invalid_literal_suffix_on_tuple_index)]
690 pub(crate) struct InvalidLiteralSuffixOnTupleIndex {
695 #[help(tuple_exception_line_1)]
696 #[help(tuple_exception_line_2)]
697 #[help(tuple_exception_line_3)]
698 pub exception: Option<()>,
701 #[derive(Diagnostic)]
702 #[diag(parse_non_string_abi_literal)]
703 pub(crate) struct NonStringAbiLiteral {
705 #[suggestion(code = "\"C\"", applicability = "maybe-incorrect")]
709 #[derive(Diagnostic)]
710 #[diag(parse_mismatched_closing_delimiter)]
711 pub(crate) struct MismatchedClosingDelimiter {
713 pub spans: Vec<Span>,
714 pub delimiter: String,
715 #[label(label_unmatched)]
717 #[label(label_opening_candidate)]
718 pub opening_candidate: Option<Span>,
719 #[label(label_unclosed)]
720 pub unclosed: Option<Span>,
723 #[derive(Diagnostic)]
724 #[diag(parse_incorrect_visibility_restriction, code = "E0704")]
726 pub(crate) struct IncorrectVisibilityRestriction {
728 #[suggestion(code = "in {inner_str}", applicability = "machine-applicable")]
730 pub inner_str: String,
733 #[derive(Diagnostic)]
734 #[diag(parse_assignment_else_not_allowed)]
735 pub(crate) struct AssignmentElseNotAllowed {
740 #[derive(Diagnostic)]
741 #[diag(parse_expected_statement_after_outer_attr)]
742 pub(crate) struct ExpectedStatementAfterOuterAttr {
747 #[derive(Diagnostic)]
748 #[diag(parse_doc_comment_does_not_document_anything, code = "E0585")]
750 pub(crate) struct DocCommentDoesNotDocumentAnything {
753 #[suggestion(code = ",", applicability = "machine-applicable")]
754 pub missing_comma: Option<Span>,
757 #[derive(Diagnostic)]
758 #[diag(parse_const_let_mutually_exclusive)]
759 pub(crate) struct ConstLetMutuallyExclusive {
761 #[suggestion(code = "const", applicability = "maybe-incorrect")]
765 #[derive(Diagnostic)]
766 #[diag(parse_invalid_expression_in_let_else)]
767 pub(crate) struct InvalidExpressionInLetElse {
770 pub operator: &'static str,
772 pub sugg: WrapExpressionInParentheses,
775 #[derive(Diagnostic)]
776 #[diag(parse_invalid_curly_in_let_else)]
777 pub(crate) struct InvalidCurlyInLetElse {
781 pub sugg: WrapExpressionInParentheses,
784 #[derive(Diagnostic)]
785 #[diag(parse_compound_assignment_expression_in_let)]
787 pub(crate) struct CompoundAssignmentExpressionInLet {
789 #[suggestion(style = "short", code = "=", applicability = "maybe-incorrect")]
793 #[derive(Diagnostic)]
794 #[diag(parse_suffixed_literal_in_attribute)]
796 pub(crate) struct SuffixedLiteralInAttribute {
801 #[derive(Diagnostic)]
802 #[diag(parse_invalid_meta_item)]
803 pub(crate) struct InvalidMetaItem {
809 #[derive(Subdiagnostic)]
811 parse_sugg_escape_to_use_as_identifier,
813 applicability = "maybe-incorrect",
816 pub(crate) struct SuggEscapeToUseAsIdentifier {
819 pub ident_name: String,
822 #[derive(Subdiagnostic)]
823 #[suggestion(parse_sugg_remove_comma, applicability = "machine-applicable", code = "")]
824 pub(crate) struct SuggRemoveComma {
829 #[derive(Subdiagnostic)]
830 pub(crate) enum ExpectedIdentifierFound {
831 #[label(parse_expected_identifier_found_reserved_identifier)]
832 ReservedIdentifier(#[primary_span] Span),
833 #[label(parse_expected_identifier_found_keyword)]
834 Keyword(#[primary_span] Span),
835 #[label(parse_expected_identifier_found_reserved_keyword)]
836 ReservedKeyword(#[primary_span] Span),
837 #[label(parse_expected_identifier_found_doc_comment)]
838 DocComment(#[primary_span] Span),
839 #[label(parse_expected_identifier)]
840 Other(#[primary_span] Span),
843 impl ExpectedIdentifierFound {
844 pub fn new(token_descr: Option<TokenDescription>, span: Span) -> Self {
846 Some(TokenDescription::ReservedIdentifier) => {
847 ExpectedIdentifierFound::ReservedIdentifier
849 Some(TokenDescription::Keyword) => ExpectedIdentifierFound::Keyword,
850 Some(TokenDescription::ReservedKeyword) => ExpectedIdentifierFound::ReservedKeyword,
851 Some(TokenDescription::DocComment) => ExpectedIdentifierFound::DocComment,
852 None => ExpectedIdentifierFound::Other,
857 pub(crate) struct ExpectedIdentifier {
860 pub suggest_raw: Option<SuggEscapeToUseAsIdentifier>,
861 pub suggest_remove_comma: Option<SuggRemoveComma>,
864 impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedIdentifier {
868 handler: &'a rustc_errors::Handler,
869 ) -> rustc_errors::DiagnosticBuilder<'a, G> {
870 let token_descr = super::parser::TokenDescription::from_token(&self.token);
872 let mut diag = handler.struct_diagnostic(match token_descr {
873 Some(TokenDescription::ReservedIdentifier) => {
874 fluent::parse_expected_identifier_found_reserved_identifier_str
876 Some(TokenDescription::Keyword) => fluent::parse_expected_identifier_found_keyword_str,
877 Some(TokenDescription::ReservedKeyword) => {
878 fluent::parse_expected_identifier_found_reserved_keyword_str
880 Some(TokenDescription::DocComment) => {
881 fluent::parse_expected_identifier_found_doc_comment_str
883 None => fluent::parse_expected_identifier_found_str,
885 diag.set_span(self.span);
886 diag.set_arg("token", self.token);
888 if let Some(sugg) = self.suggest_raw {
889 sugg.add_to_diagnostic(&mut diag);
892 ExpectedIdentifierFound::new(token_descr, self.span).add_to_diagnostic(&mut diag);
894 if let Some(sugg) = self.suggest_remove_comma {
895 sugg.add_to_diagnostic(&mut diag);
902 pub(crate) struct ExpectedSemi {
906 pub unexpected_token_label: Option<Span>,
907 pub sugg: ExpectedSemiSugg,
910 impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedSemi {
914 handler: &'a rustc_errors::Handler,
915 ) -> rustc_errors::DiagnosticBuilder<'a, G> {
916 let token_descr = super::parser::TokenDescription::from_token(&self.token);
918 let mut diag = handler.struct_diagnostic(match token_descr {
919 Some(TokenDescription::ReservedIdentifier) => {
920 fluent::parse_expected_semi_found_reserved_identifier_str
922 Some(TokenDescription::Keyword) => fluent::parse_expected_semi_found_keyword_str,
923 Some(TokenDescription::ReservedKeyword) => {
924 fluent::parse_expected_semi_found_reserved_keyword_str
926 Some(TokenDescription::DocComment) => fluent::parse_expected_semi_found_doc_comment_str,
927 None => fluent::parse_expected_semi_found_str,
929 diag.set_span(self.span);
930 diag.set_arg("token", self.token);
932 if let Some(unexpected_token_label) = self.unexpected_token_label {
933 diag.span_label(unexpected_token_label, fluent::parse_label_unexpected_token);
936 self.sugg.add_to_diagnostic(&mut diag);
942 #[derive(Subdiagnostic)]
943 pub(crate) enum ExpectedSemiSugg {
944 #[suggestion(parse_sugg_change_this_to_semi, code = ";", applicability = "machine-applicable")]
945 ChangeToSemi(#[primary_span] Span),
950 applicability = "machine-applicable"
952 AddSemi(#[primary_span] Span),
955 #[derive(Diagnostic)]
956 #[diag(parse_struct_literal_body_without_path)]
957 pub(crate) struct StructLiteralBodyWithoutPath {
961 pub sugg: StructLiteralBodyWithoutPathSugg,
964 #[derive(Subdiagnostic)]
965 #[multipart_suggestion(suggestion, applicability = "has-placeholders")]
966 pub(crate) struct StructLiteralBodyWithoutPathSugg {
967 #[suggestion_part(code = "{{ SomeStruct ")]
969 #[suggestion_part(code = " }}")]
973 #[derive(Diagnostic)]
974 #[diag(parse_unmatched_angle_brackets)]
975 pub(crate) struct UnmatchedAngleBrackets {
977 #[suggestion(code = "", applicability = "machine-applicable")]
979 pub num_extra_brackets: usize,
982 #[derive(Diagnostic)]
983 #[diag(parse_generic_parameters_without_angle_brackets)]
984 pub(crate) struct GenericParamsWithoutAngleBrackets {
988 pub sugg: GenericParamsWithoutAngleBracketsSugg,
991 #[derive(Subdiagnostic)]
992 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
993 pub(crate) struct GenericParamsWithoutAngleBracketsSugg {
994 #[suggestion_part(code = "<")]
996 #[suggestion_part(code = ">")]
1000 #[derive(Diagnostic)]
1001 #[diag(parse_comparison_operators_cannot_be_chained)]
1002 pub(crate) struct ComparisonOperatorsCannotBeChained {
1004 pub span: Vec<Span>,
1006 parse_sugg_turbofish_syntax,
1009 applicability = "maybe-incorrect"
1011 pub suggest_turbofish: Option<Span>,
1012 #[help(parse_sugg_turbofish_syntax)]
1013 #[help(sugg_parentheses_for_function_args)]
1014 pub help_turbofish: Option<()>,
1016 pub chaining_sugg: Option<ComparisonOperatorsCannotBeChainedSugg>,
1019 #[derive(Subdiagnostic)]
1020 pub(crate) enum ComparisonOperatorsCannotBeChainedSugg {
1022 sugg_split_comparison,
1024 code = " && {middle_term}",
1025 applicability = "maybe-incorrect"
1030 middle_term: String,
1032 #[multipart_suggestion(sugg_parenthesize, applicability = "maybe-incorrect")]
1034 #[suggestion_part(code = "(")]
1036 #[suggestion_part(code = ")")]
1041 #[derive(Diagnostic)]
1042 #[diag(parse_question_mark_in_type)]
1043 pub(crate) struct QuestionMarkInType {
1048 pub sugg: QuestionMarkInTypeSugg,
1051 #[derive(Subdiagnostic)]
1052 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1053 pub(crate) struct QuestionMarkInTypeSugg {
1054 #[suggestion_part(code = "Option<")]
1056 #[suggestion_part(code = ">")]
1060 #[derive(Diagnostic)]
1061 #[diag(parse_unexpected_parentheses_in_for_head)]
1062 pub(crate) struct ParenthesesInForHead {
1064 pub span: Vec<Span>,
1066 pub sugg: ParenthesesInForHeadSugg,
1069 #[derive(Subdiagnostic)]
1070 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1071 pub(crate) struct ParenthesesInForHeadSugg {
1072 #[suggestion_part(code = "{left_snippet}")]
1074 pub left_snippet: String,
1075 #[suggestion_part(code = "{right_snippet}")]
1077 pub right_snippet: String,
1080 #[derive(Diagnostic)]
1081 #[diag(parse_doc_comment_on_param_type)]
1082 pub(crate) struct DocCommentOnParamType {
1088 #[derive(Diagnostic)]
1089 #[diag(parse_attribute_on_param_type)]
1090 pub(crate) struct AttributeOnParamType {
1096 #[derive(Diagnostic)]
1097 #[diag(parse_pattern_method_param_without_body, code = "E0642")]
1098 pub(crate) struct PatternMethodParamWithoutBody {
1100 #[suggestion(code = "_", applicability = "machine-applicable")]
1104 #[derive(Diagnostic)]
1105 #[diag(parse_self_param_not_first)]
1106 pub(crate) struct SelfParamNotFirst {
1112 #[derive(Diagnostic)]
1113 #[diag(parse_invalid_identifier_with_leading_number)]
1114 pub(crate) struct InvalidIdentiferStartsWithNumber {
1120 #[derive(Diagnostic)]
1121 #[diag(parse_const_generic_without_braces)]
1122 pub(crate) struct ConstGenericWithoutBraces {
1126 pub sugg: ConstGenericWithoutBracesSugg,
1129 #[derive(Subdiagnostic)]
1130 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1131 pub(crate) struct ConstGenericWithoutBracesSugg {
1132 #[suggestion_part(code = "{{ ")]
1134 #[suggestion_part(code = " }}")]
1138 #[derive(Diagnostic)]
1139 #[diag(parse_unexpected_const_param_declaration)]
1140 pub(crate) struct UnexpectedConstParamDeclaration {
1145 pub sugg: Option<UnexpectedConstParamDeclarationSugg>,
1148 #[derive(Subdiagnostic)]
1149 pub(crate) enum UnexpectedConstParamDeclarationSugg {
1150 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1152 #[suggestion_part(code = "<{snippet}>")]
1153 impl_generics: Span,
1154 #[suggestion_part(code = "{ident}")]
1155 incorrect_decl: Span,
1159 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1161 #[suggestion_part(code = ", {snippet}")]
1162 impl_generics_end: Span,
1163 #[suggestion_part(code = "{ident}")]
1164 incorrect_decl: Span,
1170 #[derive(Diagnostic)]
1171 #[diag(parse_unexpected_const_in_generic_param)]
1172 pub(crate) struct UnexpectedConstInGenericParam {
1175 #[suggestion(style = "verbose", code = "", applicability = "maybe-incorrect")]
1176 pub to_remove: Option<Span>,
1179 #[derive(Diagnostic)]
1180 #[diag(parse_async_move_order_incorrect)]
1181 pub(crate) struct AsyncMoveOrderIncorrect {
1183 #[suggestion(style = "verbose", code = "async move", applicability = "maybe-incorrect")]
1187 #[derive(Diagnostic)]
1188 #[diag(parse_double_colon_in_bound)]
1189 pub(crate) struct DoubleColonInBound {
1192 #[suggestion(code = ": ", applicability = "machine-applicable")]
1196 #[derive(Diagnostic)]
1197 #[diag(parse_fn_ptr_with_generics)]
1198 pub(crate) struct FnPtrWithGenerics {
1202 pub sugg: Option<FnPtrWithGenericsSugg>,
1205 #[derive(Subdiagnostic)]
1206 #[multipart_suggestion(suggestion, applicability = "maybe-incorrect")]
1207 pub(crate) struct FnPtrWithGenericsSugg {
1208 #[suggestion_part(code = "{snippet}")]
1210 pub snippet: String,
1211 #[suggestion_part(code = "")]
1214 pub for_param_list_exists: bool,
1217 #[derive(Diagnostic)]
1218 #[diag(parse_unexpected_if_with_if)]
1219 pub(crate) struct UnexpectedIfWithIf(
1221 #[suggestion(applicability = "machine-applicable", code = " ", style = "verbose")]
1225 #[derive(Diagnostic)]
1226 #[diag(parse_maybe_fn_typo_with_impl)]
1227 pub(crate) struct FnTypoWithImpl {
1229 #[suggestion(applicability = "maybe-incorrect", code = "impl", style = "verbose")]
1233 #[derive(Diagnostic)]
1234 #[diag(parse_expected_fn_path_found_fn_keyword)]
1235 pub(crate) struct ExpectedFnPathFoundFnKeyword {
1237 #[suggestion(applicability = "machine-applicable", code = "Fn", style = "verbose")]
1238 pub fn_token_span: Span,