3 use rustc_ast::token::Token;
4 use rustc_ast::{Path, Visibility};
5 use rustc_errors::{fluent, AddToDiagnostic, Applicability, EmissionGuarantee, IntoDiagnostic};
6 use rustc_macros::{Diagnostic, Subdiagnostic};
7 use rustc_session::errors::ExprParenthesesNeeded;
8 use rustc_span::edition::{Edition, LATEST_STABLE_EDITION};
9 use rustc_span::symbol::Ident;
10 use rustc_span::{Span, Symbol};
12 use crate::parser::TokenDescription;
15 #[diag(parse_maybe_report_ambiguous_plus)]
16 pub(crate) struct AmbiguousPlus {
19 #[suggestion(code = "({sum_ty})")]
24 #[diag(parse_maybe_recover_from_bad_type_plus, code = "E0178")]
25 pub(crate) struct BadTypePlus {
30 pub sub: BadTypePlusSub,
33 #[derive(Subdiagnostic)]
34 pub(crate) enum BadTypePlusSub {
37 code = "{sum_with_parens}",
38 applicability = "machine-applicable"
41 sum_with_parens: String,
45 #[label(parse_forgot_paren)]
50 #[label(parse_expect_path)]
58 #[diag(parse_maybe_recover_from_bad_qpath_stage_2)]
59 pub(crate) struct BadQPathStage2 {
61 #[suggestion(code = "", applicability = "maybe-incorrect")]
67 #[diag(parse_incorrect_semicolon)]
68 pub(crate) struct IncorrectSemicolon<'a> {
70 #[suggestion(style = "short", code = "", applicability = "machine-applicable")]
73 pub opt_help: Option<()>,
78 #[diag(parse_incorrect_use_of_await)]
79 pub(crate) struct IncorrectUseOfAwait {
81 #[suggestion(parentheses_suggestion, code = "", applicability = "machine-applicable")]
86 #[diag(parse_incorrect_use_of_await)]
87 pub(crate) struct IncorrectAwait {
90 #[suggestion(postfix_suggestion, code = "{expr}.await{question_mark}")]
91 pub sugg_span: (Span, Applicability),
93 pub question_mark: &'static str,
97 #[diag(parse_in_in_typo)]
98 pub(crate) struct InInTypo {
101 #[suggestion(code = "", applicability = "machine-applicable")]
105 #[derive(Diagnostic)]
106 #[diag(parse_invalid_variable_declaration)]
107 pub(crate) struct InvalidVariableDeclaration {
111 pub sub: InvalidVariableDeclarationSub,
114 #[derive(Subdiagnostic)]
115 pub(crate) enum InvalidVariableDeclarationSub {
116 #[suggestion(parse_switch_mut_let_order, applicability = "maybe-incorrect", code = "let mut")]
117 SwitchMutLetOrder(#[primary_span] Span),
119 parse_missing_let_before_mut,
120 applicability = "machine-applicable",
123 MissingLet(#[primary_span] Span),
124 #[suggestion(parse_use_let_not_auto, applicability = "machine-applicable", code = "let")]
125 UseLetNotAuto(#[primary_span] Span),
126 #[suggestion(parse_use_let_not_var, applicability = "machine-applicable", code = "let")]
127 UseLetNotVar(#[primary_span] Span),
130 #[derive(Diagnostic)]
131 #[diag(parse_invalid_comparison_operator)]
132 pub(crate) struct InvalidComparisonOperator {
137 pub sub: InvalidComparisonOperatorSub,
140 #[derive(Subdiagnostic)]
141 pub(crate) enum InvalidComparisonOperatorSub {
145 applicability = "machine-applicable",
154 #[label(spaceship_operator_invalid)]
155 Spaceship(#[primary_span] Span),
158 #[derive(Diagnostic)]
159 #[diag(parse_invalid_logical_operator)]
161 pub(crate) struct InvalidLogicalOperator {
164 pub incorrect: String,
166 pub sub: InvalidLogicalOperatorSub,
169 #[derive(Subdiagnostic)]
170 pub(crate) enum InvalidLogicalOperatorSub {
172 use_amp_amp_for_conjunction,
174 applicability = "machine-applicable",
177 Conjunction(#[primary_span] Span),
179 use_pipe_pipe_for_disjunction,
181 applicability = "machine-applicable",
184 Disjunction(#[primary_span] Span),
187 #[derive(Diagnostic)]
188 #[diag(parse_tilde_is_not_unary_operator)]
189 pub(crate) struct TildeAsUnaryOperator(
191 #[suggestion(style = "short", applicability = "machine-applicable", code = "!")]
195 #[derive(Diagnostic)]
196 #[diag(parse_unexpected_token_after_not)]
197 pub(crate) struct NotAsNegationOperator {
200 pub negated_desc: String,
202 pub sub: NotAsNegationOperatorSub,
205 #[derive(Subdiagnostic)]
206 pub enum NotAsNegationOperatorSub {
208 parse_unexpected_token_after_not_default,
210 applicability = "machine-applicable",
213 SuggestNotDefault(#[primary_span] Span),
216 parse_unexpected_token_after_not_bitwise,
218 applicability = "machine-applicable",
221 SuggestNotBitwise(#[primary_span] Span),
224 parse_unexpected_token_after_not_logical,
226 applicability = "machine-applicable",
229 SuggestNotLogical(#[primary_span] Span),
232 #[derive(Diagnostic)]
233 #[diag(parse_malformed_loop_label)]
234 pub(crate) struct MalformedLoopLabel {
236 #[suggestion(applicability = "machine-applicable", code = "{correct_label}")]
238 pub correct_label: Ident,
241 #[derive(Diagnostic)]
242 #[diag(parse_lifetime_in_borrow_expression)]
243 pub(crate) struct LifetimeInBorrowExpression {
246 #[suggestion(applicability = "machine-applicable", code = "")]
248 pub lifetime_span: Span,
251 #[derive(Diagnostic)]
252 #[diag(parse_field_expression_with_generic)]
253 pub(crate) struct FieldExpressionWithGeneric(#[primary_span] pub Span);
255 #[derive(Diagnostic)]
256 #[diag(parse_macro_invocation_with_qualified_path)]
257 pub(crate) struct MacroInvocationWithQualifiedPath(#[primary_span] pub Span);
259 #[derive(Diagnostic)]
260 #[diag(parse_unexpected_token_after_label)]
261 pub(crate) struct UnexpectedTokenAfterLabel {
263 #[label(parse_unexpected_token_after_label)]
265 #[suggestion(suggestion_remove_label, style = "verbose", code = "")]
266 pub remove_label: Option<Span>,
268 pub enclose_in_block: Option<UnexpectedTokenAfterLabelSugg>,
271 #[derive(Subdiagnostic)]
272 #[multipart_suggestion(suggestion_enclose_in_block, applicability = "machine-applicable")]
273 pub(crate) struct UnexpectedTokenAfterLabelSugg {
274 #[suggestion_part(code = "{{ ")]
276 #[suggestion_part(code = " }}")]
280 #[derive(Diagnostic)]
281 #[diag(parse_require_colon_after_labeled_expression)]
283 pub(crate) struct RequireColonAfterLabeledExpression {
288 #[suggestion(style = "short", applicability = "machine-applicable", code = ": ")]
292 #[derive(Diagnostic)]
293 #[diag(parse_do_catch_syntax_removed)]
295 pub(crate) struct DoCatchSyntaxRemoved {
297 #[suggestion(applicability = "machine-applicable", code = "try")]
301 #[derive(Diagnostic)]
302 #[diag(parse_float_literal_requires_integer_part)]
303 pub(crate) struct FloatLiteralRequiresIntegerPart {
305 #[suggestion(applicability = "machine-applicable", code = "{correct}")]
310 #[derive(Diagnostic)]
311 #[diag(parse_missing_semicolon_before_array)]
312 pub(crate) struct MissingSemicolonBeforeArray {
314 pub open_delim: Span,
315 #[suggestion(style = "verbose", applicability = "maybe-incorrect", code = ";")]
319 #[derive(Diagnostic)]
320 #[diag(parse_expect_dotdot_not_dotdotdot)]
321 pub(crate) struct MissingDotDot {
323 pub token_span: Span,
324 #[suggestion(applicability = "maybe-incorrect", code = "..", style = "verbose")]
328 #[derive(Diagnostic)]
329 #[diag(parse_invalid_block_macro_segment)]
330 pub(crate) struct InvalidBlockMacroSegment {
337 #[derive(Diagnostic)]
338 #[diag(parse_if_expression_missing_then_block)]
339 pub(crate) struct IfExpressionMissingThenBlock {
343 pub missing_then_block_sub: IfExpressionMissingThenBlockSub,
345 pub let_else_sub: Option<IfExpressionLetSomeSub>,
348 #[derive(Subdiagnostic)]
349 pub(crate) enum IfExpressionMissingThenBlockSub {
350 #[help(condition_possibly_unfinished)]
351 UnfinishedCondition(#[primary_span] Span),
352 #[help(add_then_block)]
353 AddThenBlock(#[primary_span] Span),
356 #[derive(Subdiagnostic)]
357 #[suggestion(parse_extra_if_in_let_else, applicability = "maybe-incorrect", code = "")]
358 pub(crate) struct IfExpressionLetSomeSub {
363 #[derive(Diagnostic)]
364 #[diag(parse_if_expression_missing_condition)]
365 pub(crate) struct IfExpressionMissingCondition {
367 #[label(condition_label)]
369 #[label(block_label)]
370 pub block_span: Span,
373 #[derive(Diagnostic)]
374 #[diag(parse_expected_expression_found_let)]
375 pub(crate) struct ExpectedExpressionFoundLet {
380 #[derive(Diagnostic)]
381 #[diag(parse_expect_eq_instead_of_eqeq)]
382 pub(crate) struct ExpectedEqForLetExpr {
385 #[suggestion(applicability = "maybe-incorrect", code = "=", style = "verbose")]
389 #[derive(Diagnostic)]
390 #[diag(parse_expected_else_block)]
391 pub(crate) struct ExpectedElseBlock {
393 pub first_tok_span: Span,
394 pub first_tok: String,
397 #[suggestion(applicability = "maybe-incorrect", code = "if ")]
398 pub condition_start: Span,
401 #[derive(Diagnostic)]
402 #[diag(parse_outer_attribute_not_allowed_on_if_else)]
403 pub(crate) struct OuterAttributeNotAllowedOnIfElse {
407 #[label(branch_label)]
408 pub branch_span: Span,
414 #[suggestion(applicability = "machine-applicable", code = "")]
415 pub attributes: Span,
418 #[derive(Diagnostic)]
419 #[diag(parse_missing_in_in_for_loop)]
420 pub(crate) struct MissingInInForLoop {
424 pub sub: MissingInInForLoopSub,
427 #[derive(Subdiagnostic)]
428 pub(crate) enum MissingInInForLoopSub {
429 // Has been misleading, at least in the past (closed Issue #48492), thus maybe-incorrect
430 #[suggestion(use_in_not_of, style = "short", applicability = "maybe-incorrect", code = "in")]
431 InNotOf(#[primary_span] Span),
432 #[suggestion(add_in, style = "short", applicability = "maybe-incorrect", code = " in ")]
433 AddIn(#[primary_span] Span),
436 #[derive(Diagnostic)]
437 #[diag(parse_missing_expression_in_for_loop)]
438 pub(crate) struct MissingExpressionInForLoop {
441 code = "/* expression */ ",
442 applicability = "has-placeholders",
448 #[derive(Diagnostic)]
449 #[diag(parse_missing_comma_after_match_arm)]
450 pub(crate) struct MissingCommaAfterMatchArm {
452 #[suggestion(applicability = "machine-applicable", code = ",")]
456 #[derive(Diagnostic)]
457 #[diag(parse_catch_after_try)]
459 pub(crate) struct CatchAfterTry {
464 #[derive(Diagnostic)]
465 #[diag(parse_comma_after_base_struct)]
467 pub(crate) struct CommaAfterBaseStruct {
470 #[suggestion(style = "short", applicability = "machine-applicable", code = "")]
474 #[derive(Diagnostic)]
475 #[diag(parse_eq_field_init)]
476 pub(crate) struct EqFieldInit {
479 #[suggestion(applicability = "machine-applicable", code = ":")]
483 #[derive(Diagnostic)]
484 #[diag(parse_dotdotdot)]
485 pub(crate) struct DotDotDot {
487 #[suggestion(suggest_exclusive_range, applicability = "maybe-incorrect", code = "..")]
488 #[suggestion(suggest_inclusive_range, applicability = "maybe-incorrect", code = "..=")]
492 #[derive(Diagnostic)]
493 #[diag(parse_left_arrow_operator)]
494 pub(crate) struct LeftArrowOperator {
496 #[suggestion(applicability = "maybe-incorrect", code = "< -")]
500 #[derive(Diagnostic)]
501 #[diag(parse_remove_let)]
502 pub(crate) struct RemoveLet {
504 #[suggestion(applicability = "machine-applicable", code = "")]
508 #[derive(Diagnostic)]
509 #[diag(parse_use_eq_instead)]
510 pub(crate) struct UseEqInstead {
512 #[suggestion(style = "short", applicability = "machine-applicable", code = "=")]
516 #[derive(Diagnostic)]
517 #[diag(parse_use_empty_block_not_semi)]
518 pub(crate) struct UseEmptyBlockNotSemi {
520 #[suggestion(style = "hidden", applicability = "machine-applicable", code = "{{}}")]
524 #[derive(Diagnostic)]
525 #[diag(parse_comparison_interpreted_as_generic)]
526 pub(crate) struct ComparisonInterpretedAsGeneric {
528 #[label(label_comparison)]
529 pub comparison: Span,
534 pub suggestion: ComparisonOrShiftInterpretedAsGenericSugg,
537 #[derive(Diagnostic)]
538 #[diag(parse_shift_interpreted_as_generic)]
539 pub(crate) struct ShiftInterpretedAsGeneric {
541 #[label(label_comparison)]
547 pub suggestion: ComparisonOrShiftInterpretedAsGenericSugg,
550 #[derive(Subdiagnostic)]
551 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
552 pub(crate) struct ComparisonOrShiftInterpretedAsGenericSugg {
553 #[suggestion_part(code = "(")]
555 #[suggestion_part(code = ")")]
559 #[derive(Diagnostic)]
560 #[diag(parse_found_expr_would_be_stmt)]
561 pub(crate) struct FoundExprWouldBeStmt {
567 pub suggestion: ExprParenthesesNeeded,
570 #[derive(Diagnostic)]
571 #[diag(parse_leading_plus_not_supported)]
572 pub(crate) struct LeadingPlusNotSupported {
577 suggestion_remove_plus,
580 applicability = "machine-applicable"
582 pub remove_plus: Option<Span>,
584 pub add_parentheses: Option<ExprParenthesesNeeded>,
587 #[derive(Diagnostic)]
588 #[diag(parse_parentheses_with_struct_fields)]
589 pub(crate) struct ParenthesesWithStructFields {
594 pub braces_for_struct: BracesForStructLiteral,
596 pub no_fields_for_fn: NoFieldsForFnCall,
599 #[derive(Subdiagnostic)]
600 #[multipart_suggestion(suggestion_braces_for_struct, applicability = "maybe-incorrect")]
601 pub(crate) struct BracesForStructLiteral {
602 #[suggestion_part(code = " {{ ")]
604 #[suggestion_part(code = " }}")]
608 #[derive(Subdiagnostic)]
609 #[multipart_suggestion(suggestion_no_fields_for_fn, applicability = "maybe-incorrect")]
610 pub(crate) struct NoFieldsForFnCall {
611 #[suggestion_part(code = "")]
612 pub fields: Vec<Span>,
615 #[derive(Diagnostic)]
616 #[diag(parse_labeled_loop_in_break)]
617 pub(crate) struct LabeledLoopInBreak {
621 pub sub: WrapExpressionInParentheses,
624 #[derive(Subdiagnostic)]
625 #[multipart_suggestion(
626 parse_sugg_wrap_expression_in_parentheses,
627 applicability = "machine-applicable"
629 pub(crate) struct WrapExpressionInParentheses {
630 #[suggestion_part(code = "(")]
632 #[suggestion_part(code = ")")]
636 #[derive(Diagnostic)]
637 #[diag(parse_array_brackets_instead_of_braces)]
638 pub(crate) struct ArrayBracketsInsteadOfSpaces {
642 pub sub: ArrayBracketsInsteadOfSpacesSugg,
645 #[derive(Subdiagnostic)]
646 #[multipart_suggestion(suggestion, applicability = "maybe-incorrect")]
647 pub(crate) struct ArrayBracketsInsteadOfSpacesSugg {
648 #[suggestion_part(code = "[")]
650 #[suggestion_part(code = "]")]
654 #[derive(Diagnostic)]
655 #[diag(parse_match_arm_body_without_braces)]
656 pub(crate) struct MatchArmBodyWithoutBraces {
658 #[label(label_statements)]
659 pub statements: Span,
660 #[label(label_arrow)]
662 pub num_statements: usize,
664 pub sub: MatchArmBodyWithoutBracesSugg,
667 #[derive(Diagnostic)]
668 #[diag(parse_inclusive_range_extra_equals)]
670 pub(crate) struct InclusiveRangeExtraEquals {
673 suggestion_remove_eq,
676 applicability = "maybe-incorrect"
681 #[derive(Diagnostic)]
682 #[diag(parse_inclusive_range_match_arrow)]
683 pub(crate) struct InclusiveRangeMatchArrow {
688 #[suggestion(style = "verbose", code = " ", applicability = "machine-applicable")]
692 #[derive(Diagnostic)]
693 #[diag(parse_inclusive_range_no_end, code = "E0586")]
695 pub(crate) struct InclusiveRangeNoEnd {
698 suggestion_open_range,
700 applicability = "machine-applicable",
706 #[derive(Subdiagnostic)]
707 pub(crate) enum MatchArmBodyWithoutBracesSugg {
708 #[multipart_suggestion(suggestion_add_braces, applicability = "machine-applicable")]
710 #[suggestion_part(code = "{{ ")]
712 #[suggestion_part(code = " }}")]
716 suggestion_use_comma_not_semicolon,
718 applicability = "machine-applicable"
726 #[derive(Diagnostic)]
727 #[diag(parse_struct_literal_not_allowed_here)]
728 pub(crate) struct StructLiteralNotAllowedHere {
732 pub sub: StructLiteralNotAllowedHereSugg,
735 #[derive(Subdiagnostic)]
736 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
737 pub(crate) struct StructLiteralNotAllowedHereSugg {
738 #[suggestion_part(code = "(")]
740 #[suggestion_part(code = ")")]
744 #[derive(Diagnostic)]
745 #[diag(parse_invalid_interpolated_expression)]
746 pub(crate) struct InvalidInterpolatedExpression {
751 #[derive(Diagnostic)]
752 #[diag(parse_invalid_literal_suffix_on_tuple_index)]
753 pub(crate) struct InvalidLiteralSuffixOnTupleIndex {
758 #[help(tuple_exception_line_1)]
759 #[help(tuple_exception_line_2)]
760 #[help(tuple_exception_line_3)]
761 pub exception: Option<()>,
764 #[derive(Diagnostic)]
765 #[diag(parse_non_string_abi_literal)]
766 pub(crate) struct NonStringAbiLiteral {
768 #[suggestion(code = "\"C\"", applicability = "maybe-incorrect")]
772 #[derive(Diagnostic)]
773 #[diag(parse_mismatched_closing_delimiter)]
774 pub(crate) struct MismatchedClosingDelimiter {
776 pub spans: Vec<Span>,
777 pub delimiter: String,
778 #[label(label_unmatched)]
780 #[label(label_opening_candidate)]
781 pub opening_candidate: Option<Span>,
782 #[label(label_unclosed)]
783 pub unclosed: Option<Span>,
786 #[derive(Diagnostic)]
787 #[diag(parse_incorrect_visibility_restriction, code = "E0704")]
789 pub(crate) struct IncorrectVisibilityRestriction {
791 #[suggestion(code = "in {inner_str}", applicability = "machine-applicable")]
793 pub inner_str: String,
796 #[derive(Diagnostic)]
797 #[diag(parse_assignment_else_not_allowed)]
798 pub(crate) struct AssignmentElseNotAllowed {
803 #[derive(Diagnostic)]
804 #[diag(parse_expected_statement_after_outer_attr)]
805 pub(crate) struct ExpectedStatementAfterOuterAttr {
810 #[derive(Diagnostic)]
811 #[diag(parse_doc_comment_does_not_document_anything, code = "E0585")]
813 pub(crate) struct DocCommentDoesNotDocumentAnything {
816 #[suggestion(code = ",", applicability = "machine-applicable")]
817 pub missing_comma: Option<Span>,
820 #[derive(Diagnostic)]
821 #[diag(parse_const_let_mutually_exclusive)]
822 pub(crate) struct ConstLetMutuallyExclusive {
824 #[suggestion(code = "const", applicability = "maybe-incorrect")]
828 #[derive(Diagnostic)]
829 #[diag(parse_invalid_expression_in_let_else)]
830 pub(crate) struct InvalidExpressionInLetElse {
833 pub operator: &'static str,
835 pub sugg: WrapExpressionInParentheses,
838 #[derive(Diagnostic)]
839 #[diag(parse_invalid_curly_in_let_else)]
840 pub(crate) struct InvalidCurlyInLetElse {
844 pub sugg: WrapExpressionInParentheses,
847 #[derive(Diagnostic)]
848 #[diag(parse_compound_assignment_expression_in_let)]
850 pub(crate) struct CompoundAssignmentExpressionInLet {
852 #[suggestion(style = "short", code = "=", applicability = "maybe-incorrect")]
856 #[derive(Diagnostic)]
857 #[diag(parse_suffixed_literal_in_attribute)]
859 pub(crate) struct SuffixedLiteralInAttribute {
864 #[derive(Diagnostic)]
865 #[diag(parse_invalid_meta_item)]
866 pub(crate) struct InvalidMetaItem {
872 #[derive(Subdiagnostic)]
874 parse_sugg_escape_to_use_as_identifier,
876 applicability = "maybe-incorrect",
879 pub(crate) struct SuggEscapeToUseAsIdentifier {
882 pub ident_name: String,
885 #[derive(Subdiagnostic)]
886 #[suggestion(parse_sugg_remove_comma, applicability = "machine-applicable", code = "")]
887 pub(crate) struct SuggRemoveComma {
892 #[derive(Subdiagnostic)]
893 pub(crate) enum ExpectedIdentifierFound {
894 #[label(parse_expected_identifier_found_reserved_identifier)]
895 ReservedIdentifier(#[primary_span] Span),
896 #[label(parse_expected_identifier_found_keyword)]
897 Keyword(#[primary_span] Span),
898 #[label(parse_expected_identifier_found_reserved_keyword)]
899 ReservedKeyword(#[primary_span] Span),
900 #[label(parse_expected_identifier_found_doc_comment)]
901 DocComment(#[primary_span] Span),
902 #[label(parse_expected_identifier)]
903 Other(#[primary_span] Span),
906 impl ExpectedIdentifierFound {
907 pub fn new(token_descr: Option<TokenDescription>, span: Span) -> Self {
909 Some(TokenDescription::ReservedIdentifier) => {
910 ExpectedIdentifierFound::ReservedIdentifier
912 Some(TokenDescription::Keyword) => ExpectedIdentifierFound::Keyword,
913 Some(TokenDescription::ReservedKeyword) => ExpectedIdentifierFound::ReservedKeyword,
914 Some(TokenDescription::DocComment) => ExpectedIdentifierFound::DocComment,
915 None => ExpectedIdentifierFound::Other,
920 pub(crate) struct ExpectedIdentifier {
923 pub suggest_raw: Option<SuggEscapeToUseAsIdentifier>,
924 pub suggest_remove_comma: Option<SuggRemoveComma>,
927 impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedIdentifier {
931 handler: &'a rustc_errors::Handler,
932 ) -> rustc_errors::DiagnosticBuilder<'a, G> {
933 let token_descr = super::parser::TokenDescription::from_token(&self.token);
935 let mut diag = handler.struct_diagnostic(match token_descr {
936 Some(TokenDescription::ReservedIdentifier) => {
937 fluent::parse_expected_identifier_found_reserved_identifier_str
939 Some(TokenDescription::Keyword) => fluent::parse_expected_identifier_found_keyword_str,
940 Some(TokenDescription::ReservedKeyword) => {
941 fluent::parse_expected_identifier_found_reserved_keyword_str
943 Some(TokenDescription::DocComment) => {
944 fluent::parse_expected_identifier_found_doc_comment_str
946 None => fluent::parse_expected_identifier_found_str,
948 diag.set_span(self.span);
949 diag.set_arg("token", self.token);
951 if let Some(sugg) = self.suggest_raw {
952 sugg.add_to_diagnostic(&mut diag);
955 ExpectedIdentifierFound::new(token_descr, self.span).add_to_diagnostic(&mut diag);
957 if let Some(sugg) = self.suggest_remove_comma {
958 sugg.add_to_diagnostic(&mut diag);
965 pub(crate) struct ExpectedSemi {
969 pub unexpected_token_label: Option<Span>,
970 pub sugg: ExpectedSemiSugg,
973 impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedSemi {
977 handler: &'a rustc_errors::Handler,
978 ) -> rustc_errors::DiagnosticBuilder<'a, G> {
979 let token_descr = super::parser::TokenDescription::from_token(&self.token);
981 let mut diag = handler.struct_diagnostic(match token_descr {
982 Some(TokenDescription::ReservedIdentifier) => {
983 fluent::parse_expected_semi_found_reserved_identifier_str
985 Some(TokenDescription::Keyword) => fluent::parse_expected_semi_found_keyword_str,
986 Some(TokenDescription::ReservedKeyword) => {
987 fluent::parse_expected_semi_found_reserved_keyword_str
989 Some(TokenDescription::DocComment) => fluent::parse_expected_semi_found_doc_comment_str,
990 None => fluent::parse_expected_semi_found_str,
992 diag.set_span(self.span);
993 diag.set_arg("token", self.token);
995 if let Some(unexpected_token_label) = self.unexpected_token_label {
996 diag.span_label(unexpected_token_label, fluent::parse_label_unexpected_token);
999 self.sugg.add_to_diagnostic(&mut diag);
1005 #[derive(Subdiagnostic)]
1006 pub(crate) enum ExpectedSemiSugg {
1007 #[suggestion(parse_sugg_change_this_to_semi, code = ";", applicability = "machine-applicable")]
1008 ChangeToSemi(#[primary_span] Span),
1010 parse_sugg_add_semi,
1013 applicability = "machine-applicable"
1015 AddSemi(#[primary_span] Span),
1018 #[derive(Diagnostic)]
1019 #[diag(parse_struct_literal_body_without_path)]
1020 pub(crate) struct StructLiteralBodyWithoutPath {
1024 pub sugg: StructLiteralBodyWithoutPathSugg,
1027 #[derive(Subdiagnostic)]
1028 #[multipart_suggestion(suggestion, applicability = "has-placeholders")]
1029 pub(crate) struct StructLiteralBodyWithoutPathSugg {
1030 #[suggestion_part(code = "{{ SomeStruct ")]
1032 #[suggestion_part(code = " }}")]
1036 #[derive(Diagnostic)]
1037 #[diag(parse_struct_literal_needing_parens)]
1038 pub(crate) struct StructLiteralNeedingParens {
1042 pub sugg: StructLiteralNeedingParensSugg,
1045 #[derive(Subdiagnostic)]
1046 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1047 pub(crate) struct StructLiteralNeedingParensSugg {
1048 #[suggestion_part(code = "(")]
1050 #[suggestion_part(code = ")")]
1054 #[derive(Diagnostic)]
1055 #[diag(parse_unmatched_angle_brackets)]
1056 pub(crate) struct UnmatchedAngleBrackets {
1058 #[suggestion(code = "", applicability = "machine-applicable")]
1060 pub num_extra_brackets: usize,
1063 #[derive(Diagnostic)]
1064 #[diag(parse_generic_parameters_without_angle_brackets)]
1065 pub(crate) struct GenericParamsWithoutAngleBrackets {
1069 pub sugg: GenericParamsWithoutAngleBracketsSugg,
1072 #[derive(Subdiagnostic)]
1073 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1074 pub(crate) struct GenericParamsWithoutAngleBracketsSugg {
1075 #[suggestion_part(code = "<")]
1077 #[suggestion_part(code = ">")]
1081 #[derive(Diagnostic)]
1082 #[diag(parse_comparison_operators_cannot_be_chained)]
1083 pub(crate) struct ComparisonOperatorsCannotBeChained {
1085 pub span: Vec<Span>,
1087 parse_sugg_turbofish_syntax,
1090 applicability = "maybe-incorrect"
1092 pub suggest_turbofish: Option<Span>,
1093 #[help(parse_sugg_turbofish_syntax)]
1094 #[help(sugg_parentheses_for_function_args)]
1095 pub help_turbofish: Option<()>,
1097 pub chaining_sugg: Option<ComparisonOperatorsCannotBeChainedSugg>,
1100 #[derive(Subdiagnostic)]
1101 pub(crate) enum ComparisonOperatorsCannotBeChainedSugg {
1103 sugg_split_comparison,
1105 code = " && {middle_term}",
1106 applicability = "maybe-incorrect"
1111 middle_term: String,
1113 #[multipart_suggestion(sugg_parenthesize, applicability = "maybe-incorrect")]
1115 #[suggestion_part(code = "(")]
1117 #[suggestion_part(code = ")")]
1122 #[derive(Diagnostic)]
1123 #[diag(parse_question_mark_in_type)]
1124 pub(crate) struct QuestionMarkInType {
1129 pub sugg: QuestionMarkInTypeSugg,
1132 #[derive(Subdiagnostic)]
1133 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1134 pub(crate) struct QuestionMarkInTypeSugg {
1135 #[suggestion_part(code = "Option<")]
1137 #[suggestion_part(code = ">")]
1141 #[derive(Diagnostic)]
1142 #[diag(parse_unexpected_parentheses_in_for_head)]
1143 pub(crate) struct ParenthesesInForHead {
1145 pub span: Vec<Span>,
1147 pub sugg: ParenthesesInForHeadSugg,
1150 #[derive(Subdiagnostic)]
1151 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1152 pub(crate) struct ParenthesesInForHeadSugg {
1153 #[suggestion_part(code = "{left_snippet}")]
1155 pub left_snippet: String,
1156 #[suggestion_part(code = "{right_snippet}")]
1158 pub right_snippet: String,
1161 #[derive(Diagnostic)]
1162 #[diag(parse_doc_comment_on_param_type)]
1163 pub(crate) struct DocCommentOnParamType {
1169 #[derive(Diagnostic)]
1170 #[diag(parse_attribute_on_param_type)]
1171 pub(crate) struct AttributeOnParamType {
1177 #[derive(Diagnostic)]
1178 #[diag(parse_pattern_method_param_without_body, code = "E0642")]
1179 pub(crate) struct PatternMethodParamWithoutBody {
1181 #[suggestion(code = "_", applicability = "machine-applicable")]
1185 #[derive(Diagnostic)]
1186 #[diag(parse_self_param_not_first)]
1187 pub(crate) struct SelfParamNotFirst {
1193 #[derive(Diagnostic)]
1194 #[diag(parse_invalid_identifier_with_leading_number)]
1195 pub(crate) struct InvalidIdentiferStartsWithNumber {
1201 #[derive(Diagnostic)]
1202 #[diag(parse_const_generic_without_braces)]
1203 pub(crate) struct ConstGenericWithoutBraces {
1207 pub sugg: ConstGenericWithoutBracesSugg,
1210 #[derive(Subdiagnostic)]
1211 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1212 pub(crate) struct ConstGenericWithoutBracesSugg {
1213 #[suggestion_part(code = "{{ ")]
1215 #[suggestion_part(code = " }}")]
1219 #[derive(Diagnostic)]
1220 #[diag(parse_unexpected_const_param_declaration)]
1221 pub(crate) struct UnexpectedConstParamDeclaration {
1226 pub sugg: Option<UnexpectedConstParamDeclarationSugg>,
1229 #[derive(Subdiagnostic)]
1230 pub(crate) enum UnexpectedConstParamDeclarationSugg {
1231 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1233 #[suggestion_part(code = "<{snippet}>")]
1234 impl_generics: Span,
1235 #[suggestion_part(code = "{ident}")]
1236 incorrect_decl: Span,
1240 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1242 #[suggestion_part(code = ", {snippet}")]
1243 impl_generics_end: Span,
1244 #[suggestion_part(code = "{ident}")]
1245 incorrect_decl: Span,
1251 #[derive(Diagnostic)]
1252 #[diag(parse_unexpected_const_in_generic_param)]
1253 pub(crate) struct UnexpectedConstInGenericParam {
1256 #[suggestion(style = "verbose", code = "", applicability = "maybe-incorrect")]
1257 pub to_remove: Option<Span>,
1260 #[derive(Diagnostic)]
1261 #[diag(parse_async_move_order_incorrect)]
1262 pub(crate) struct AsyncMoveOrderIncorrect {
1264 #[suggestion(style = "verbose", code = "async move", applicability = "maybe-incorrect")]
1268 #[derive(Diagnostic)]
1269 #[diag(parse_double_colon_in_bound)]
1270 pub(crate) struct DoubleColonInBound {
1273 #[suggestion(code = ": ", applicability = "machine-applicable")]
1277 #[derive(Diagnostic)]
1278 #[diag(parse_fn_ptr_with_generics)]
1279 pub(crate) struct FnPtrWithGenerics {
1283 pub sugg: Option<FnPtrWithGenericsSugg>,
1286 #[derive(Subdiagnostic)]
1287 #[multipart_suggestion(suggestion, applicability = "maybe-incorrect")]
1288 pub(crate) struct FnPtrWithGenericsSugg {
1289 #[suggestion_part(code = "{snippet}")]
1291 pub snippet: String,
1292 #[suggestion_part(code = "")]
1295 pub for_param_list_exists: bool,
1298 #[derive(Diagnostic)]
1299 #[diag(parse_unexpected_if_with_if)]
1300 pub(crate) struct UnexpectedIfWithIf(
1302 #[suggestion(applicability = "machine-applicable", code = " ", style = "verbose")]
1306 #[derive(Diagnostic)]
1307 #[diag(parse_maybe_fn_typo_with_impl)]
1308 pub(crate) struct FnTypoWithImpl {
1310 #[suggestion(applicability = "maybe-incorrect", code = "impl", style = "verbose")]
1314 #[derive(Diagnostic)]
1315 #[diag(parse_expected_fn_path_found_fn_keyword)]
1316 pub(crate) struct ExpectedFnPathFoundFnKeyword {
1318 #[suggestion(applicability = "machine-applicable", code = "Fn", style = "verbose")]
1319 pub fn_token_span: Span,
1322 #[derive(Diagnostic)]
1323 #[diag(parse_where_clause_before_tuple_struct_body)]
1324 pub(crate) struct WhereClauseBeforeTupleStructBody {
1328 #[label(name_label)]
1330 #[label(body_label)]
1333 pub sugg: Option<WhereClauseBeforeTupleStructBodySugg>,
1336 #[derive(Subdiagnostic)]
1337 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1338 pub(crate) struct WhereClauseBeforeTupleStructBodySugg {
1339 #[suggestion_part(code = "{snippet}")]
1341 pub snippet: String,
1342 #[suggestion_part(code = "")]
1346 #[derive(Diagnostic)]
1347 #[diag(parse_async_fn_in_2015, code = "E0670")]
1348 pub(crate) struct AsyncFnIn2015 {
1353 pub help: HelpUseLatestEdition,
1356 #[derive(Subdiagnostic)]
1357 #[label(parse_async_block_in_2015)]
1358 pub(crate) struct AsyncBlockIn2015 {
1363 #[derive(Diagnostic)]
1364 #[diag(parse_self_argument_pointer)]
1365 pub(crate) struct SelfArgumentPointer {
1371 #[derive(Diagnostic)]
1372 #[diag(parse_unexpected_token_after_dot)]
1373 pub struct UnexpectedTokenAfterDot<'a> {
1376 pub actual: Cow<'a, str>,
1379 #[derive(Diagnostic)]
1380 #[diag(parse_visibility_not_followed_by_item)]
1382 pub(crate) struct VisibilityNotFollowedByItem {
1386 pub vis: Visibility,
1389 #[derive(Diagnostic)]
1390 #[diag(parse_default_not_followed_by_item)]
1392 pub(crate) struct DefaultNotFollowedByItem {
1398 #[derive(Diagnostic)]
1399 pub(crate) enum MissingKeywordForItemDefinition {
1400 #[diag(parse_missing_struct_for_struct_definition)]
1403 #[suggestion(style = "short", applicability = "maybe-incorrect", code = " struct ")]
1407 #[diag(parse_missing_fn_for_function_definition)]
1410 #[suggestion(style = "short", applicability = "maybe-incorrect", code = " fn ")]
1414 #[diag(parse_missing_fn_for_method_definition)]
1417 #[suggestion(style = "short", applicability = "maybe-incorrect", code = " fn ")]
1421 #[diag(parse_ambiguous_missing_keyword_for_item_definition)]
1426 subdiag: Option<AmbiguousMissingKwForItemSub>,
1430 #[derive(Subdiagnostic)]
1431 pub(crate) enum AmbiguousMissingKwForItemSub {
1432 #[suggestion(suggestion, applicability = "maybe-incorrect", code = "{snippet}!")]
1442 #[derive(Diagnostic)]
1443 #[diag(parse_missing_trait_in_trait_impl)]
1444 pub(crate) struct MissingTraitInTraitImpl {
1446 #[suggestion(suggestion_add_trait, code = " Trait ", applicability = "has-placeholders")]
1448 #[suggestion(suggestion_remove_for, code = "", applicability = "maybe-incorrect")]
1452 #[derive(Diagnostic)]
1453 #[diag(parse_missing_for_in_trait_impl)]
1454 pub(crate) struct MissingForInTraitImpl {
1456 #[suggestion(style = "short", code = " for ", applicability = "machine-applicable")]
1460 #[derive(Diagnostic)]
1461 #[diag(parse_expected_trait_in_trait_impl_found_type)]
1462 pub(crate) struct ExpectedTraitInTraitImplFoundType {
1467 #[derive(Diagnostic)]
1468 #[diag(parse_bounds_not_allowed_on_trait_aliases)]
1469 pub(crate) struct BoundsNotAllowedOnTraitAliases {
1474 #[derive(Diagnostic)]
1475 #[diag(parse_trait_alias_cannot_be_auto)]
1476 pub(crate) struct TraitAliasCannotBeAuto {
1478 #[label(parse_trait_alias_cannot_be_auto)]
1482 #[derive(Diagnostic)]
1483 #[diag(parse_trait_alias_cannot_be_unsafe)]
1484 pub(crate) struct TraitAliasCannotBeUnsafe {
1486 #[label(parse_trait_alias_cannot_be_unsafe)]
1490 #[derive(Diagnostic)]
1491 #[diag(parse_associated_static_item_not_allowed)]
1492 pub(crate) struct AssociatedStaticItemNotAllowed {
1497 #[derive(Diagnostic)]
1498 #[diag(parse_extern_crate_name_with_dashes)]
1499 pub(crate) struct ExternCrateNameWithDashes {
1504 pub sugg: ExternCrateNameWithDashesSugg,
1507 #[derive(Subdiagnostic)]
1508 #[multipart_suggestion(suggestion, applicability = "machine-applicable")]
1509 pub(crate) struct ExternCrateNameWithDashesSugg {
1510 #[suggestion_part(code = "_")]
1511 pub dashes: Vec<Span>,
1514 #[derive(Diagnostic)]
1515 #[diag(parse_extern_item_cannot_be_const)]
1517 pub(crate) struct ExternItemCannotBeConst {
1519 pub ident_span: Span,
1520 #[suggestion(code = "static ", applicability = "machine-applicable")]
1521 pub const_span: Span,
1524 #[derive(Diagnostic)]
1525 #[diag(parse_const_global_cannot_be_mutable)]
1526 pub(crate) struct ConstGlobalCannotBeMutable {
1529 pub ident_span: Span,
1530 #[suggestion(code = "static", applicability = "maybe-incorrect")]
1531 pub const_span: Span,
1534 #[derive(Diagnostic)]
1535 #[diag(parse_missing_const_type)]
1536 pub(crate) struct MissingConstType {
1538 #[suggestion(code = "{colon} <type>", applicability = "has-placeholders")]
1541 pub kind: &'static str,
1542 pub colon: &'static str,
1545 #[derive(Diagnostic)]
1546 #[diag(parse_enum_struct_mutually_exclusive)]
1547 pub(crate) struct EnumStructMutuallyExclusive {
1549 #[suggestion(code = "enum", applicability = "machine-applicable")]
1553 #[derive(Diagnostic)]
1554 pub(crate) enum UnexpectedTokenAfterStructName {
1555 #[diag(parse_unexpected_token_after_struct_name_found_reserved_identifier)]
1556 ReservedIdentifier {
1558 #[label(parse_unexpected_token_after_struct_name)]
1562 #[diag(parse_unexpected_token_after_struct_name_found_keyword)]
1565 #[label(parse_unexpected_token_after_struct_name)]
1569 #[diag(parse_unexpected_token_after_struct_name_found_reserved_keyword)]
1572 #[label(parse_unexpected_token_after_struct_name)]
1576 #[diag(parse_unexpected_token_after_struct_name_found_doc_comment)]
1579 #[label(parse_unexpected_token_after_struct_name)]
1583 #[diag(parse_unexpected_token_after_struct_name_found_other)]
1586 #[label(parse_unexpected_token_after_struct_name)]
1592 impl UnexpectedTokenAfterStructName {
1593 pub fn new(span: Span, token: Token) -> Self {
1594 match TokenDescription::from_token(&token) {
1595 Some(TokenDescription::ReservedIdentifier) => Self::ReservedIdentifier { span, token },
1596 Some(TokenDescription::Keyword) => Self::Keyword { span, token },
1597 Some(TokenDescription::ReservedKeyword) => Self::ReservedKeyword { span, token },
1598 Some(TokenDescription::DocComment) => Self::DocComment { span, token },
1599 None => Self::Other { span, token },
1604 #[derive(Diagnostic)]
1605 #[diag(parse_unexpected_self_in_generic_parameters)]
1607 pub(crate) struct UnexpectedSelfInGenericParameters {
1612 #[derive(Diagnostic)]
1613 #[diag(parse_unexpected_default_value_for_lifetime_in_generic_parameters)]
1614 pub(crate) struct UnexpectedDefaultValueForLifetimeInGenericParameters {
1620 #[derive(Diagnostic)]
1621 #[diag(parse_multiple_where_clauses)]
1622 pub(crate) struct MultipleWhereClauses {
1627 #[suggestion(style = "verbose", code = ",", applicability = "maybe-incorrect")]
1631 #[derive(Diagnostic)]
1632 pub(crate) enum UnexpectedNonterminal {
1633 #[diag(parse_nonterminal_expected_item_keyword)]
1634 Item(#[primary_span] Span),
1635 #[diag(parse_nonterminal_expected_statement)]
1636 Statement(#[primary_span] Span),
1637 #[diag(parse_nonterminal_expected_ident)]
1643 #[diag(parse_nonterminal_expected_lifetime)]
1651 #[derive(Diagnostic)]
1652 pub(crate) enum TopLevelOrPatternNotAllowed {
1653 #[diag(parse_or_pattern_not_allowed_in_let_binding)]
1658 sub: Option<TopLevelOrPatternNotAllowedSugg>,
1660 #[diag(parse_or_pattern_not_allowed_in_fn_parameters)]
1665 sub: Option<TopLevelOrPatternNotAllowedSugg>,
1669 #[derive(Diagnostic)]
1670 #[diag(parse_cannot_be_raw_ident)]
1671 pub struct CannotBeRawIdent {
1677 #[derive(Diagnostic)]
1678 #[diag(parse_cr_doc_comment)]
1679 pub struct CrDocComment {
1685 #[derive(Diagnostic)]
1686 #[diag(parse_no_digits_literal, code = "E0768")]
1687 pub struct NoDigitsLiteral {
1692 #[derive(Diagnostic)]
1693 #[diag(parse_invalid_digit_literal)]
1694 pub struct InvalidDigitLiteral {
1700 #[derive(Diagnostic)]
1701 #[diag(parse_empty_exponent_float)]
1702 pub struct EmptyExponentFloat {
1707 #[derive(Diagnostic)]
1708 #[diag(parse_float_literal_unsupported_base)]
1709 pub struct FloatLiteralUnsupportedBase {
1712 pub base: &'static str,
1715 #[derive(Diagnostic)]
1716 #[diag(parse_unknown_prefix)]
1718 pub struct UnknownPrefix<'a> {
1722 pub prefix: &'a str,
1724 pub sugg: Option<UnknownPrefixSugg>,
1727 #[derive(Subdiagnostic)]
1728 pub enum UnknownPrefixSugg {
1729 #[suggestion(suggestion_br, code = "br", applicability = "maybe-incorrect", style = "verbose")]
1730 UseBr(#[primary_span] Span),
1732 suggestion_whitespace,
1734 applicability = "maybe-incorrect",
1737 Whitespace(#[primary_span] Span),
1740 #[derive(Diagnostic)]
1741 #[diag(parse_too_many_hashes)]
1742 pub struct TooManyHashes {
1748 #[derive(Diagnostic)]
1749 #[diag(parse_unknown_start_of_token)]
1750 pub struct UnknownTokenStart {
1753 pub escaped: String,
1755 pub sugg: Option<TokenSubstitution>,
1757 pub null: Option<UnknownTokenNull>,
1759 pub repeat: Option<UnknownTokenRepeat>,
1762 #[derive(Subdiagnostic)]
1763 pub enum TokenSubstitution {
1764 #[suggestion(sugg_quotes, code = "{suggestion}", applicability = "maybe-incorrect")]
1769 ascii_str: &'static str,
1770 ascii_name: &'static str,
1772 #[suggestion(sugg_other, code = "{suggestion}", applicability = "maybe-incorrect")]
1778 u_name: &'static str,
1779 ascii_str: &'static str,
1780 ascii_name: &'static str,
1784 #[derive(Subdiagnostic)]
1785 #[note(note_repeats)]
1786 pub struct UnknownTokenRepeat {
1790 #[derive(Subdiagnostic)]
1792 pub struct UnknownTokenNull;
1794 #[derive(Diagnostic)]
1795 pub enum UnescapeError {
1796 #[diag(parse_invalid_unicode_escape)]
1798 InvalidUnicodeEscape {
1804 #[diag(parse_escape_only_char)]
1808 #[suggestion(escape, applicability = "machine-applicable", code = "{escaped_sugg}")]
1810 escaped_sugg: String,
1811 escaped_msg: String,
1814 #[diag(parse_bare_cr)]
1817 #[suggestion(escape, applicability = "machine-applicable", code = "\\r")]
1819 double_quotes: bool,
1821 #[diag(parse_bare_cr_in_raw_string)]
1822 BareCrRawString(#[primary_span] Span),
1823 #[diag(parse_too_short_hex_escape)]
1824 TooShortHexEscape(#[primary_span] Span),
1825 #[diag(parse_invalid_char_in_escape)]
1826 InvalidCharInEscape {
1833 #[diag(parse_out_of_range_hex_escape)]
1834 OutOfRangeHexEscape(
1839 #[diag(parse_leading_underscore_unicode_escape)]
1840 LeadingUnderscoreUnicodeEscape {
1842 #[label(parse_leading_underscore_unicode_escape_label)]
1846 #[diag(parse_overlong_unicode_escape)]
1847 OverlongUnicodeEscape(
1852 #[diag(parse_unclosed_unicode_escape)]
1853 UnclosedUnicodeEscape(
1857 #[suggestion(terminate, code = "}}", applicability = "maybe-incorrect", style = "verbose")]
1860 #[diag(parse_no_brace_unicode_escape)]
1861 NoBraceInUnicodeEscape {
1865 label: Option<Span>,
1867 sub: NoBraceUnicodeSub,
1869 #[diag(parse_unicode_escape_in_byte)]
1871 UnicodeEscapeInByte(
1876 #[diag(parse_empty_unicode_escape)]
1882 #[diag(parse_zero_chars)]
1888 #[diag(parse_lone_slash)]
1894 #[diag(parse_unskipped_whitespace)]
1895 UnskippedWhitespace {
1902 #[diag(parse_multiple_skipped_lines)]
1903 MultipleSkippedLinesWarning(
1908 #[diag(parse_more_than_one_char)]
1913 note: Option<MoreThanOneCharNote>,
1915 suggestion: MoreThanOneCharSugg,
1919 #[derive(Subdiagnostic)]
1920 pub enum MoreThanOneCharSugg {
1921 #[suggestion(consider_normalized, code = "{normalized}", applicability = "machine-applicable")]
1928 #[suggestion(remove_non, code = "{ch}", applicability = "maybe-incorrect")]
1934 #[suggestion(use_double_quotes, code = "{sugg}", applicability = "machine-applicable")]
1943 #[derive(Subdiagnostic)]
1944 pub enum MoreThanOneCharNote {
1945 #[note(followed_by)]
1951 escaped_marks: String,
1953 #[note(non_printing)]
1961 #[derive(Subdiagnostic)]
1962 pub enum NoBraceUnicodeSub {
1963 #[suggestion(use_braces, code = "{suggestion}", applicability = "maybe-incorrect")]
1969 #[help(format_of_unicode)]
1973 #[derive(Subdiagnostic)]
1974 pub(crate) enum TopLevelOrPatternNotAllowedSugg {
1976 parse_sugg_remove_leading_vert_in_pattern,
1978 applicability = "machine-applicable"
1986 parse_sugg_wrap_pattern_in_parens,
1988 applicability = "machine-applicable"
1997 #[derive(Diagnostic)]
1998 #[diag(parse_unexpected_vert_vert_before_function_parameter)]
1999 #[note(parse_note_pattern_alternatives_use_single_vert)]
2000 pub(crate) struct UnexpectedVertVertBeforeFunctionParam {
2002 #[suggestion(code = "", applicability = "machine-applicable")]
2006 #[derive(Diagnostic)]
2007 #[diag(parse_unexpected_vert_vert_in_pattern)]
2008 pub(crate) struct UnexpectedVertVertInPattern {
2010 #[suggestion(code = "|", applicability = "machine-applicable")]
2012 #[label(parse_label_while_parsing_or_pattern_here)]
2013 pub start: Option<Span>,
2016 #[derive(Diagnostic)]
2017 #[diag(parse_trailing_vert_not_allowed)]
2018 pub(crate) struct TrailingVertNotAllowed {
2020 #[suggestion(code = "", applicability = "machine-applicable")]
2022 #[label(parse_label_while_parsing_or_pattern_here)]
2023 pub start: Option<Span>,
2025 #[note(parse_note_pattern_alternatives_use_single_vert)]
2026 pub note_double_vert: Option<()>,
2029 #[derive(Diagnostic)]
2030 #[diag(parse_dotdotdot_rest_pattern)]
2031 pub(crate) struct DotDotDotRestPattern {
2033 #[suggestion(style = "short", code = "..", applicability = "machine-applicable")]
2038 #[derive(Diagnostic)]
2039 #[diag(parse_pattern_on_wrong_side_of_at)]
2040 pub(crate) struct PatternOnWrongSideOfAt {
2042 #[suggestion(code = "{whole_pat}", applicability = "machine-applicable")]
2043 pub whole_span: Span,
2044 pub whole_pat: String,
2045 #[label(label_pattern)]
2047 #[label(label_binding)]
2051 #[derive(Diagnostic)]
2052 #[diag(parse_expected_binding_left_of_at)]
2054 pub(crate) struct ExpectedBindingLeftOfAt {
2056 pub whole_span: Span,
2063 #[derive(Diagnostic)]
2064 #[diag(parse_ambiguous_range_pattern)]
2065 pub(crate) struct AmbiguousRangePattern {
2067 #[suggestion(code = "({pat})", applicability = "maybe-incorrect")]
2072 #[derive(Diagnostic)]
2073 #[diag(parse_unexpected_lifetime_in_pattern)]
2074 pub(crate) struct UnexpectedLifetimeInPattern {
2076 #[suggestion(code = "", applicability = "machine-applicable")]
2081 #[derive(Diagnostic)]
2082 #[diag(parse_ref_mut_order_incorrect)]
2083 pub(crate) struct RefMutOrderIncorrect {
2085 #[suggestion(code = "ref mut", applicability = "machine-applicable")]
2089 #[derive(Diagnostic)]
2090 pub(crate) enum InvalidMutInPattern {
2091 #[diag(parse_mut_on_nested_ident_pattern)]
2092 #[note(parse_note_mut_pattern_usage)]
2095 #[suggestion(code = "{pat}", applicability = "machine-applicable")]
2099 #[diag(parse_mut_on_non_ident_pattern)]
2100 #[note(parse_note_mut_pattern_usage)]
2103 #[suggestion(code = "{pat}", applicability = "machine-applicable")]
2109 #[derive(Diagnostic)]
2110 #[diag(parse_repeated_mut_in_pattern)]
2111 pub(crate) struct RepeatedMutInPattern {
2113 #[suggestion(code = "", applicability = "machine-applicable")]
2117 #[derive(Diagnostic)]
2118 #[diag(parse_dot_dot_dot_range_to_pattern_not_allowed)]
2119 pub(crate) struct DotDotDotRangeToPatternNotAllowed {
2121 #[suggestion(style = "short", code = "..=", applicability = "machine-applicable")]
2125 #[derive(Diagnostic)]
2126 #[diag(parse_enum_pattern_instead_of_identifier)]
2127 pub(crate) struct EnumPatternInsteadOfIdentifier {
2132 #[derive(Diagnostic)]
2133 #[diag(parse_dot_dot_dot_for_remaining_fields)]
2134 pub(crate) struct DotDotDotForRemainingFields {
2136 #[suggestion(code = "..", style = "verbose", applicability = "machine-applicable")]
2138 pub token_str: Cow<'static, str>,
2141 #[derive(Diagnostic)]
2142 #[diag(parse_expected_comma_after_pattern_field)]
2143 pub(crate) struct ExpectedCommaAfterPatternField {
2148 #[derive(Diagnostic)]
2149 #[diag(parse_return_types_use_thin_arrow)]
2150 pub(crate) struct ReturnTypesUseThinArrow {
2152 #[suggestion(style = "short", code = "->", applicability = "machine-applicable")]
2156 #[derive(Diagnostic)]
2157 #[diag(parse_need_plus_after_trait_object_lifetime)]
2158 pub(crate) struct NeedPlusAfterTraitObjectLifetime {
2163 #[derive(Diagnostic)]
2164 #[diag(parse_expected_mut_or_const_in_raw_pointer_type)]
2165 pub(crate) struct ExpectedMutOrConstInRawPointerType {
2168 #[suggestion(code("mut ", "const "), applicability = "has-placeholders")]
2169 pub after_asterisk: Span,
2172 #[derive(Diagnostic)]
2173 #[diag(parse_lifetime_after_mut)]
2174 pub(crate) struct LifetimeAfterMut {
2177 #[suggestion(code = "&{snippet} mut", applicability = "maybe-incorrect")]
2178 pub suggest_lifetime: Option<Span>,
2179 pub snippet: String,
2182 #[derive(Diagnostic)]
2183 #[diag(parse_dyn_after_mut)]
2184 pub(crate) struct DynAfterMut {
2186 #[suggestion(code = "&mut dyn", applicability = "machine-applicable")]
2190 #[derive(Diagnostic)]
2191 #[diag(parse_fn_pointer_cannot_be_const)]
2192 pub(crate) struct FnPointerCannotBeConst {
2195 #[suggestion(code = "", applicability = "maybe-incorrect")]
2197 pub qualifier: Span,
2200 #[derive(Diagnostic)]
2201 #[diag(parse_fn_pointer_cannot_be_async)]
2202 pub(crate) struct FnPointerCannotBeAsync {
2205 #[suggestion(code = "", applicability = "maybe-incorrect")]
2207 pub qualifier: Span,
2210 #[derive(Diagnostic)]
2211 #[diag(parse_nested_c_variadic_type, code = "E0743")]
2212 pub(crate) struct NestedCVariadicType {
2217 #[derive(Diagnostic)]
2218 #[diag(parse_invalid_dyn_keyword)]
2220 pub(crate) struct InvalidDynKeyword {
2222 #[suggestion(code = "", applicability = "machine-applicable")]
2226 #[derive(Diagnostic)]
2227 #[diag(parse_negative_bounds_not_supported)]
2228 pub(crate) struct NegativeBoundsNotSupported {
2230 pub negative_bounds: Vec<Span>,
2232 pub last_span: Span,
2234 pub sub: Option<NegativeBoundsNotSupportedSugg>,
2237 #[derive(Subdiagnostic)]
2240 style = "tool-only",
2242 applicability = "machine-applicable"
2244 pub(crate) struct NegativeBoundsNotSupportedSugg {
2246 pub bound_list: Span,
2247 pub num_bounds: usize,
2251 #[derive(Subdiagnostic)]
2252 pub enum HelpUseLatestEdition {
2253 #[help(parse_help_set_edition_cargo)]
2254 #[note(parse_note_edition_guide)]
2255 Cargo { edition: Edition },
2256 #[help(parse_help_set_edition_standalone)]
2257 #[note(parse_note_edition_guide)]
2258 Standalone { edition: Edition },
2261 impl HelpUseLatestEdition {
2262 pub fn new() -> Self {
2263 let edition = LATEST_STABLE_EDITION;
2264 if std::env::var_os("CARGO").is_some() {
2265 Self::Cargo { edition }
2267 Self::Standalone { edition }