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_expect_dotdot_not_dotdotdot)]
373 pub(crate) struct MissingDotDot {
375 pub token_span: Span,
376 #[suggestion(applicability = "maybe-incorrect", code = "..", style = "verbose")]
380 #[derive(Diagnostic)]
381 #[diag(parser_invalid_block_macro_segment)]
382 pub(crate) struct InvalidBlockMacroSegment {
389 #[derive(Diagnostic)]
390 #[diag(parser_if_expression_missing_then_block)]
391 pub(crate) struct IfExpressionMissingThenBlock {
395 pub sub: IfExpressionMissingThenBlockSub,
398 #[derive(Subdiagnostic)]
399 pub(crate) enum IfExpressionMissingThenBlockSub {
400 #[help(condition_possibly_unfinished)]
401 UnfinishedCondition(#[primary_span] Span),
402 #[help(add_then_block)]
403 AddThenBlock(#[primary_span] Span),
406 #[derive(Diagnostic)]
407 #[diag(parser_if_expression_missing_condition)]
408 pub(crate) struct IfExpressionMissingCondition {
410 #[label(condition_label)]
412 #[label(block_label)]
413 pub block_span: Span,
416 #[derive(Diagnostic)]
417 #[diag(parser_expected_expression_found_let)]
418 pub(crate) struct ExpectedExpressionFoundLet {
423 #[derive(Diagnostic)]
424 #[diag(parser_expect_eq_instead_of_eqeq)]
425 pub(crate) struct ExpectedEqForLetExpr {
428 #[suggestion(applicability = "maybe-incorrect", code = "=", style = "verbose")]
432 #[derive(Diagnostic)]
433 #[diag(parser_expected_else_block)]
434 pub(crate) struct ExpectedElseBlock {
436 pub first_tok_span: Span,
437 pub first_tok: String,
440 #[suggestion(applicability = "maybe-incorrect", code = "if ")]
441 pub condition_start: Span,
444 #[derive(Diagnostic)]
445 #[diag(parser_outer_attribute_not_allowed_on_if_else)]
446 pub(crate) struct OuterAttributeNotAllowedOnIfElse {
450 #[label(branch_label)]
451 pub branch_span: Span,
457 #[suggestion(applicability = "machine-applicable", code = "")]
458 pub attributes: Span,
461 #[derive(Diagnostic)]
462 #[diag(parser_missing_in_in_for_loop)]
463 pub(crate) struct MissingInInForLoop {
467 pub sub: MissingInInForLoopSub,
470 #[derive(Subdiagnostic)]
471 pub(crate) enum MissingInInForLoopSub {
472 // Has been misleading, at least in the past (closed Issue #48492), thus maybe-incorrect
473 #[suggestion(use_in_not_of, style = "short", applicability = "maybe-incorrect", code = "in")]
474 InNotOf(#[primary_span] Span),
475 #[suggestion(add_in, style = "short", applicability = "maybe-incorrect", code = " in ")]
476 AddIn(#[primary_span] Span),
479 #[derive(Diagnostic)]
480 #[diag(parser_missing_comma_after_match_arm)]
481 pub(crate) struct MissingCommaAfterMatchArm {
483 #[suggestion(applicability = "machine-applicable", code = ",")]
487 #[derive(Diagnostic)]
488 #[diag(parser_catch_after_try)]
490 pub(crate) struct CatchAfterTry {
495 #[derive(Diagnostic)]
496 #[diag(parser_comma_after_base_struct)]
498 pub(crate) struct CommaAfterBaseStruct {
501 #[suggestion(style = "short", applicability = "machine-applicable", code = "")]
505 #[derive(Diagnostic)]
506 #[diag(parser_eq_field_init)]
507 pub(crate) struct EqFieldInit {
510 #[suggestion(applicability = "machine-applicable", code = ":")]
514 #[derive(Diagnostic)]
515 #[diag(parser_dotdotdot)]
516 pub(crate) struct DotDotDot {
518 #[suggestion(suggest_exclusive_range, applicability = "maybe-incorrect", code = "..")]
519 #[suggestion(suggest_inclusive_range, applicability = "maybe-incorrect", code = "..=")]
523 #[derive(Diagnostic)]
524 #[diag(parser_left_arrow_operator)]
525 pub(crate) struct LeftArrowOperator {
527 #[suggestion(applicability = "maybe-incorrect", code = "< -")]
531 #[derive(Diagnostic)]
532 #[diag(parser_remove_let)]
533 pub(crate) struct RemoveLet {
535 #[suggestion(applicability = "machine-applicable", code = "")]
539 #[derive(Diagnostic)]
540 #[diag(parser_use_eq_instead)]
541 pub(crate) struct UseEqInstead {
543 #[suggestion(style = "short", applicability = "machine-applicable", code = "=")]
547 #[derive(Diagnostic)]
548 #[diag(parser_use_empty_block_not_semi)]
549 pub(crate) struct UseEmptyBlockNotSemi {
551 #[suggestion(style = "hidden", applicability = "machine-applicable", code = "{{}}")]
555 #[derive(Diagnostic)]
556 #[diag(parser_comparison_interpreted_as_generic)]
557 pub(crate) struct ComparisonInterpretedAsGeneric {
559 #[label(label_comparison)]
560 pub comparison: Span,
565 pub suggestion: ComparisonOrShiftInterpretedAsGenericSugg,
568 #[derive(Diagnostic)]
569 #[diag(parser_shift_interpreted_as_generic)]
570 pub(crate) struct ShiftInterpretedAsGeneric {
572 #[label(label_comparison)]
578 pub suggestion: ComparisonOrShiftInterpretedAsGenericSugg,
581 #[derive(Subdiagnostic)]
582 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
583 pub(crate) struct ComparisonOrShiftInterpretedAsGenericSugg {
584 #[suggestion_part(code = "(")]
586 #[suggestion_part(code = ")")]
590 #[derive(Diagnostic)]
591 #[diag(parser_found_expr_would_be_stmt)]
592 pub(crate) struct FoundExprWouldBeStmt {
598 pub suggestion: ExprParenthesesNeeded,
601 #[derive(Diagnostic)]
602 #[diag(parser_leading_plus_not_supported)]
603 pub(crate) struct LeadingPlusNotSupported {
608 suggestion_remove_plus,
611 applicability = "machine-applicable"
613 pub remove_plus: Option<Span>,
615 pub add_parentheses: Option<ExprParenthesesNeeded>,
618 #[derive(Diagnostic)]
619 #[diag(parser_parentheses_with_struct_fields)]
620 pub(crate) struct ParenthesesWithStructFields {
625 pub braces_for_struct: BracesForStructLiteral,
627 pub no_fields_for_fn: NoFieldsForFnCall,
630 #[derive(Subdiagnostic)]
631 #[multipart_suggestion(suggestion_braces_for_struct, applicability = "maybe-incorrect")]
632 pub(crate) struct BracesForStructLiteral {
633 #[suggestion_part(code = " {{ ")]
635 #[suggestion_part(code = " }}")]
639 #[derive(Subdiagnostic)]
640 #[multipart_suggestion(suggestion_no_fields_for_fn, applicability = "maybe-incorrect")]
641 pub(crate) struct NoFieldsForFnCall {
642 #[suggestion_part(code = "")]
643 pub fields: Vec<Span>,
646 #[derive(Diagnostic)]
647 #[diag(parser_labeled_loop_in_break)]
648 pub(crate) struct LabeledLoopInBreak {
652 pub sub: WrapExpressionInParentheses,
655 #[derive(Subdiagnostic)]
656 #[multipart_suggestion(
657 parser_sugg_wrap_expression_in_parentheses,
658 applicability = "machine-applicable"
660 pub(crate) struct WrapExpressionInParentheses {
661 #[suggestion_part(code = "(")]
663 #[suggestion_part(code = ")")]
667 #[derive(Diagnostic)]
668 #[diag(parser_array_brackets_instead_of_braces)]
669 pub(crate) struct ArrayBracketsInsteadOfSpaces {
673 pub sub: ArrayBracketsInsteadOfSpacesSugg,
676 #[derive(Subdiagnostic)]
677 #[multipart_suggestion(suggestion, applicability = "maybe-incorrect")]
678 pub(crate) struct ArrayBracketsInsteadOfSpacesSugg {
679 #[suggestion_part(code = "[")]
681 #[suggestion_part(code = "]")]
685 #[derive(Diagnostic)]
686 #[diag(parser_match_arm_body_without_braces)]
687 pub(crate) struct MatchArmBodyWithoutBraces {
689 #[label(label_statements)]
690 pub statements: Span,
691 #[label(label_arrow)]
693 pub num_statements: usize,
695 pub sub: MatchArmBodyWithoutBracesSugg,
698 #[derive(Subdiagnostic)]
699 pub(crate) enum MatchArmBodyWithoutBracesSugg {
700 #[multipart_suggestion(suggestion_add_braces, applicability = "machine-applicable")]
702 #[suggestion_part(code = "{{ ")]
704 #[suggestion_part(code = " }}")]
708 suggestion_use_comma_not_semicolon,
710 applicability = "machine-applicable"
718 #[derive(Diagnostic)]
719 #[diag(parser_struct_literal_not_allowed_here)]
720 pub(crate) struct StructLiteralNotAllowedHere {
724 pub sub: StructLiteralNotAllowedHereSugg,
727 #[derive(Subdiagnostic)]
728 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
729 pub(crate) struct StructLiteralNotAllowedHereSugg {
730 #[suggestion_part(code = "(")]
732 #[suggestion_part(code = ")")]
736 #[derive(Diagnostic)]
737 #[diag(parser_invalid_interpolated_expression)]
738 pub(crate) struct InvalidInterpolatedExpression {
743 #[derive(Diagnostic)]
744 #[diag(parser_hexadecimal_float_literal_not_supported)]
745 pub(crate) struct HexadecimalFloatLiteralNotSupported {
747 #[label(parser_not_supported)]
751 #[derive(Diagnostic)]
752 #[diag(parser_octal_float_literal_not_supported)]
753 pub(crate) struct OctalFloatLiteralNotSupported {
755 #[label(parser_not_supported)]
759 #[derive(Diagnostic)]
760 #[diag(parser_binary_float_literal_not_supported)]
761 pub(crate) struct BinaryFloatLiteralNotSupported {
763 #[label(parser_not_supported)]
767 #[derive(Diagnostic)]
768 #[diag(parser_invalid_literal_suffix)]
769 pub(crate) struct InvalidLiteralSuffix {
778 #[derive(Diagnostic)]
779 #[diag(parser_invalid_literal_suffix_on_tuple_index)]
780 pub(crate) struct InvalidLiteralSuffixOnTupleIndex {
785 #[help(tuple_exception_line_1)]
786 #[help(tuple_exception_line_2)]
787 #[help(tuple_exception_line_3)]
788 pub exception: Option<()>,
791 #[derive(Diagnostic)]
792 #[diag(parser_non_string_abi_literal)]
793 pub(crate) struct NonStringAbiLiteral {
795 #[suggestion(code = "\"C\"", applicability = "maybe-incorrect")]
799 #[derive(Diagnostic)]
800 #[diag(parser_mismatched_closing_delimiter)]
801 pub(crate) struct MismatchedClosingDelimiter {
803 pub spans: Vec<Span>,
804 pub delimiter: String,
805 #[label(label_unmatched)]
807 #[label(label_opening_candidate)]
808 pub opening_candidate: Option<Span>,
809 #[label(label_unclosed)]
810 pub unclosed: Option<Span>,
813 #[derive(Diagnostic)]
814 #[diag(parser_incorrect_visibility_restriction, code = "E0704")]
816 pub(crate) struct IncorrectVisibilityRestriction {
818 #[suggestion(code = "in {inner_str}", applicability = "machine-applicable")]
820 pub inner_str: String,
823 #[derive(Diagnostic)]
824 #[diag(parser_assignment_else_not_allowed)]
825 pub(crate) struct AssignmentElseNotAllowed {
830 #[derive(Diagnostic)]
831 #[diag(parser_expected_statement_after_outer_attr)]
832 pub(crate) struct ExpectedStatementAfterOuterAttr {
837 #[derive(Diagnostic)]
838 #[diag(parser_doc_comment_does_not_document_anything, code = "E0585")]
840 pub(crate) struct DocCommentDoesNotDocumentAnything {
843 #[suggestion(code = ",", applicability = "machine-applicable")]
844 pub missing_comma: Option<Span>,
847 #[derive(Diagnostic)]
848 #[diag(parser_const_let_mutually_exclusive)]
849 pub(crate) struct ConstLetMutuallyExclusive {
851 #[suggestion(code = "const", applicability = "maybe-incorrect")]
855 #[derive(Diagnostic)]
856 #[diag(parser_invalid_expression_in_let_else)]
857 pub(crate) struct InvalidExpressionInLetElse {
860 pub operator: &'static str,
862 pub sugg: WrapExpressionInParentheses,
865 #[derive(Diagnostic)]
866 #[diag(parser_invalid_curly_in_let_else)]
867 pub(crate) struct InvalidCurlyInLetElse {
871 pub sugg: WrapExpressionInParentheses,
874 #[derive(Diagnostic)]
875 #[diag(parser_compound_assignment_expression_in_let)]
877 pub(crate) struct CompoundAssignmentExpressionInLet {
879 #[suggestion(style = "short", code = "=", applicability = "maybe-incorrect")]
883 #[derive(Diagnostic)]
884 #[diag(parser_suffixed_literal_in_attribute)]
886 pub(crate) struct SuffixedLiteralInAttribute {
891 #[derive(Diagnostic)]
892 #[diag(parser_invalid_meta_item)]
893 pub(crate) struct InvalidMetaItem {
899 #[derive(Subdiagnostic)]
901 parser_sugg_escape_to_use_as_identifier,
903 applicability = "maybe-incorrect",
906 pub(crate) struct SuggEscapeToUseAsIdentifier {
909 pub ident_name: String,
912 #[derive(Subdiagnostic)]
913 #[suggestion(parser_sugg_remove_comma, applicability = "machine-applicable", code = "")]
914 pub(crate) struct SuggRemoveComma {
919 #[derive(Subdiagnostic)]
920 pub(crate) enum ExpectedIdentifierFound {
921 #[label(parser_expected_identifier_found_reserved_identifier)]
922 ReservedIdentifier(#[primary_span] Span),
923 #[label(parser_expected_identifier_found_keyword)]
924 Keyword(#[primary_span] Span),
925 #[label(parser_expected_identifier_found_reserved_keyword)]
926 ReservedKeyword(#[primary_span] Span),
927 #[label(parser_expected_identifier_found_doc_comment)]
928 DocComment(#[primary_span] Span),
929 #[label(parser_expected_identifier)]
930 Other(#[primary_span] Span),
933 impl ExpectedIdentifierFound {
934 pub fn new(token_descr: Option<TokenDescription>, span: Span) -> Self {
936 Some(TokenDescription::ReservedIdentifier) => {
937 ExpectedIdentifierFound::ReservedIdentifier
939 Some(TokenDescription::Keyword) => ExpectedIdentifierFound::Keyword,
940 Some(TokenDescription::ReservedKeyword) => ExpectedIdentifierFound::ReservedKeyword,
941 Some(TokenDescription::DocComment) => ExpectedIdentifierFound::DocComment,
942 None => ExpectedIdentifierFound::Other,
947 pub(crate) struct ExpectedIdentifier {
950 pub suggest_raw: Option<SuggEscapeToUseAsIdentifier>,
951 pub suggest_remove_comma: Option<SuggRemoveComma>,
954 impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedIdentifier {
958 handler: &'a rustc_errors::Handler,
959 ) -> rustc_errors::DiagnosticBuilder<'a, G> {
960 let token_descr = super::parser::TokenDescription::from_token(&self.token);
962 let mut diag = handler.struct_diagnostic(match token_descr {
963 Some(TokenDescription::ReservedIdentifier) => {
964 fluent::parser_expected_identifier_found_reserved_identifier_str
966 Some(TokenDescription::Keyword) => fluent::parser_expected_identifier_found_keyword_str,
967 Some(TokenDescription::ReservedKeyword) => {
968 fluent::parser_expected_identifier_found_reserved_keyword_str
970 Some(TokenDescription::DocComment) => {
971 fluent::parser_expected_identifier_found_doc_comment_str
973 None => fluent::parser_expected_identifier_found_str,
975 diag.set_span(self.span);
976 diag.set_arg("token", self.token);
978 if let Some(sugg) = self.suggest_raw {
979 sugg.add_to_diagnostic(&mut diag);
982 ExpectedIdentifierFound::new(token_descr, self.span).add_to_diagnostic(&mut diag);
984 if let Some(sugg) = self.suggest_remove_comma {
985 sugg.add_to_diagnostic(&mut diag);
992 pub(crate) struct ExpectedSemi {
996 pub unexpected_token_label: Option<Span>,
997 pub sugg: ExpectedSemiSugg,
1000 impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedSemi {
1004 handler: &'a rustc_errors::Handler,
1005 ) -> rustc_errors::DiagnosticBuilder<'a, G> {
1006 let token_descr = super::parser::TokenDescription::from_token(&self.token);
1008 let mut diag = handler.struct_diagnostic(match token_descr {
1009 Some(TokenDescription::ReservedIdentifier) => {
1010 fluent::parser_expected_semi_found_reserved_identifier_str
1012 Some(TokenDescription::Keyword) => fluent::parser_expected_semi_found_keyword_str,
1013 Some(TokenDescription::ReservedKeyword) => {
1014 fluent::parser_expected_semi_found_reserved_keyword_str
1016 Some(TokenDescription::DocComment) => {
1017 fluent::parser_expected_semi_found_doc_comment_str
1019 None => fluent::parser_expected_semi_found_str,
1021 diag.set_span(self.span);
1022 diag.set_arg("token", self.token);
1024 if let Some(unexpected_token_label) = self.unexpected_token_label {
1025 diag.span_label(unexpected_token_label, fluent::parser_label_unexpected_token);
1028 self.sugg.add_to_diagnostic(&mut diag);
1034 #[derive(Subdiagnostic)]
1035 pub(crate) enum ExpectedSemiSugg {
1037 parser_sugg_change_this_to_semi,
1039 applicability = "machine-applicable"
1041 ChangeToSemi(#[primary_span] Span),
1043 parser_sugg_add_semi,
1046 applicability = "machine-applicable"
1048 AddSemi(#[primary_span] Span),
1051 #[derive(Diagnostic)]
1052 #[diag(parser_struct_literal_body_without_path)]
1053 pub(crate) struct StructLiteralBodyWithoutPath {
1057 pub sugg: StructLiteralBodyWithoutPathSugg,
1060 #[derive(Subdiagnostic)]
1061 #[multipart_suggestion(suggestion, applicability = "has-placeholders")]
1062 pub(crate) struct StructLiteralBodyWithoutPathSugg {
1063 #[suggestion_part(code = "{{ SomeStruct ")]
1065 #[suggestion_part(code = " }}")]
1069 #[derive(Diagnostic)]
1070 #[diag(parser_unmatched_angle_brackets)]
1071 pub(crate) struct UnmatchedAngleBrackets {
1073 #[suggestion(code = "", applicability = "machine-applicable")]
1075 pub num_extra_brackets: usize,
1078 #[derive(Diagnostic)]
1079 #[diag(parser_generic_parameters_without_angle_brackets)]
1080 pub(crate) struct GenericParamsWithoutAngleBrackets {
1084 pub sugg: GenericParamsWithoutAngleBracketsSugg,
1087 #[derive(Subdiagnostic)]
1088 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1089 pub(crate) struct GenericParamsWithoutAngleBracketsSugg {
1090 #[suggestion_part(code = "<")]
1092 #[suggestion_part(code = ">")]
1096 #[derive(Diagnostic)]
1097 #[diag(parser_comparison_operators_cannot_be_chained)]
1098 pub(crate) struct ComparisonOperatorsCannotBeChained {
1100 pub span: Vec<Span>,
1102 parser_sugg_turbofish_syntax,
1105 applicability = "maybe-incorrect"
1107 pub suggest_turbofish: Option<Span>,
1108 #[help(parser_sugg_turbofish_syntax)]
1109 #[help(sugg_parentheses_for_function_args)]
1110 pub help_turbofish: Option<()>,
1112 pub chaining_sugg: Option<ComparisonOperatorsCannotBeChainedSugg>,
1115 #[derive(Subdiagnostic)]
1116 pub(crate) enum ComparisonOperatorsCannotBeChainedSugg {
1118 sugg_split_comparison,
1120 code = " && {middle_term}",
1121 applicability = "maybe-incorrect"
1126 middle_term: String,
1128 #[multipart_suggestion(sugg_parenthesize, applicability = "maybe-incorrect")]
1130 #[suggestion_part(code = "(")]
1132 #[suggestion_part(code = ")")]
1137 #[derive(Diagnostic)]
1138 #[diag(parser_question_mark_in_type)]
1139 pub(crate) struct QuestionMarkInType {
1144 pub sugg: QuestionMarkInTypeSugg,
1147 #[derive(Subdiagnostic)]
1148 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1149 pub(crate) struct QuestionMarkInTypeSugg {
1150 #[suggestion_part(code = "Option<")]
1152 #[suggestion_part(code = ">")]
1156 #[derive(Diagnostic)]
1157 #[diag(parser_unexpected_parentheses_in_for_head)]
1158 pub(crate) struct ParenthesesInForHead {
1160 pub span: Vec<Span>,
1162 pub sugg: ParenthesesInForHeadSugg,
1165 #[derive(Subdiagnostic)]
1166 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1167 pub(crate) struct ParenthesesInForHeadSugg {
1168 #[suggestion_part(code = "")]
1170 #[suggestion_part(code = "")]
1174 #[derive(Diagnostic)]
1175 #[diag(parser_doc_comment_on_param_type)]
1176 pub(crate) struct DocCommentOnParamType {
1182 #[derive(Diagnostic)]
1183 #[diag(parser_attribute_on_param_type)]
1184 pub(crate) struct AttributeOnParamType {
1190 #[derive(Diagnostic)]
1191 #[diag(parser_pattern_method_param_without_body, code = "E0642")]
1192 pub(crate) struct PatternMethodParamWithoutBody {
1194 #[suggestion(code = "_", applicability = "machine-applicable")]
1198 #[derive(Diagnostic)]
1199 #[diag(parser_self_param_not_first)]
1200 pub(crate) struct SelfParamNotFirst {
1206 #[derive(Diagnostic)]
1207 #[diag(parser_const_generic_without_braces)]
1208 pub(crate) struct ConstGenericWithoutBraces {
1212 pub sugg: ConstGenericWithoutBracesSugg,
1215 #[derive(Subdiagnostic)]
1216 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1217 pub(crate) struct ConstGenericWithoutBracesSugg {
1218 #[suggestion_part(code = "{{ ")]
1220 #[suggestion_part(code = " }}")]
1224 #[derive(Diagnostic)]
1225 #[diag(parser_unexpected_const_param_declaration)]
1226 pub(crate) struct UnexpectedConstParamDeclaration {
1231 pub sugg: Option<UnexpectedConstParamDeclarationSugg>,
1234 #[derive(Subdiagnostic)]
1235 pub(crate) enum UnexpectedConstParamDeclarationSugg {
1236 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1238 #[suggestion_part(code = "<{snippet}>")]
1239 impl_generics: Span,
1240 #[suggestion_part(code = "{ident}")]
1241 incorrect_decl: Span,
1245 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1247 #[suggestion_part(code = ", {snippet}")]
1248 impl_generics_end: Span,
1249 #[suggestion_part(code = "{ident}")]
1250 incorrect_decl: Span,
1256 #[derive(Diagnostic)]
1257 #[diag(parser_unexpected_const_in_generic_param)]
1258 pub(crate) struct UnexpectedConstInGenericParam {
1261 #[suggestion(style = "verbose", code = "", applicability = "maybe-incorrect")]
1262 pub to_remove: Option<Span>,
1265 #[derive(Diagnostic)]
1266 #[diag(parser_async_move_order_incorrect)]
1267 pub(crate) struct AsyncMoveOrderIncorrect {
1269 #[suggestion(style = "verbose", code = "async move", applicability = "maybe-incorrect")]
1273 #[derive(Diagnostic)]
1274 #[diag(parser_double_colon_in_bound)]
1275 pub(crate) struct DoubleColonInBound {
1278 #[suggestion(code = ": ", applicability = "machine-applicable")]