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_verbose(applicability = "maybe-incorrect", code = "..")]
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_expected_else_block)]
425 pub(crate) struct ExpectedElseBlock {
427 pub first_tok_span: Span,
428 pub first_tok: String,
431 #[suggestion(applicability = "maybe-incorrect", code = "if ")]
432 pub condition_start: Span,
435 #[derive(Diagnostic)]
436 #[diag(parser_outer_attribute_not_allowed_on_if_else)]
437 pub(crate) struct OuterAttributeNotAllowedOnIfElse {
441 #[label(branch_label)]
442 pub branch_span: Span,
448 #[suggestion(applicability = "machine-applicable", code = "")]
449 pub attributes: Span,
452 #[derive(Diagnostic)]
453 #[diag(parser_missing_in_in_for_loop)]
454 pub(crate) struct MissingInInForLoop {
458 pub sub: MissingInInForLoopSub,
461 #[derive(Subdiagnostic)]
462 pub(crate) enum MissingInInForLoopSub {
463 // Has been misleading, at least in the past (closed Issue #48492), thus maybe-incorrect
464 #[suggestion(use_in_not_of, style = "short", applicability = "maybe-incorrect", code = "in")]
465 InNotOf(#[primary_span] Span),
466 #[suggestion(add_in, style = "short", applicability = "maybe-incorrect", code = " in ")]
467 AddIn(#[primary_span] Span),
470 #[derive(Diagnostic)]
471 #[diag(parser_missing_comma_after_match_arm)]
472 pub(crate) struct MissingCommaAfterMatchArm {
474 #[suggestion(applicability = "machine-applicable", code = ",")]
478 #[derive(Diagnostic)]
479 #[diag(parser_catch_after_try)]
481 pub(crate) struct CatchAfterTry {
486 #[derive(Diagnostic)]
487 #[diag(parser_comma_after_base_struct)]
489 pub(crate) struct CommaAfterBaseStruct {
492 #[suggestion(style = "short", applicability = "machine-applicable", code = "")]
496 #[derive(Diagnostic)]
497 #[diag(parser_eq_field_init)]
498 pub(crate) struct EqFieldInit {
501 #[suggestion(applicability = "machine-applicable", code = ":")]
505 #[derive(Diagnostic)]
506 #[diag(parser_dotdotdot)]
507 pub(crate) struct DotDotDot {
509 #[suggestion(suggest_exclusive_range, applicability = "maybe-incorrect", code = "..")]
510 #[suggestion(suggest_inclusive_range, applicability = "maybe-incorrect", code = "..=")]
514 #[derive(Diagnostic)]
515 #[diag(parser_left_arrow_operator)]
516 pub(crate) struct LeftArrowOperator {
518 #[suggestion(applicability = "maybe-incorrect", code = "< -")]
522 #[derive(Diagnostic)]
523 #[diag(parser_remove_let)]
524 pub(crate) struct RemoveLet {
526 #[suggestion(applicability = "machine-applicable", code = "")]
530 #[derive(Diagnostic)]
531 #[diag(parser_use_eq_instead)]
532 pub(crate) struct UseEqInstead {
534 #[suggestion(style = "short", applicability = "machine-applicable", code = "=")]
538 #[derive(Diagnostic)]
539 #[diag(parser_use_empty_block_not_semi)]
540 pub(crate) struct UseEmptyBlockNotSemi {
542 #[suggestion(style = "hidden", applicability = "machine-applicable", code = "{{}}")]
546 #[derive(Diagnostic)]
547 #[diag(parser_comparison_interpreted_as_generic)]
548 pub(crate) struct ComparisonInterpretedAsGeneric {
550 #[label(label_comparison)]
551 pub comparison: Span,
556 pub suggestion: ComparisonOrShiftInterpretedAsGenericSugg,
559 #[derive(Diagnostic)]
560 #[diag(parser_shift_interpreted_as_generic)]
561 pub(crate) struct ShiftInterpretedAsGeneric {
563 #[label(label_comparison)]
569 pub suggestion: ComparisonOrShiftInterpretedAsGenericSugg,
572 #[derive(Subdiagnostic)]
573 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
574 pub(crate) struct ComparisonOrShiftInterpretedAsGenericSugg {
575 #[suggestion_part(code = "(")]
577 #[suggestion_part(code = ")")]
581 #[derive(Diagnostic)]
582 #[diag(parser_found_expr_would_be_stmt)]
583 pub(crate) struct FoundExprWouldBeStmt {
589 pub suggestion: ExprParenthesesNeeded,
592 #[derive(Diagnostic)]
593 #[diag(parser_leading_plus_not_supported)]
594 pub(crate) struct LeadingPlusNotSupported {
599 suggestion_remove_plus,
602 applicability = "machine-applicable"
604 pub remove_plus: Option<Span>,
606 pub add_parentheses: Option<ExprParenthesesNeeded>,
609 #[derive(Diagnostic)]
610 #[diag(parser_parentheses_with_struct_fields)]
611 pub(crate) struct ParenthesesWithStructFields {
616 pub braces_for_struct: BracesForStructLiteral,
618 pub no_fields_for_fn: NoFieldsForFnCall,
621 #[derive(Subdiagnostic)]
622 #[multipart_suggestion(suggestion_braces_for_struct, applicability = "maybe-incorrect")]
623 pub(crate) struct BracesForStructLiteral {
624 #[suggestion_part(code = " {{ ")]
626 #[suggestion_part(code = " }}")]
630 #[derive(Subdiagnostic)]
631 #[multipart_suggestion(suggestion_no_fields_for_fn, applicability = "maybe-incorrect")]
632 pub(crate) struct NoFieldsForFnCall {
633 #[suggestion_part(code = "")]
634 pub fields: Vec<Span>,
637 #[derive(Diagnostic)]
638 #[diag(parser_labeled_loop_in_break)]
639 pub(crate) struct LabeledLoopInBreak {
643 pub sub: WrapExpressionInParentheses,
646 #[derive(Subdiagnostic)]
647 #[multipart_suggestion(
648 parser_sugg_wrap_expression_in_parentheses,
649 applicability = "machine-applicable"
651 pub(crate) struct WrapExpressionInParentheses {
652 #[suggestion_part(code = "(")]
654 #[suggestion_part(code = ")")]
658 #[derive(Diagnostic)]
659 #[diag(parser_array_brackets_instead_of_braces)]
660 pub(crate) struct ArrayBracketsInsteadOfSpaces {
664 pub sub: ArrayBracketsInsteadOfSpacesSugg,
667 #[derive(Subdiagnostic)]
668 #[multipart_suggestion(suggestion, applicability = "maybe-incorrect")]
669 pub(crate) struct ArrayBracketsInsteadOfSpacesSugg {
670 #[suggestion_part(code = "[")]
672 #[suggestion_part(code = "]")]
676 #[derive(Diagnostic)]
677 #[diag(parser_match_arm_body_without_braces)]
678 pub(crate) struct MatchArmBodyWithoutBraces {
680 #[label(label_statements)]
681 pub statements: Span,
682 #[label(label_arrow)]
684 pub num_statements: usize,
686 pub sub: MatchArmBodyWithoutBracesSugg,
689 #[derive(Subdiagnostic)]
690 pub(crate) enum MatchArmBodyWithoutBracesSugg {
691 #[multipart_suggestion(suggestion_add_braces, applicability = "machine-applicable")]
693 #[suggestion_part(code = "{{ ")]
695 #[suggestion_part(code = " }}")]
699 suggestion_use_comma_not_semicolon,
701 applicability = "machine-applicable"
709 #[derive(Diagnostic)]
710 #[diag(parser_struct_literal_not_allowed_here)]
711 pub(crate) struct StructLiteralNotAllowedHere {
715 pub sub: StructLiteralNotAllowedHereSugg,
718 #[derive(Subdiagnostic)]
719 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
720 pub(crate) struct StructLiteralNotAllowedHereSugg {
721 #[suggestion_part(code = "(")]
723 #[suggestion_part(code = ")")]
727 #[derive(Diagnostic)]
728 #[diag(parser_invalid_interpolated_expression)]
729 pub(crate) struct InvalidInterpolatedExpression {
734 #[derive(Diagnostic)]
735 #[diag(parser_hexadecimal_float_literal_not_supported)]
736 pub(crate) struct HexadecimalFloatLiteralNotSupported {
738 #[label(parser_not_supported)]
742 #[derive(Diagnostic)]
743 #[diag(parser_octal_float_literal_not_supported)]
744 pub(crate) struct OctalFloatLiteralNotSupported {
746 #[label(parser_not_supported)]
750 #[derive(Diagnostic)]
751 #[diag(parser_binary_float_literal_not_supported)]
752 pub(crate) struct BinaryFloatLiteralNotSupported {
754 #[label(parser_not_supported)]
758 #[derive(Diagnostic)]
759 #[diag(parser_invalid_literal_suffix)]
760 pub(crate) struct InvalidLiteralSuffix {
769 #[derive(Diagnostic)]
770 #[diag(parser_invalid_literal_suffix_on_tuple_index)]
771 pub(crate) struct InvalidLiteralSuffixOnTupleIndex {
776 #[help(tuple_exception_line_1)]
777 #[help(tuple_exception_line_2)]
778 #[help(tuple_exception_line_3)]
779 pub exception: Option<()>,
782 #[derive(Diagnostic)]
783 #[diag(parser_non_string_abi_literal)]
784 pub(crate) struct NonStringAbiLiteral {
786 #[suggestion(code = "\"C\"", applicability = "maybe-incorrect")]
790 #[derive(Diagnostic)]
791 #[diag(parser_mismatched_closing_delimiter)]
792 pub(crate) struct MismatchedClosingDelimiter {
794 pub spans: Vec<Span>,
795 pub delimiter: String,
796 #[label(label_unmatched)]
798 #[label(label_opening_candidate)]
799 pub opening_candidate: Option<Span>,
800 #[label(label_unclosed)]
801 pub unclosed: Option<Span>,
804 #[derive(Diagnostic)]
805 #[diag(parser_incorrect_visibility_restriction, code = "E0704")]
807 pub(crate) struct IncorrectVisibilityRestriction {
809 #[suggestion(code = "in {inner_str}", applicability = "machine-applicable")]
811 pub inner_str: String,
814 #[derive(Diagnostic)]
815 #[diag(parser_assignment_else_not_allowed)]
816 pub(crate) struct AssignmentElseNotAllowed {
821 #[derive(Diagnostic)]
822 #[diag(parser_expected_statement_after_outer_attr)]
823 pub(crate) struct ExpectedStatementAfterOuterAttr {
828 #[derive(Diagnostic)]
829 #[diag(parser_doc_comment_does_not_document_anything, code = "E0585")]
831 pub(crate) struct DocCommentDoesNotDocumentAnything {
834 #[suggestion(code = ",", applicability = "machine-applicable")]
835 pub missing_comma: Option<Span>,
838 #[derive(Diagnostic)]
839 #[diag(parser_const_let_mutually_exclusive)]
840 pub(crate) struct ConstLetMutuallyExclusive {
842 #[suggestion(code = "const", applicability = "maybe-incorrect")]
846 #[derive(Diagnostic)]
847 #[diag(parser_invalid_expression_in_let_else)]
848 pub(crate) struct InvalidExpressionInLetElse {
851 pub operator: &'static str,
853 pub sugg: WrapExpressionInParentheses,
856 #[derive(Diagnostic)]
857 #[diag(parser_invalid_curly_in_let_else)]
858 pub(crate) struct InvalidCurlyInLetElse {
862 pub sugg: WrapExpressionInParentheses,
865 #[derive(Diagnostic)]
866 #[diag(parser_compound_assignment_expression_in_let)]
868 pub(crate) struct CompoundAssignmentExpressionInLet {
870 #[suggestion(style = "short", code = "=", applicability = "maybe-incorrect")]
874 #[derive(Diagnostic)]
875 #[diag(parser_suffixed_literal_in_attribute)]
877 pub(crate) struct SuffixedLiteralInAttribute {
882 #[derive(Diagnostic)]
883 #[diag(parser_invalid_meta_item)]
884 pub(crate) struct InvalidMetaItem {
890 #[derive(Subdiagnostic)]
892 parser_sugg_escape_to_use_as_identifier,
894 applicability = "maybe-incorrect",
897 pub(crate) struct SuggEscapeToUseAsIdentifier {
900 pub ident_name: String,
903 #[derive(Subdiagnostic)]
904 #[suggestion(parser_sugg_remove_comma, applicability = "machine-applicable", code = "")]
905 pub(crate) struct SuggRemoveComma {
910 #[derive(Subdiagnostic)]
911 pub(crate) enum ExpectedIdentifierFound {
912 #[label(parser_expected_identifier_found_reserved_identifier)]
913 ReservedIdentifier(#[primary_span] Span),
914 #[label(parser_expected_identifier_found_keyword)]
915 Keyword(#[primary_span] Span),
916 #[label(parser_expected_identifier_found_reserved_keyword)]
917 ReservedKeyword(#[primary_span] Span),
918 #[label(parser_expected_identifier_found_doc_comment)]
919 DocComment(#[primary_span] Span),
920 #[label(parser_expected_identifier)]
921 Other(#[primary_span] Span),
924 impl ExpectedIdentifierFound {
925 pub fn new(token_descr: Option<TokenDescription>, span: Span) -> Self {
927 Some(TokenDescription::ReservedIdentifier) => {
928 ExpectedIdentifierFound::ReservedIdentifier
930 Some(TokenDescription::Keyword) => ExpectedIdentifierFound::Keyword,
931 Some(TokenDescription::ReservedKeyword) => ExpectedIdentifierFound::ReservedKeyword,
932 Some(TokenDescription::DocComment) => ExpectedIdentifierFound::DocComment,
933 None => ExpectedIdentifierFound::Other,
938 pub(crate) struct ExpectedIdentifier {
941 pub suggest_raw: Option<SuggEscapeToUseAsIdentifier>,
942 pub suggest_remove_comma: Option<SuggRemoveComma>,
945 impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedIdentifier {
949 handler: &'a rustc_errors::Handler,
950 ) -> rustc_errors::DiagnosticBuilder<'a, G> {
951 let token_descr = super::parser::TokenDescription::from_token(&self.token);
953 let mut diag = handler.struct_diagnostic(match token_descr {
954 Some(TokenDescription::ReservedIdentifier) => {
955 fluent::parser_expected_identifier_found_reserved_identifier_str
957 Some(TokenDescription::Keyword) => fluent::parser_expected_identifier_found_keyword_str,
958 Some(TokenDescription::ReservedKeyword) => {
959 fluent::parser_expected_identifier_found_reserved_keyword_str
961 Some(TokenDescription::DocComment) => {
962 fluent::parser_expected_identifier_found_doc_comment_str
964 None => fluent::parser_expected_identifier_found_str,
966 diag.set_span(self.span);
967 diag.set_arg("token", self.token);
969 if let Some(sugg) = self.suggest_raw {
970 sugg.add_to_diagnostic(&mut diag);
973 ExpectedIdentifierFound::new(token_descr, self.span).add_to_diagnostic(&mut diag);
975 if let Some(sugg) = self.suggest_remove_comma {
976 sugg.add_to_diagnostic(&mut diag);
983 pub(crate) struct ExpectedSemi {
987 pub unexpected_token_label: Option<Span>,
988 pub sugg: ExpectedSemiSugg,
991 impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedSemi {
995 handler: &'a rustc_errors::Handler,
996 ) -> rustc_errors::DiagnosticBuilder<'a, G> {
997 let token_descr = super::parser::TokenDescription::from_token(&self.token);
999 let mut diag = handler.struct_diagnostic(match token_descr {
1000 Some(TokenDescription::ReservedIdentifier) => {
1001 fluent::parser_expected_semi_found_reserved_identifier_str
1003 Some(TokenDescription::Keyword) => fluent::parser_expected_semi_found_keyword_str,
1004 Some(TokenDescription::ReservedKeyword) => {
1005 fluent::parser_expected_semi_found_reserved_keyword_str
1007 Some(TokenDescription::DocComment) => {
1008 fluent::parser_expected_semi_found_doc_comment_str
1010 None => fluent::parser_expected_semi_found_str,
1012 diag.set_span(self.span);
1013 diag.set_arg("token", self.token);
1015 if let Some(unexpected_token_label) = self.unexpected_token_label {
1016 diag.span_label(unexpected_token_label, fluent::parser_label_unexpected_token);
1019 self.sugg.add_to_diagnostic(&mut diag);
1025 #[derive(Subdiagnostic)]
1026 pub(crate) enum ExpectedSemiSugg {
1028 parser_sugg_change_this_to_semi,
1030 applicability = "machine-applicable"
1032 ChangeToSemi(#[primary_span] Span),
1034 parser_sugg_add_semi,
1037 applicability = "machine-applicable"
1039 AddSemi(#[primary_span] Span),
1042 #[derive(Diagnostic)]
1043 #[diag(parser_struct_literal_body_without_path)]
1044 pub(crate) struct StructLiteralBodyWithoutPath {
1048 pub sugg: StructLiteralBodyWithoutPathSugg,
1051 #[derive(Subdiagnostic)]
1052 #[multipart_suggestion(suggestion, applicability = "has-placeholders")]
1053 pub(crate) struct StructLiteralBodyWithoutPathSugg {
1054 #[suggestion_part(code = "{{ SomeStruct ")]
1056 #[suggestion_part(code = " }}")]
1060 #[derive(Diagnostic)]
1061 #[diag(parser_unmatched_angle_brackets)]
1062 pub(crate) struct UnmatchedAngleBrackets {
1064 #[suggestion(code = "", applicability = "machine-applicable")]
1066 pub num_extra_brackets: usize,
1069 #[derive(Diagnostic)]
1070 #[diag(parser_generic_parameters_without_angle_brackets)]
1071 pub(crate) struct GenericParamsWithoutAngleBrackets {
1075 pub sugg: GenericParamsWithoutAngleBracketsSugg,
1078 #[derive(Subdiagnostic)]
1079 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1080 pub(crate) struct GenericParamsWithoutAngleBracketsSugg {
1081 #[suggestion_part(code = "<")]
1083 #[suggestion_part(code = ">")]
1087 #[derive(Diagnostic)]
1088 #[diag(parser_comparison_operators_cannot_be_chained)]
1089 pub(crate) struct ComparisonOperatorsCannotBeChained {
1091 pub span: Vec<Span>,
1093 parser_sugg_turbofish_syntax,
1096 applicability = "maybe-incorrect"
1098 pub suggest_turbofish: Option<Span>,
1099 #[help(parser_sugg_turbofish_syntax)]
1100 #[help(sugg_parentheses_for_function_args)]
1101 pub help_turbofish: Option<()>,
1103 pub chaining_sugg: Option<ComparisonOperatorsCannotBeChainedSugg>,
1106 #[derive(Subdiagnostic)]
1107 pub(crate) enum ComparisonOperatorsCannotBeChainedSugg {
1109 sugg_split_comparison,
1111 code = " && {middle_term}",
1112 applicability = "maybe-incorrect"
1117 middle_term: String,
1119 #[multipart_suggestion(sugg_parenthesize, applicability = "maybe-incorrect")]
1121 #[suggestion_part(code = "(")]
1123 #[suggestion_part(code = ")")]
1128 #[derive(Diagnostic)]
1129 #[diag(parser_question_mark_in_type)]
1130 pub(crate) struct QuestionMarkInType {
1135 pub sugg: QuestionMarkInTypeSugg,
1138 #[derive(Subdiagnostic)]
1139 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1140 pub(crate) struct QuestionMarkInTypeSugg {
1141 #[suggestion_part(code = "Option<")]
1143 #[suggestion_part(code = ">")]
1147 #[derive(Diagnostic)]
1148 #[diag(parser_unexpected_parentheses_in_for_head)]
1149 pub(crate) struct ParenthesesInForHead {
1151 pub span: Vec<Span>,
1153 pub sugg: ParenthesesInForHeadSugg,
1156 #[derive(Subdiagnostic)]
1157 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1158 pub(crate) struct ParenthesesInForHeadSugg {
1159 #[suggestion_part(code = "")]
1161 #[suggestion_part(code = "")]
1165 #[derive(Diagnostic)]
1166 #[diag(parser_doc_comment_on_param_type)]
1167 pub(crate) struct DocCommentOnParamType {
1173 #[derive(Diagnostic)]
1174 #[diag(parser_attribute_on_param_type)]
1175 pub(crate) struct AttributeOnParamType {
1181 #[derive(Diagnostic)]
1182 #[diag(parser_pattern_method_param_without_body, code = "E0642")]
1183 pub(crate) struct PatternMethodParamWithoutBody {
1185 #[suggestion(code = "_", applicability = "machine-applicable")]
1189 #[derive(Diagnostic)]
1190 #[diag(parser_self_param_not_first)]
1191 pub(crate) struct SelfParamNotFirst {
1197 #[derive(Diagnostic)]
1198 #[diag(parser_const_generic_without_braces)]
1199 pub(crate) struct ConstGenericWithoutBraces {
1203 pub sugg: ConstGenericWithoutBracesSugg,
1206 #[derive(Subdiagnostic)]
1207 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1208 pub(crate) struct ConstGenericWithoutBracesSugg {
1209 #[suggestion_part(code = "{{ ")]
1211 #[suggestion_part(code = " }}")]
1215 #[derive(Diagnostic)]
1216 #[diag(parser_unexpected_const_param_declaration)]
1217 pub(crate) struct UnexpectedConstParamDeclaration {
1222 pub sugg: Option<UnexpectedConstParamDeclarationSugg>,
1225 #[derive(Subdiagnostic)]
1226 pub(crate) enum UnexpectedConstParamDeclarationSugg {
1227 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1229 #[suggestion_part(code = "<{snippet}>")]
1230 impl_generics: Span,
1231 #[suggestion_part(code = "{ident}")]
1232 incorrect_decl: Span,
1236 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1238 #[suggestion_part(code = ", {snippet}")]
1239 impl_generics_end: Span,
1240 #[suggestion_part(code = "{ident}")]
1241 incorrect_decl: Span,
1247 #[derive(Diagnostic)]
1248 #[diag(parser_unexpected_const_in_generic_param)]
1249 pub(crate) struct UnexpectedConstInGenericParam {
1252 #[suggestion(style = "verbose", code = "", applicability = "maybe-incorrect")]
1253 pub to_remove: Option<Span>,
1256 #[derive(Diagnostic)]
1257 #[diag(parser_async_move_order_incorrect)]
1258 pub(crate) struct AsyncMoveOrderIncorrect {
1260 #[suggestion(style = "verbose", code = "async move", applicability = "maybe-incorrect")]
1264 #[derive(Diagnostic)]
1265 #[diag(parser_double_colon_in_bound)]
1266 pub(crate) struct DoubleColonInBound {
1269 #[suggestion(code = ": ", applicability = "machine-applicable")]