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(parser_maybe_report_ambiguous_plus)]
13 pub(crate) struct AmbiguousPlus {
16 #[suggestion(code = "({sum_ty})")]
21 #[diag(parser_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(parser_forgot_paren)]
47 #[label(parser_expect_path)]
55 #[diag(parser_maybe_recover_from_bad_qpath_stage_2)]
56 pub(crate) struct BadQPathStage2 {
58 #[suggestion(code = "", applicability = "maybe-incorrect")]
64 #[diag(parser_incorrect_semicolon)]
65 pub(crate) struct IncorrectSemicolon<'a> {
67 #[suggestion(style = "short", code = "", applicability = "machine-applicable")]
70 pub opt_help: Option<()>,
75 #[diag(parser_incorrect_use_of_await)]
76 pub(crate) struct IncorrectUseOfAwait {
78 #[suggestion(parentheses_suggestion, code = "", applicability = "machine-applicable")]
83 #[diag(parser_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(parser_in_in_typo)]
95 pub(crate) struct InInTypo {
98 #[suggestion(code = "", applicability = "machine-applicable")]
102 #[derive(Diagnostic)]
103 #[diag(parser_invalid_variable_declaration)]
104 pub(crate) struct InvalidVariableDeclaration {
108 pub sub: InvalidVariableDeclarationSub,
111 #[derive(Subdiagnostic)]
112 pub(crate) enum InvalidVariableDeclarationSub {
113 #[suggestion(parser_switch_mut_let_order, applicability = "maybe-incorrect", code = "let mut")]
114 SwitchMutLetOrder(#[primary_span] Span),
116 parser_missing_let_before_mut,
117 applicability = "machine-applicable",
120 MissingLet(#[primary_span] Span),
121 #[suggestion(parser_use_let_not_auto, applicability = "machine-applicable", code = "let")]
122 UseLetNotAuto(#[primary_span] Span),
123 #[suggestion(parser_use_let_not_var, applicability = "machine-applicable", code = "let")]
124 UseLetNotVar(#[primary_span] Span),
127 #[derive(Diagnostic)]
128 #[diag(parser_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(parser_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(parser_tilde_is_not_unary_operator)]
186 pub(crate) struct TildeAsUnaryOperator(
188 #[suggestion(style = "short", applicability = "machine-applicable", code = "!")]
192 #[derive(Diagnostic)]
193 #[diag(parser_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 parser_unexpected_token_after_not_default,
207 applicability = "machine-applicable",
210 SuggestNotDefault(#[primary_span] Span),
213 parser_unexpected_token_after_not_bitwise,
215 applicability = "machine-applicable",
218 SuggestNotBitwise(#[primary_span] Span),
221 parser_unexpected_token_after_not_logical,
223 applicability = "machine-applicable",
226 SuggestNotLogical(#[primary_span] Span),
229 #[derive(Diagnostic)]
230 #[diag(parser_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(parser_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(parser_field_expression_with_generic)]
250 pub(crate) struct FieldExpressionWithGeneric(#[primary_span] pub Span);
252 #[derive(Diagnostic)]
253 #[diag(parser_macro_invocation_with_qualified_path)]
254 pub(crate) struct MacroInvocationWithQualifiedPath(#[primary_span] pub Span);
256 #[derive(Diagnostic)]
257 #[diag(parser_unexpected_token_after_label)]
258 pub(crate) struct UnexpectedTokenAfterLabel {
260 #[label(parser_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(parser_require_colon_after_labeled_expression)]
280 pub(crate) struct RequireColonAfterLabeledExpression {
285 #[suggestion(style = "short", applicability = "machine-applicable", code = ": ")]
289 #[derive(Diagnostic)]
290 #[diag(parser_do_catch_syntax_removed)]
292 pub(crate) struct DoCatchSyntaxRemoved {
294 #[suggestion(applicability = "machine-applicable", code = "try")]
298 #[derive(Diagnostic)]
299 #[diag(parser_float_literal_requires_integer_part)]
300 pub(crate) struct FloatLiteralRequiresIntegerPart {
302 #[suggestion(applicability = "machine-applicable", code = "{correct}")]
307 #[derive(Diagnostic)]
308 #[diag(parser_invalid_int_literal_width)]
310 pub(crate) struct InvalidIntLiteralWidth {
316 #[derive(Diagnostic)]
317 #[diag(parser_invalid_num_literal_base_prefix)]
319 pub(crate) struct InvalidNumLiteralBasePrefix {
321 #[suggestion(applicability = "maybe-incorrect", code = "{fixed}")]
326 #[derive(Diagnostic)]
327 #[diag(parser_invalid_num_literal_suffix)]
329 pub(crate) struct InvalidNumLiteralSuffix {
336 #[derive(Diagnostic)]
337 #[diag(parser_invalid_float_literal_width)]
339 pub(crate) struct InvalidFloatLiteralWidth {
345 #[derive(Diagnostic)]
346 #[diag(parser_invalid_float_literal_suffix)]
348 pub(crate) struct InvalidFloatLiteralSuffix {
355 #[derive(Diagnostic)]
356 #[diag(parser_int_literal_too_large)]
357 pub(crate) struct IntLiteralTooLarge {
362 #[derive(Diagnostic)]
363 #[diag(parser_missing_semicolon_before_array)]
364 pub(crate) struct MissingSemicolonBeforeArray {
366 pub open_delim: Span,
367 #[suggestion(style = "verbose", applicability = "maybe-incorrect", code = ";")]
371 #[derive(Diagnostic)]
372 #[diag(parser_invalid_block_macro_segment)]
373 pub(crate) struct InvalidBlockMacroSegment {
380 #[derive(Diagnostic)]
381 #[diag(parser_if_expression_missing_then_block)]
382 pub(crate) struct IfExpressionMissingThenBlock {
386 pub sub: IfExpressionMissingThenBlockSub,
389 #[derive(Subdiagnostic)]
390 pub(crate) enum IfExpressionMissingThenBlockSub {
391 #[help(condition_possibly_unfinished)]
392 UnfinishedCondition(#[primary_span] Span),
393 #[help(add_then_block)]
394 AddThenBlock(#[primary_span] Span),
397 #[derive(Diagnostic)]
398 #[diag(parser_if_expression_missing_condition)]
399 pub(crate) struct IfExpressionMissingCondition {
401 #[label(condition_label)]
403 #[label(block_label)]
404 pub block_span: Span,
407 #[derive(Diagnostic)]
408 #[diag(parser_expected_expression_found_let)]
409 pub(crate) struct ExpectedExpressionFoundLet {
414 #[derive(Diagnostic)]
415 #[diag(parser_expected_else_block)]
416 pub(crate) struct ExpectedElseBlock {
418 pub first_tok_span: Span,
419 pub first_tok: String,
422 #[suggestion(applicability = "maybe-incorrect", code = "if ")]
423 pub condition_start: Span,
426 #[derive(Diagnostic)]
427 #[diag(parser_outer_attribute_not_allowed_on_if_else)]
428 pub(crate) struct OuterAttributeNotAllowedOnIfElse {
432 #[label(branch_label)]
433 pub branch_span: Span,
439 #[suggestion(applicability = "machine-applicable", code = "")]
440 pub attributes: Span,
443 #[derive(Diagnostic)]
444 #[diag(parser_missing_in_in_for_loop)]
445 pub(crate) struct MissingInInForLoop {
449 pub sub: MissingInInForLoopSub,
452 #[derive(Subdiagnostic)]
453 pub(crate) enum MissingInInForLoopSub {
454 // Has been misleading, at least in the past (closed Issue #48492), thus maybe-incorrect
455 #[suggestion(use_in_not_of, style = "short", applicability = "maybe-incorrect", code = "in")]
456 InNotOf(#[primary_span] Span),
457 #[suggestion(add_in, style = "short", applicability = "maybe-incorrect", code = " in ")]
458 AddIn(#[primary_span] Span),
461 #[derive(Diagnostic)]
462 #[diag(parser_missing_comma_after_match_arm)]
463 pub(crate) struct MissingCommaAfterMatchArm {
465 #[suggestion(applicability = "machine-applicable", code = ",")]
469 #[derive(Diagnostic)]
470 #[diag(parser_catch_after_try)]
472 pub(crate) struct CatchAfterTry {
477 #[derive(Diagnostic)]
478 #[diag(parser_comma_after_base_struct)]
480 pub(crate) struct CommaAfterBaseStruct {
483 #[suggestion(style = "short", applicability = "machine-applicable", code = "")]
487 #[derive(Diagnostic)]
488 #[diag(parser_eq_field_init)]
489 pub(crate) struct EqFieldInit {
492 #[suggestion(applicability = "machine-applicable", code = ":")]
496 #[derive(Diagnostic)]
497 #[diag(parser_dotdotdot)]
498 pub(crate) struct DotDotDot {
500 #[suggestion(suggest_exclusive_range, applicability = "maybe-incorrect", code = "..")]
501 #[suggestion(suggest_inclusive_range, applicability = "maybe-incorrect", code = "..=")]
505 #[derive(Diagnostic)]
506 #[diag(parser_left_arrow_operator)]
507 pub(crate) struct LeftArrowOperator {
509 #[suggestion(applicability = "maybe-incorrect", code = "< -")]
513 #[derive(Diagnostic)]
514 #[diag(parser_remove_let)]
515 pub(crate) struct RemoveLet {
517 #[suggestion(applicability = "machine-applicable", code = "")]
521 #[derive(Diagnostic)]
522 #[diag(parser_use_eq_instead)]
523 pub(crate) struct UseEqInstead {
525 #[suggestion(style = "short", applicability = "machine-applicable", code = "=")]
529 #[derive(Diagnostic)]
530 #[diag(parser_use_empty_block_not_semi)]
531 pub(crate) struct UseEmptyBlockNotSemi {
533 #[suggestion(style = "hidden", applicability = "machine-applicable", code = "{{}}")]
537 #[derive(Diagnostic)]
538 #[diag(parser_comparison_interpreted_as_generic)]
539 pub(crate) struct ComparisonInterpretedAsGeneric {
541 #[label(label_comparison)]
542 pub comparison: Span,
547 pub suggestion: ComparisonOrShiftInterpretedAsGenericSugg,
550 #[derive(Diagnostic)]
551 #[diag(parser_shift_interpreted_as_generic)]
552 pub(crate) struct ShiftInterpretedAsGeneric {
554 #[label(label_comparison)]
560 pub suggestion: ComparisonOrShiftInterpretedAsGenericSugg,
563 #[derive(Subdiagnostic)]
564 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
565 pub(crate) struct ComparisonOrShiftInterpretedAsGenericSugg {
566 #[suggestion_part(code = "(")]
568 #[suggestion_part(code = ")")]
572 #[derive(Diagnostic)]
573 #[diag(parser_found_expr_would_be_stmt)]
574 pub(crate) struct FoundExprWouldBeStmt {
580 pub suggestion: ExprParenthesesNeeded,
583 #[derive(Diagnostic)]
584 #[diag(parser_leading_plus_not_supported)]
585 pub(crate) struct LeadingPlusNotSupported {
590 suggestion_remove_plus,
593 applicability = "machine-applicable"
595 pub remove_plus: Option<Span>,
597 pub add_parentheses: Option<ExprParenthesesNeeded>,
600 #[derive(Diagnostic)]
601 #[diag(parser_parentheses_with_struct_fields)]
602 pub(crate) struct ParenthesesWithStructFields {
607 pub braces_for_struct: BracesForStructLiteral,
609 pub no_fields_for_fn: NoFieldsForFnCall,
612 #[derive(Subdiagnostic)]
613 #[multipart_suggestion(suggestion_braces_for_struct, applicability = "maybe-incorrect")]
614 pub(crate) struct BracesForStructLiteral {
615 #[suggestion_part(code = " {{ ")]
617 #[suggestion_part(code = " }}")]
621 #[derive(Subdiagnostic)]
622 #[multipart_suggestion(suggestion_no_fields_for_fn, applicability = "maybe-incorrect")]
623 pub(crate) struct NoFieldsForFnCall {
624 #[suggestion_part(code = "")]
625 pub fields: Vec<Span>,
628 #[derive(Diagnostic)]
629 #[diag(parser_labeled_loop_in_break)]
630 pub(crate) struct LabeledLoopInBreak {
634 pub sub: WrapExpressionInParentheses,
637 #[derive(Subdiagnostic)]
638 #[multipart_suggestion(
639 parser_sugg_wrap_expression_in_parentheses,
640 applicability = "machine-applicable"
642 pub(crate) struct WrapExpressionInParentheses {
643 #[suggestion_part(code = "(")]
645 #[suggestion_part(code = ")")]
649 #[derive(Diagnostic)]
650 #[diag(parser_array_brackets_instead_of_braces)]
651 pub(crate) struct ArrayBracketsInsteadOfSpaces {
655 pub sub: ArrayBracketsInsteadOfSpacesSugg,
658 #[derive(Subdiagnostic)]
659 #[multipart_suggestion(suggestion, applicability = "maybe-incorrect")]
660 pub(crate) struct ArrayBracketsInsteadOfSpacesSugg {
661 #[suggestion_part(code = "[")]
663 #[suggestion_part(code = "]")]
667 #[derive(Diagnostic)]
668 #[diag(parser_match_arm_body_without_braces)]
669 pub(crate) struct MatchArmBodyWithoutBraces {
671 #[label(label_statements)]
672 pub statements: Span,
673 #[label(label_arrow)]
675 pub num_statements: usize,
677 pub sub: MatchArmBodyWithoutBracesSugg,
680 #[derive(Subdiagnostic)]
681 pub(crate) enum MatchArmBodyWithoutBracesSugg {
682 #[multipart_suggestion(suggestion_add_braces, applicability = "machine-applicable")]
684 #[suggestion_part(code = "{{ ")]
686 #[suggestion_part(code = " }}")]
690 suggestion_use_comma_not_semicolon,
692 applicability = "machine-applicable"
700 #[derive(Diagnostic)]
701 #[diag(parser_struct_literal_not_allowed_here)]
702 pub(crate) struct StructLiteralNotAllowedHere {
706 pub sub: StructLiteralNotAllowedHereSugg,
709 #[derive(Subdiagnostic)]
710 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
711 pub(crate) struct StructLiteralNotAllowedHereSugg {
712 #[suggestion_part(code = "(")]
714 #[suggestion_part(code = ")")]
718 #[derive(Diagnostic)]
719 #[diag(parser_invalid_interpolated_expression)]
720 pub(crate) struct InvalidInterpolatedExpression {
725 #[derive(Diagnostic)]
726 #[diag(parser_hexadecimal_float_literal_not_supported)]
727 pub(crate) struct HexadecimalFloatLiteralNotSupported {
729 #[label(parser_not_supported)]
733 #[derive(Diagnostic)]
734 #[diag(parser_octal_float_literal_not_supported)]
735 pub(crate) struct OctalFloatLiteralNotSupported {
737 #[label(parser_not_supported)]
741 #[derive(Diagnostic)]
742 #[diag(parser_binary_float_literal_not_supported)]
743 pub(crate) struct BinaryFloatLiteralNotSupported {
745 #[label(parser_not_supported)]
749 #[derive(Diagnostic)]
750 #[diag(parser_invalid_literal_suffix)]
751 pub(crate) struct InvalidLiteralSuffix {
760 #[derive(Diagnostic)]
761 #[diag(parser_invalid_literal_suffix_on_tuple_index)]
762 pub(crate) struct InvalidLiteralSuffixOnTupleIndex {
767 #[help(tuple_exception_line_1)]
768 #[help(tuple_exception_line_2)]
769 #[help(tuple_exception_line_3)]
770 pub exception: Option<()>,
773 #[derive(Diagnostic)]
774 #[diag(parser_non_string_abi_literal)]
775 pub(crate) struct NonStringAbiLiteral {
777 #[suggestion(code = "\"C\"", applicability = "maybe-incorrect")]
781 #[derive(Diagnostic)]
782 #[diag(parser_mismatched_closing_delimiter)]
783 pub(crate) struct MismatchedClosingDelimiter {
785 pub spans: Vec<Span>,
786 pub delimiter: String,
787 #[label(label_unmatched)]
789 #[label(label_opening_candidate)]
790 pub opening_candidate: Option<Span>,
791 #[label(label_unclosed)]
792 pub unclosed: Option<Span>,
795 #[derive(Diagnostic)]
796 #[diag(parser_incorrect_visibility_restriction, code = "E0704")]
798 pub(crate) struct IncorrectVisibilityRestriction {
800 #[suggestion(code = "in {inner_str}", applicability = "machine-applicable")]
802 pub inner_str: String,
805 #[derive(Diagnostic)]
806 #[diag(parser_assignment_else_not_allowed)]
807 pub(crate) struct AssignmentElseNotAllowed {
812 #[derive(Diagnostic)]
813 #[diag(parser_expected_statement_after_outer_attr)]
814 pub(crate) struct ExpectedStatementAfterOuterAttr {
819 #[derive(Diagnostic)]
820 #[diag(parser_doc_comment_does_not_document_anything, code = "E0585")]
822 pub(crate) struct DocCommentDoesNotDocumentAnything {
825 #[suggestion(code = ",", applicability = "machine-applicable")]
826 pub missing_comma: Option<Span>,
829 #[derive(Diagnostic)]
830 #[diag(parser_const_let_mutually_exclusive)]
831 pub(crate) struct ConstLetMutuallyExclusive {
833 #[suggestion(code = "const", applicability = "maybe-incorrect")]
837 #[derive(Diagnostic)]
838 #[diag(parser_invalid_expression_in_let_else)]
839 pub(crate) struct InvalidExpressionInLetElse {
842 pub operator: &'static str,
844 pub sugg: WrapExpressionInParentheses,
847 #[derive(Diagnostic)]
848 #[diag(parser_invalid_curly_in_let_else)]
849 pub(crate) struct InvalidCurlyInLetElse {
853 pub sugg: WrapExpressionInParentheses,
856 #[derive(Diagnostic)]
857 #[diag(parser_compound_assignment_expression_in_let)]
859 pub(crate) struct CompoundAssignmentExpressionInLet {
861 #[suggestion(style = "short", code = "=", applicability = "maybe-incorrect")]
865 #[derive(Diagnostic)]
866 #[diag(parser_suffixed_literal_in_attribute)]
868 pub(crate) struct SuffixedLiteralInAttribute {
873 #[derive(Diagnostic)]
874 #[diag(parser_invalid_meta_item)]
875 pub(crate) struct InvalidMetaItem {
881 #[derive(Subdiagnostic)]
883 parser_sugg_escape_to_use_as_identifier,
885 applicability = "maybe-incorrect",
888 pub(crate) struct SuggEscapeToUseAsIdentifier {
891 pub ident_name: String,
894 #[derive(Subdiagnostic)]
895 #[suggestion(parser_sugg_remove_comma, applicability = "machine-applicable", code = "")]
896 pub(crate) struct SuggRemoveComma {
901 #[derive(Subdiagnostic)]
902 pub(crate) enum ExpectedIdentifierFound {
903 #[label(parser_expected_identifier_found_reserved_identifier)]
904 ReservedIdentifier(#[primary_span] Span),
905 #[label(parser_expected_identifier_found_keyword)]
906 Keyword(#[primary_span] Span),
907 #[label(parser_expected_identifier_found_reserved_keyword)]
908 ReservedKeyword(#[primary_span] Span),
909 #[label(parser_expected_identifier_found_doc_comment)]
910 DocComment(#[primary_span] Span),
911 #[label(parser_expected_identifier)]
912 Other(#[primary_span] Span),
915 impl ExpectedIdentifierFound {
916 pub fn new(token_descr: Option<TokenDescription>, span: Span) -> Self {
918 Some(TokenDescription::ReservedIdentifier) => {
919 ExpectedIdentifierFound::ReservedIdentifier
921 Some(TokenDescription::Keyword) => ExpectedIdentifierFound::Keyword,
922 Some(TokenDescription::ReservedKeyword) => ExpectedIdentifierFound::ReservedKeyword,
923 Some(TokenDescription::DocComment) => ExpectedIdentifierFound::DocComment,
924 None => ExpectedIdentifierFound::Other,
929 pub(crate) struct ExpectedIdentifier {
932 pub suggest_raw: Option<SuggEscapeToUseAsIdentifier>,
933 pub suggest_remove_comma: Option<SuggRemoveComma>,
936 impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedIdentifier {
939 handler: &'a rustc_errors::Handler,
940 ) -> rustc_errors::DiagnosticBuilder<'a, G> {
941 let token_descr = super::parser::TokenDescription::from_token(&self.token);
943 let mut diag = handler.struct_diagnostic(match token_descr {
944 Some(TokenDescription::ReservedIdentifier) => {
945 fluent::parser_expected_identifier_found_reserved_identifier_str
947 Some(TokenDescription::Keyword) => fluent::parser_expected_identifier_found_keyword_str,
948 Some(TokenDescription::ReservedKeyword) => {
949 fluent::parser_expected_identifier_found_reserved_keyword_str
951 Some(TokenDescription::DocComment) => {
952 fluent::parser_expected_identifier_found_doc_comment_str
954 None => fluent::parser_expected_identifier_found_str,
956 diag.set_span(self.span);
957 diag.set_arg("token", self.token);
959 if let Some(sugg) = self.suggest_raw {
960 sugg.add_to_diagnostic(&mut diag);
963 ExpectedIdentifierFound::new(token_descr, self.span).add_to_diagnostic(&mut diag);
965 if let Some(sugg) = self.suggest_remove_comma {
966 sugg.add_to_diagnostic(&mut diag);
973 pub(crate) struct ExpectedSemi {
977 pub unexpected_token_label: Option<Span>,
978 pub sugg: ExpectedSemiSugg,
981 impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedSemi {
984 handler: &'a rustc_errors::Handler,
985 ) -> rustc_errors::DiagnosticBuilder<'a, G> {
986 let token_descr = super::parser::TokenDescription::from_token(&self.token);
988 let mut diag = handler.struct_diagnostic(match token_descr {
989 Some(TokenDescription::ReservedIdentifier) => {
990 fluent::parser_expected_semi_found_reserved_identifier_str
992 Some(TokenDescription::Keyword) => fluent::parser_expected_semi_found_keyword_str,
993 Some(TokenDescription::ReservedKeyword) => {
994 fluent::parser_expected_semi_found_reserved_keyword_str
996 Some(TokenDescription::DocComment) => {
997 fluent::parser_expected_semi_found_doc_comment_str
999 None => fluent::parser_expected_semi_found_str,
1001 diag.set_span(self.span);
1002 diag.set_arg("token", self.token);
1004 if let Some(unexpected_token_label) = self.unexpected_token_label {
1005 diag.span_label(unexpected_token_label, fluent::parser_label_unexpected_token);
1008 self.sugg.add_to_diagnostic(&mut diag);
1014 #[derive(Subdiagnostic)]
1015 pub(crate) enum ExpectedSemiSugg {
1017 parser_sugg_change_this_to_semi,
1019 applicability = "machine-applicable"
1021 ChangeToSemi(#[primary_span] Span),
1023 parser_sugg_add_semi,
1026 applicability = "machine-applicable"
1028 AddSemi(#[primary_span] Span),
1031 #[derive(Diagnostic)]
1032 #[diag(parser_struct_literal_body_without_path)]
1033 pub(crate) struct StructLiteralBodyWithoutPath {
1037 pub sugg: StructLiteralBodyWithoutPathSugg,
1040 #[derive(Subdiagnostic)]
1041 #[multipart_suggestion(suggestion, applicability = "has-placeholders")]
1042 pub(crate) struct StructLiteralBodyWithoutPathSugg {
1043 #[suggestion_part(code = "{{ SomeStruct ")]
1045 #[suggestion_part(code = " }}")]
1049 #[derive(Diagnostic)]
1050 #[diag(parser_unmatched_angle_brackets)]
1051 pub(crate) struct UnmatchedAngleBrackets {
1053 #[suggestion(code = "", applicability = "machine-applicable")]
1055 pub num_extra_brackets: usize,
1058 #[derive(Diagnostic)]
1059 #[diag(parser_generic_parameters_without_angle_brackets)]
1060 pub(crate) struct GenericParamsWithoutAngleBrackets {
1064 pub sugg: GenericParamsWithoutAngleBracketsSugg,
1067 #[derive(Subdiagnostic)]
1068 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1069 pub(crate) struct GenericParamsWithoutAngleBracketsSugg {
1070 #[suggestion_part(code = "<")]
1072 #[suggestion_part(code = ">")]
1076 #[derive(Diagnostic)]
1077 #[diag(parser_comparison_operators_cannot_be_chained)]
1078 pub(crate) struct ComparisonOperatorsCannotBeChained {
1080 pub span: Vec<Span>,
1082 parser_sugg_turbofish_syntax,
1085 applicability = "maybe-incorrect"
1087 pub suggest_turbofish: Option<Span>,
1088 #[help(parser_sugg_turbofish_syntax)]
1089 #[help(sugg_parentheses_for_function_args)]
1090 pub help_turbofish: Option<()>,
1092 pub chaining_sugg: Option<ComparisonOperatorsCannotBeChainedSugg>,
1095 #[derive(Subdiagnostic)]
1096 pub(crate) enum ComparisonOperatorsCannotBeChainedSugg {
1098 sugg_split_comparison,
1100 code = " && {middle_term}",
1101 applicability = "maybe-incorrect"
1106 middle_term: String,
1108 #[multipart_suggestion(sugg_parenthesize, applicability = "maybe-incorrect")]
1110 #[suggestion_part(code = "(")]
1112 #[suggestion_part(code = ")")]
1117 #[derive(Diagnostic)]
1118 #[diag(parser_question_mark_in_type)]
1119 pub(crate) struct QuestionMarkInType {
1124 pub sugg: QuestionMarkInTypeSugg,
1127 #[derive(Subdiagnostic)]
1128 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1129 pub(crate) struct QuestionMarkInTypeSugg {
1130 #[suggestion_part(code = "Option<")]
1132 #[suggestion_part(code = ">")]
1136 #[derive(Diagnostic)]
1137 #[diag(parser_unexpected_parentheses_in_for_head)]
1138 pub(crate) struct ParenthesesInForHead {
1140 pub span: Vec<Span>,
1142 pub sugg: ParenthesesInForHeadSugg,
1145 #[derive(Subdiagnostic)]
1146 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1147 pub(crate) struct ParenthesesInForHeadSugg {
1148 #[suggestion_part(code = "")]
1150 #[suggestion_part(code = "")]
1154 #[derive(Diagnostic)]
1155 #[diag(parser_doc_comment_on_param_type)]
1156 pub(crate) struct DocCommentOnParamType {
1162 #[derive(Diagnostic)]
1163 #[diag(parser_attribute_on_param_type)]
1164 pub(crate) struct AttributeOnParamType {
1170 #[derive(Diagnostic)]
1171 #[diag(parser_pattern_method_param_without_body, code = "E0642")]
1172 pub(crate) struct PatternMethodParamWithoutBody {
1174 #[suggestion(code = "_", applicability = "machine-applicable")]
1178 #[derive(Diagnostic)]
1179 #[diag(parser_self_param_not_first)]
1180 pub(crate) struct SelfParamNotFirst {
1186 #[derive(Diagnostic)]
1187 #[diag(parser_const_generic_without_braces)]
1188 pub(crate) struct ConstGenericWithoutBraces {
1192 pub sugg: ConstGenericWithoutBracesSugg,
1195 #[derive(Subdiagnostic)]
1196 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1197 pub(crate) struct ConstGenericWithoutBracesSugg {
1198 #[suggestion_part(code = "{{ ")]
1200 #[suggestion_part(code = " }}")]
1204 #[derive(Diagnostic)]
1205 #[diag(parser_unexpected_const_param_declaration)]
1206 pub(crate) struct UnexpectedConstParamDeclaration {
1211 pub sugg: Option<UnexpectedConstParamDeclarationSugg>,
1214 #[derive(Subdiagnostic)]
1215 pub(crate) enum UnexpectedConstParamDeclarationSugg {
1216 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1218 #[suggestion_part(code = "<{snippet}>")]
1219 impl_generics: Span,
1220 #[suggestion_part(code = "{ident}")]
1221 incorrect_decl: Span,
1225 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1227 #[suggestion_part(code = ", {snippet}")]
1228 impl_generics_end: Span,
1229 #[suggestion_part(code = "{ident}")]
1230 incorrect_decl: Span,
1236 #[derive(Diagnostic)]
1237 #[diag(parser_unexpected_const_in_generic_param)]
1238 pub(crate) struct UnexpectedConstInGenericParam {
1241 #[suggestion(style = "verbose", code = "", applicability = "maybe-incorrect")]
1242 pub to_remove: Option<Span>,
1245 #[derive(Diagnostic)]
1246 #[diag(parser_async_move_order_incorrect)]
1247 pub(crate) struct AsyncMoveOrderIncorrect {
1249 #[suggestion(style = "verbose", code = "async move", applicability = "maybe-incorrect")]
1253 #[derive(Diagnostic)]
1254 #[diag(parser_double_colon_in_bound)]
1255 pub(crate) struct DoubleColonInBound {
1258 #[suggestion(code = ": ", applicability = "machine-applicable")]