From 692bc344d55cf9d86c60b06c92a70684d013c89f Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Sat, 6 Jul 2024 03:07:46 +0000 Subject: Make parse error suggestions verbose and fix spans Go over all structured parser suggestions and make them verbose style. When suggesting to add or remove delimiters, turn them into multiple suggestion parts. --- compiler/rustc_parse/src/errors.rs | 392 +++++++++++++++++++++++++------------ 1 file changed, 266 insertions(+), 126 deletions(-) (limited to 'compiler/rustc_parse/src/errors.rs') diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 3ae9b6dad99..0f13a8e5e14 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -18,10 +18,10 @@ use crate::parser::{ForbiddenLetReason, TokenDescription}; #[derive(Diagnostic)] #[diag(parse_maybe_report_ambiguous_plus)] pub(crate) struct AmbiguousPlus { - pub sum_ty: String, #[primary_span] - #[suggestion(code = "({sum_ty})")] pub span: Span, + #[subdiagnostic] + pub suggestion: AddParen, } #[derive(Diagnostic)] @@ -34,17 +34,20 @@ pub(crate) struct BadTypePlus { pub sub: BadTypePlusSub, } +#[derive(Subdiagnostic)] +#[multipart_suggestion(parse_add_paren, applicability = "machine-applicable")] +pub(crate) struct AddParen { + #[suggestion_part(code = "(")] + pub lo: Span, + #[suggestion_part(code = ")")] + pub hi: Span, +} + #[derive(Subdiagnostic)] pub(crate) enum BadTypePlusSub { - #[suggestion( - parse_add_paren, - code = "{sum_with_parens}", - applicability = "machine-applicable" - )] AddParen { - sum_with_parens: String, - #[primary_span] - span: Span, + #[subdiagnostic] + suggestion: AddParen, }, #[label(parse_forgot_paren)] ForgotParen { @@ -80,7 +83,7 @@ pub(crate) struct WrapType { #[diag(parse_incorrect_semicolon)] pub(crate) struct IncorrectSemicolon<'a> { #[primary_span] - #[suggestion(style = "short", code = "", applicability = "machine-applicable")] + #[suggestion(style = "verbose", code = "", applicability = "machine-applicable")] pub span: Span, #[help] pub show_help: bool, @@ -91,7 +94,12 @@ pub(crate) struct IncorrectSemicolon<'a> { #[diag(parse_incorrect_use_of_await)] pub(crate) struct IncorrectUseOfAwait { #[primary_span] - #[suggestion(parse_parentheses_suggestion, code = "", applicability = "machine-applicable")] + #[suggestion( + parse_parentheses_suggestion, + style = "verbose", + code = "", + applicability = "machine-applicable" + )] pub span: Span, } @@ -100,7 +108,11 @@ pub(crate) struct IncorrectUseOfAwait { pub(crate) struct IncorrectAwait { #[primary_span] pub span: Span, - #[suggestion(parse_postfix_suggestion, code = "{expr}.await{question_mark}")] + #[suggestion( + parse_postfix_suggestion, + style = "verbose", + code = "{expr}.await{question_mark}" + )] pub sugg_span: (Span, Applicability), pub expr: String, pub question_mark: &'static str, @@ -111,7 +123,7 @@ pub(crate) struct IncorrectAwait { pub(crate) struct InInTypo { #[primary_span] pub span: Span, - #[suggestion(code = "", applicability = "machine-applicable")] + #[suggestion(code = "", style = "verbose", applicability = "machine-applicable")] pub sugg_span: Span, } @@ -126,17 +138,33 @@ pub(crate) struct InvalidVariableDeclaration { #[derive(Subdiagnostic)] pub(crate) enum InvalidVariableDeclarationSub { - #[suggestion(parse_switch_mut_let_order, applicability = "maybe-incorrect", code = "let mut")] + #[suggestion( + parse_switch_mut_let_order, + style = "verbose", + applicability = "maybe-incorrect", + code = "let mut" + )] SwitchMutLetOrder(#[primary_span] Span), #[suggestion( parse_missing_let_before_mut, applicability = "machine-applicable", + style = "verbose", code = "let mut" )] MissingLet(#[primary_span] Span), - #[suggestion(parse_use_let_not_auto, applicability = "machine-applicable", code = "let")] + #[suggestion( + parse_use_let_not_auto, + style = "verbose", + applicability = "machine-applicable", + code = "let" + )] UseLetNotAuto(#[primary_span] Span), - #[suggestion(parse_use_let_not_var, applicability = "machine-applicable", code = "let")] + #[suggestion( + parse_use_let_not_var, + style = "verbose", + applicability = "machine-applicable", + code = "let" + )] UseLetNotVar(#[primary_span] Span), } @@ -144,7 +172,7 @@ pub(crate) enum InvalidVariableDeclarationSub { #[diag(parse_switch_ref_box_order)] pub(crate) struct SwitchRefBoxOrder { #[primary_span] - #[suggestion(applicability = "machine-applicable", code = "box ref")] + #[suggestion(applicability = "machine-applicable", style = "verbose", code = "box ref")] pub span: Span, } @@ -162,7 +190,7 @@ pub(crate) struct InvalidComparisonOperator { pub(crate) enum InvalidComparisonOperatorSub { #[suggestion( parse_use_instead, - style = "short", + style = "verbose", applicability = "machine-applicable", code = "{correct}" )] @@ -191,14 +219,14 @@ pub(crate) struct InvalidLogicalOperator { pub(crate) enum InvalidLogicalOperatorSub { #[suggestion( parse_use_amp_amp_for_conjunction, - style = "short", + style = "verbose", applicability = "machine-applicable", code = "&&" )] Conjunction(#[primary_span] Span), #[suggestion( parse_use_pipe_pipe_for_disjunction, - style = "short", + style = "verbose", applicability = "machine-applicable", code = "||" )] @@ -209,7 +237,7 @@ pub(crate) enum InvalidLogicalOperatorSub { #[diag(parse_tilde_is_not_unary_operator)] pub(crate) struct TildeAsUnaryOperator( #[primary_span] - #[suggestion(style = "short", applicability = "machine-applicable", code = "!")] + #[suggestion(style = "verbose", applicability = "machine-applicable", code = "!")] pub Span, ); @@ -227,7 +255,7 @@ pub(crate) struct NotAsNegationOperator { pub enum NotAsNegationOperatorSub { #[suggestion( parse_unexpected_token_after_not_default, - style = "short", + style = "verbose", applicability = "machine-applicable", code = "!" )] @@ -235,7 +263,7 @@ pub enum NotAsNegationOperatorSub { #[suggestion( parse_unexpected_token_after_not_bitwise, - style = "short", + style = "verbose", applicability = "machine-applicable", code = "!" )] @@ -243,7 +271,7 @@ pub enum NotAsNegationOperatorSub { #[suggestion( parse_unexpected_token_after_not_logical, - style = "short", + style = "verbose", applicability = "machine-applicable", code = "!" )] @@ -254,9 +282,9 @@ pub enum NotAsNegationOperatorSub { #[diag(parse_malformed_loop_label)] pub(crate) struct MalformedLoopLabel { #[primary_span] - #[suggestion(applicability = "machine-applicable", code = "{correct_label}")] pub span: Span, - pub correct_label: Ident, + #[suggestion(applicability = "machine-applicable", code = "'", style = "verbose")] + pub suggestion: Span, } #[derive(Diagnostic)] @@ -264,7 +292,7 @@ pub(crate) struct MalformedLoopLabel { pub(crate) struct LifetimeInBorrowExpression { #[primary_span] pub span: Span, - #[suggestion(applicability = "machine-applicable", code = "")] + #[suggestion(applicability = "machine-applicable", code = "", style = "verbose")] #[label] pub lifetime_span: Span, } @@ -306,7 +334,7 @@ pub(crate) struct RequireColonAfterLabeledExpression { pub span: Span, #[label] pub label: Span, - #[suggestion(style = "short", applicability = "machine-applicable", code = ": ")] + #[suggestion(style = "verbose", applicability = "machine-applicable", code = ": ")] pub label_end: Span, } @@ -315,7 +343,7 @@ pub(crate) struct RequireColonAfterLabeledExpression { #[note] pub(crate) struct DoCatchSyntaxRemoved { #[primary_span] - #[suggestion(applicability = "machine-applicable", code = "try")] + #[suggestion(applicability = "machine-applicable", code = "try", style = "verbose")] pub span: Span, } @@ -323,9 +351,9 @@ pub(crate) struct DoCatchSyntaxRemoved { #[diag(parse_float_literal_requires_integer_part)] pub(crate) struct FloatLiteralRequiresIntegerPart { #[primary_span] - #[suggestion(applicability = "machine-applicable", code = "{correct}")] pub span: Span, - pub correct: String, + #[suggestion(applicability = "machine-applicable", code = "0", style = "verbose")] + pub suggestion: Span, } #[derive(Diagnostic)] @@ -394,7 +422,12 @@ pub struct TernaryOperator { } #[derive(Subdiagnostic)] -#[suggestion(parse_extra_if_in_let_else, applicability = "maybe-incorrect", code = "")] +#[suggestion( + parse_extra_if_in_let_else, + applicability = "maybe-incorrect", + code = "", + style = "verbose" +)] pub(crate) struct IfExpressionLetSomeSub { #[primary_span] pub if_span: Span, @@ -463,7 +496,7 @@ pub(crate) struct ExpectedElseBlock { pub first_tok: String, #[label] pub else_span: Span, - #[suggestion(applicability = "maybe-incorrect", code = "if ")] + #[suggestion(applicability = "maybe-incorrect", code = "if ", style = "verbose")] pub condition_start: Span, } @@ -491,7 +524,7 @@ pub(crate) struct OuterAttributeNotAllowedOnIfElse { pub ctx_span: Span, pub ctx: String, - #[suggestion(applicability = "machine-applicable", code = "")] + #[suggestion(applicability = "machine-applicable", code = "", style = "verbose")] pub attributes: Span, } @@ -509,12 +542,17 @@ pub(crate) enum MissingInInForLoopSub { // Has been misleading, at least in the past (closed Issue #48492), thus maybe-incorrect #[suggestion( parse_use_in_not_of, - style = "short", + style = "verbose", applicability = "maybe-incorrect", code = "in" )] InNotOf(#[primary_span] Span), - #[suggestion(parse_add_in, style = "short", applicability = "maybe-incorrect", code = " in ")] + #[suggestion( + parse_add_in, + style = "verbose", + applicability = "maybe-incorrect", + code = " in " + )] AddIn(#[primary_span] Span), } @@ -545,7 +583,7 @@ pub(crate) struct LoopElseNotSupported { #[diag(parse_missing_comma_after_match_arm)] pub(crate) struct MissingCommaAfterMatchArm { #[primary_span] - #[suggestion(applicability = "machine-applicable", code = ",")] + #[suggestion(applicability = "machine-applicable", code = ",", style = "verbose")] pub span: Span, } @@ -563,7 +601,7 @@ pub(crate) struct CatchAfterTry { pub(crate) struct CommaAfterBaseStruct { #[primary_span] pub span: Span, - #[suggestion(style = "short", applicability = "machine-applicable", code = "")] + #[suggestion(style = "verbose", applicability = "machine-applicable", code = "")] pub comma: Span, } @@ -572,7 +610,7 @@ pub(crate) struct CommaAfterBaseStruct { pub(crate) struct EqFieldInit { #[primary_span] pub span: Span, - #[suggestion(applicability = "machine-applicable", code = ":")] + #[suggestion(applicability = "machine-applicable", code = ":", style = "verbose")] pub eq: Span, } @@ -580,8 +618,18 @@ pub(crate) struct EqFieldInit { #[diag(parse_dotdotdot)] pub(crate) struct DotDotDot { #[primary_span] - #[suggestion(parse_suggest_exclusive_range, applicability = "maybe-incorrect", code = "..")] - #[suggestion(parse_suggest_inclusive_range, applicability = "maybe-incorrect", code = "..=")] + #[suggestion( + parse_suggest_exclusive_range, + applicability = "maybe-incorrect", + code = "..", + style = "verbose" + )] + #[suggestion( + parse_suggest_inclusive_range, + applicability = "maybe-incorrect", + code = "..=", + style = "verbose" + )] pub span: Span, } @@ -589,7 +637,7 @@ pub(crate) struct DotDotDot { #[diag(parse_left_arrow_operator)] pub(crate) struct LeftArrowOperator { #[primary_span] - #[suggestion(applicability = "maybe-incorrect", code = "< -")] + #[suggestion(applicability = "maybe-incorrect", code = "< -", style = "verbose")] pub span: Span, } @@ -597,7 +645,7 @@ pub(crate) struct LeftArrowOperator { #[diag(parse_remove_let)] pub(crate) struct RemoveLet { #[primary_span] - #[suggestion(applicability = "machine-applicable", code = "")] + #[suggestion(applicability = "machine-applicable", code = "", style = "verbose")] pub span: Span, } @@ -605,8 +653,9 @@ pub(crate) struct RemoveLet { #[diag(parse_use_eq_instead)] pub(crate) struct UseEqInstead { #[primary_span] - #[suggestion(style = "short", applicability = "machine-applicable", code = "=")] pub span: Span, + #[suggestion(style = "verbose", applicability = "machine-applicable", code = "")] + pub suggestion: Span, } #[derive(Diagnostic)] @@ -780,7 +829,7 @@ pub(crate) struct InclusiveRangeExtraEquals { #[primary_span] #[suggestion( parse_suggestion_remove_eq, - style = "short", + style = "verbose", code = "..=", applicability = "maybe-incorrect" )] @@ -803,13 +852,14 @@ pub(crate) struct InclusiveRangeMatchArrow { #[note] pub(crate) struct InclusiveRangeNoEnd { #[primary_span] + pub span: Span, #[suggestion( parse_suggestion_open_range, - code = "..", + code = "", applicability = "machine-applicable", - style = "short" + style = "verbose" )] - pub span: Span, + pub suggestion: Span, } #[derive(Subdiagnostic)] @@ -824,7 +874,8 @@ pub(crate) enum MatchArmBodyWithoutBracesSugg { #[suggestion( parse_suggestion_use_comma_not_semicolon, code = ",", - applicability = "machine-applicable" + applicability = "machine-applicable", + style = "verbose" )] UseComma { #[primary_span] @@ -867,7 +918,7 @@ pub(crate) struct InvalidLiteralSuffixOnTupleIndex { #[diag(parse_non_string_abi_literal)] pub(crate) struct NonStringAbiLiteral { #[primary_span] - #[suggestion(code = "\"C\"", applicability = "maybe-incorrect")] + #[suggestion(code = "\"C\"", applicability = "maybe-incorrect", style = "verbose")] pub span: Span, } @@ -890,7 +941,7 @@ pub(crate) struct MismatchedClosingDelimiter { #[help] pub(crate) struct IncorrectVisibilityRestriction { #[primary_span] - #[suggestion(code = "in {inner_str}", applicability = "machine-applicable")] + #[suggestion(code = "in {inner_str}", applicability = "machine-applicable", style = "verbose")] pub span: Span, pub inner_str: String, } @@ -915,7 +966,7 @@ pub(crate) struct ExpectedStatementAfterOuterAttr { pub(crate) struct DocCommentDoesNotDocumentAnything { #[primary_span] pub span: Span, - #[suggestion(code = ",", applicability = "machine-applicable")] + #[suggestion(code = ",", applicability = "machine-applicable", style = "verbose")] pub missing_comma: Option, } @@ -923,7 +974,7 @@ pub(crate) struct DocCommentDoesNotDocumentAnything { #[diag(parse_const_let_mutually_exclusive)] pub(crate) struct ConstLetMutuallyExclusive { #[primary_span] - #[suggestion(code = "const", applicability = "maybe-incorrect")] + #[suggestion(code = "const", applicability = "maybe-incorrect", style = "verbose")] pub span: Span, } @@ -951,8 +1002,9 @@ pub(crate) struct InvalidCurlyInLetElse { #[help] pub(crate) struct CompoundAssignmentExpressionInLet { #[primary_span] - #[suggestion(style = "short", code = "=", applicability = "maybe-incorrect")] pub span: Span, + #[suggestion(style = "verbose", code = "", applicability = "maybe-incorrect")] + pub suggestion: Span, } #[derive(Diagnostic)] @@ -996,7 +1048,12 @@ pub(crate) struct SuggEscapeIdentifier { } #[derive(Subdiagnostic)] -#[suggestion(parse_sugg_remove_comma, applicability = "machine-applicable", code = "")] +#[suggestion( + parse_sugg_remove_comma, + applicability = "machine-applicable", + code = "", + style = "verbose" +)] pub(crate) struct SuggRemoveComma { #[primary_span] pub span: Span, @@ -1147,11 +1204,16 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for ExpectedSemi { #[derive(Subdiagnostic)] pub(crate) enum ExpectedSemiSugg { - #[suggestion(parse_sugg_change_this_to_semi, code = ";", applicability = "machine-applicable")] + #[suggestion( + parse_sugg_change_this_to_semi, + code = ";", + applicability = "machine-applicable", + style = "verbose" + )] ChangeToSemi(#[primary_span] Span), #[suggestion( parse_sugg_add_semi, - style = "short", + style = "verbose", code = ";", applicability = "machine-applicable" )] @@ -1198,7 +1260,7 @@ pub(crate) struct StructLiteralNeedingParensSugg { #[diag(parse_unmatched_angle_brackets)] pub(crate) struct UnmatchedAngleBrackets { #[primary_span] - #[suggestion(code = "", applicability = "machine-applicable")] + #[suggestion(code = "", applicability = "machine-applicable", style = "verbose")] pub span: Span, pub num_extra_brackets: usize, } @@ -1337,7 +1399,7 @@ pub(crate) struct AttributeOnParamType { #[diag(parse_pattern_method_param_without_body, code = E0642)] pub(crate) struct PatternMethodParamWithoutBody { #[primary_span] - #[suggestion(code = "_", applicability = "machine-applicable")] + #[suggestion(code = "_", applicability = "machine-applicable", style = "verbose")] pub span: Span, } @@ -1421,7 +1483,7 @@ pub(crate) struct AsyncMoveOrderIncorrect { pub(crate) struct DoubleColonInBound { #[primary_span] pub span: Span, - #[suggestion(code = ": ", applicability = "machine-applicable")] + #[suggestion(code = ": ", applicability = "machine-applicable", style = "verbose")] pub between: Span, } @@ -1500,7 +1562,7 @@ pub(crate) struct ExpectedFnPathFoundFnKeyword { #[diag(parse_path_single_colon)] pub(crate) struct PathSingleColon { #[primary_span] - #[suggestion(applicability = "machine-applicable", code = "::")] + #[suggestion(applicability = "machine-applicable", code = "::", style = "verbose")] pub span: Span, #[note(parse_type_ascription_removed)] @@ -1511,7 +1573,7 @@ pub(crate) struct PathSingleColon { #[diag(parse_colon_as_semi)] pub(crate) struct ColonAsSemi { #[primary_span] - #[suggestion(applicability = "machine-applicable", code = ";")] + #[suggestion(applicability = "machine-applicable", code = ";", style = "verbose")] pub span: Span, #[note(parse_type_ascription_removed)] @@ -1662,9 +1724,9 @@ pub(crate) enum MissingKeywordForItemDefinition { pub(crate) enum AmbiguousMissingKwForItemSub { #[suggestion( parse_suggestion, - style = "verbose", applicability = "maybe-incorrect", - code = "{snippet}!" + code = "{snippet}!", + style = "verbose" )] SuggestMacro { #[primary_span] @@ -1679,7 +1741,7 @@ pub(crate) enum AmbiguousMissingKwForItemSub { #[diag(parse_missing_fn_params)] pub(crate) struct MissingFnParams { #[primary_span] - #[suggestion(code = "()", applicability = "machine-applicable", style = "short")] + #[suggestion(code = "()", applicability = "machine-applicable", style = "verbose")] pub span: Span, } @@ -1687,9 +1749,19 @@ pub(crate) struct MissingFnParams { #[diag(parse_missing_trait_in_trait_impl)] pub(crate) struct MissingTraitInTraitImpl { #[primary_span] - #[suggestion(parse_suggestion_add_trait, code = " Trait ", applicability = "has-placeholders")] + #[suggestion( + parse_suggestion_add_trait, + code = " Trait ", + applicability = "has-placeholders", + style = "verbose" + )] pub span: Span, - #[suggestion(parse_suggestion_remove_for, code = "", applicability = "maybe-incorrect")] + #[suggestion( + parse_suggestion_remove_for, + code = "", + applicability = "maybe-incorrect", + style = "verbose" + )] pub for_span: Span, } @@ -1697,7 +1769,7 @@ pub(crate) struct MissingTraitInTraitImpl { #[diag(parse_missing_for_in_trait_impl)] pub(crate) struct MissingForInTraitImpl { #[primary_span] - #[suggestion(style = "short", code = " for ", applicability = "machine-applicable")] + #[suggestion(style = "verbose", code = " for ", applicability = "machine-applicable")] pub span: Span, } @@ -1712,7 +1784,7 @@ pub(crate) struct ExpectedTraitInTraitImplFoundType { #[diag(parse_extra_impl_keyword_in_trait_impl)] pub(crate) struct ExtraImplKeywordInTraitImpl { #[primary_span] - #[suggestion(code = "", applicability = "maybe-incorrect")] + #[suggestion(code = "", applicability = "maybe-incorrect", style = "verbose")] pub extra_impl_kw: Span, #[note] pub impl_trait_span: Span, @@ -1771,7 +1843,7 @@ pub(crate) struct ExternCrateNameWithDashesSugg { pub(crate) struct ExternItemCannotBeConst { #[primary_span] pub ident_span: Span, - #[suggestion(code = "static ", applicability = "machine-applicable")] + #[suggestion(code = "static ", applicability = "machine-applicable", style = "verbose")] pub const_span: Option, } @@ -1781,7 +1853,7 @@ pub(crate) struct ConstGlobalCannotBeMutable { #[primary_span] #[label] pub ident_span: Span, - #[suggestion(code = "static", applicability = "maybe-incorrect")] + #[suggestion(code = "static", style = "verbose", applicability = "maybe-incorrect")] pub const_span: Span, } @@ -1789,7 +1861,7 @@ pub(crate) struct ConstGlobalCannotBeMutable { #[diag(parse_missing_const_type)] pub(crate) struct MissingConstType { #[primary_span] - #[suggestion(code = "{colon} ", applicability = "has-placeholders")] + #[suggestion(code = "{colon} ", style = "verbose", applicability = "has-placeholders")] pub span: Span, pub kind: &'static str, @@ -1800,7 +1872,7 @@ pub(crate) struct MissingConstType { #[diag(parse_enum_struct_mutually_exclusive)] pub(crate) struct EnumStructMutuallyExclusive { #[primary_span] - #[suggestion(code = "enum", applicability = "machine-applicable")] + #[suggestion(code = "enum", style = "verbose", applicability = "machine-applicable")] pub span: Span, } @@ -2037,7 +2109,12 @@ pub struct UnknownTokenStart { #[derive(Subdiagnostic)] pub enum TokenSubstitution { - #[suggestion(parse_sugg_quotes, code = "{suggestion}", applicability = "maybe-incorrect")] + #[suggestion( + parse_sugg_quotes, + code = "{suggestion}", + applicability = "maybe-incorrect", + style = "verbose" + )] DirectedQuotes { #[primary_span] span: Span, @@ -2045,7 +2122,12 @@ pub enum TokenSubstitution { ascii_str: &'static str, ascii_name: &'static str, }, - #[suggestion(parse_sugg_other, code = "{suggestion}", applicability = "maybe-incorrect")] + #[suggestion( + parse_sugg_other, + code = "{suggestion}", + applicability = "maybe-incorrect", + style = "verbose" + )] Other { #[primary_span] span: Span, @@ -2081,7 +2163,12 @@ pub enum UnescapeError { EscapeOnlyChar { #[primary_span] span: Span, - #[suggestion(parse_escape, applicability = "machine-applicable", code = "{escaped_sugg}")] + #[suggestion( + parse_escape, + applicability = "machine-applicable", + code = "{escaped_sugg}", + style = "verbose" + )] char_span: Span, escaped_sugg: String, escaped_msg: String, @@ -2090,7 +2177,12 @@ pub enum UnescapeError { #[diag(parse_bare_cr)] BareCr { #[primary_span] - #[suggestion(parse_escape, applicability = "machine-applicable", code = "\\r")] + #[suggestion( + parse_escape, + applicability = "machine-applicable", + code = "\\r", + style = "verbose" + )] span: Span, double_quotes: bool, }, @@ -2207,7 +2299,8 @@ pub enum MoreThanOneCharSugg { #[suggestion( parse_consider_normalized, code = "{normalized}", - applicability = "machine-applicable" + applicability = "machine-applicable", + style = "verbose" )] NormalizedForm { #[primary_span] @@ -2215,13 +2308,23 @@ pub enum MoreThanOneCharSugg { ch: String, normalized: String, }, - #[suggestion(parse_remove_non, code = "{ch}", applicability = "maybe-incorrect")] + #[suggestion( + parse_remove_non, + code = "{ch}", + applicability = "maybe-incorrect", + style = "verbose" + )] RemoveNonPrinting { #[primary_span] span: Span, ch: String, }, - #[suggestion(parse_use_double_quotes, code = "{sugg}", applicability = "machine-applicable")] + #[suggestion( + parse_use_double_quotes, + code = "{sugg}", + applicability = "machine-applicable", + style = "verbose" + )] QuotesFull { #[primary_span] span: Span, @@ -2259,7 +2362,12 @@ pub enum MoreThanOneCharNote { #[derive(Subdiagnostic)] pub enum NoBraceUnicodeSub { - #[suggestion(parse_use_braces, code = "{suggestion}", applicability = "maybe-incorrect")] + #[suggestion( + parse_use_braces, + code = "{suggestion}", + applicability = "maybe-incorrect", + style = "verbose" + )] Suggestion { #[primary_span] span: Span, @@ -2269,27 +2377,32 @@ pub enum NoBraceUnicodeSub { Help, } +#[derive(Subdiagnostic)] +#[multipart_suggestion(parse_sugg_wrap_pattern_in_parens, applicability = "machine-applicable")] +pub(crate) struct WrapInParens { + #[suggestion_part(code = "(")] + pub(crate) lo: Span, + #[suggestion_part(code = ")")] + pub(crate) hi: Span, +} + #[derive(Subdiagnostic)] pub(crate) enum TopLevelOrPatternNotAllowedSugg { #[suggestion( parse_sugg_remove_leading_vert_in_pattern, - code = "{pat}", - applicability = "machine-applicable" + code = "", + applicability = "machine-applicable", + style = "verbose" )] RemoveLeadingVert { #[primary_span] span: Span, - pat: String, }, - #[suggestion( - parse_sugg_wrap_pattern_in_parens, - code = "({pat})", - applicability = "machine-applicable" - )] WrapInParens { #[primary_span] span: Span, - pat: String, + #[subdiagnostic] + suggestion: WrapInParens, }, } @@ -2298,7 +2411,7 @@ pub(crate) enum TopLevelOrPatternNotAllowedSugg { #[note(parse_note_pattern_alternatives_use_single_vert)] pub(crate) struct UnexpectedVertVertBeforeFunctionParam { #[primary_span] - #[suggestion(code = "", applicability = "machine-applicable")] + #[suggestion(code = "", applicability = "machine-applicable", style = "verbose")] pub span: Span, } @@ -2306,7 +2419,7 @@ pub(crate) struct UnexpectedVertVertBeforeFunctionParam { #[diag(parse_unexpected_vert_vert_in_pattern)] pub(crate) struct UnexpectedVertVertInPattern { #[primary_span] - #[suggestion(code = "|", applicability = "machine-applicable")] + #[suggestion(code = "|", applicability = "machine-applicable", style = "verbose")] pub span: Span, #[label(parse_label_while_parsing_or_pattern_here)] pub start: Option, @@ -2316,7 +2429,7 @@ pub(crate) struct UnexpectedVertVertInPattern { #[diag(parse_trailing_vert_not_allowed)] pub(crate) struct TrailingVertNotAllowed { #[primary_span] - #[suggestion(code = "", applicability = "machine-applicable")] + #[suggestion(code = "", applicability = "machine-applicable", style = "verbose")] pub span: Span, #[label(parse_label_while_parsing_or_pattern_here)] pub start: Option, @@ -2329,16 +2442,17 @@ pub(crate) struct TrailingVertNotAllowed { #[diag(parse_dotdotdot_rest_pattern)] pub(crate) struct DotDotDotRestPattern { #[primary_span] - #[suggestion(style = "short", code = "..", applicability = "machine-applicable")] #[label] pub span: Span, + #[suggestion(style = "verbose", code = "", applicability = "machine-applicable")] + pub suggestion: Span, } #[derive(Diagnostic)] #[diag(parse_pattern_on_wrong_side_of_at)] pub(crate) struct PatternOnWrongSideOfAt { #[primary_span] - #[suggestion(code = "{whole_pat}", applicability = "machine-applicable")] + #[suggestion(code = "{whole_pat}", applicability = "machine-applicable", style = "verbose")] pub whole_span: Span, pub whole_pat: String, #[label(parse_label_pattern)] @@ -2359,22 +2473,35 @@ pub(crate) struct ExpectedBindingLeftOfAt { pub rhs: Span, } +#[derive(Subdiagnostic)] +#[multipart_suggestion( + parse_ambiguous_range_pattern_suggestion, + applicability = "machine-applicable" +)] +pub(crate) struct ParenRangeSuggestion { + #[suggestion_part(code = "(")] + pub lo: Span, + #[suggestion_part(code = ")")] + pub hi: Span, +} + #[derive(Diagnostic)] #[diag(parse_ambiguous_range_pattern)] pub(crate) struct AmbiguousRangePattern { #[primary_span] - #[suggestion(code = "({pat})", applicability = "maybe-incorrect")] pub span: Span, - pub pat: String, + #[subdiagnostic] + pub suggestion: ParenRangeSuggestion, } #[derive(Diagnostic)] #[diag(parse_unexpected_lifetime_in_pattern)] pub(crate) struct UnexpectedLifetimeInPattern { #[primary_span] - #[suggestion(code = "", applicability = "machine-applicable")] pub span: Span, pub symbol: Symbol, + #[suggestion(code = "", applicability = "machine-applicable", style = "verbose")] + pub suggestion: Span, } #[derive(Diagnostic)] @@ -2383,7 +2510,7 @@ pub(crate) enum InvalidMutInPattern { #[note(parse_note_mut_pattern_usage)] NestedIdent { #[primary_span] - #[suggestion(code = "{pat}", applicability = "machine-applicable")] + #[suggestion(code = "{pat}", applicability = "machine-applicable", style = "verbose")] span: Span, pat: String, }, @@ -2391,7 +2518,7 @@ pub(crate) enum InvalidMutInPattern { #[note(parse_note_mut_pattern_usage)] NonIdent { #[primary_span] - #[suggestion(code = "", applicability = "machine-applicable")] + #[suggestion(code = "", applicability = "machine-applicable", style = "verbose")] span: Span, }, } @@ -2400,7 +2527,7 @@ pub(crate) enum InvalidMutInPattern { #[diag(parse_repeated_mut_in_pattern)] pub(crate) struct RepeatedMutInPattern { #[primary_span] - #[suggestion(code = "", applicability = "machine-applicable")] + #[suggestion(code = "", applicability = "machine-applicable", style = "verbose")] pub span: Span, } @@ -2408,7 +2535,7 @@ pub(crate) struct RepeatedMutInPattern { #[diag(parse_dot_dot_dot_range_to_pattern_not_allowed)] pub(crate) struct DotDotDotRangeToPatternNotAllowed { #[primary_span] - #[suggestion(style = "short", code = "..=", applicability = "machine-applicable")] + #[suggestion(style = "verbose", code = "..=", applicability = "machine-applicable")] pub span: Span, } @@ -2472,8 +2599,9 @@ pub(crate) struct UnexpectedParenInRangePatSugg { #[diag(parse_return_types_use_thin_arrow)] pub(crate) struct ReturnTypesUseThinArrow { #[primary_span] - #[suggestion(style = "short", code = "->", applicability = "machine-applicable")] pub span: Span, + #[suggestion(style = "verbose", code = " -> ", applicability = "machine-applicable")] + pub suggestion: Span, } #[derive(Diagnostic)] @@ -2488,7 +2616,7 @@ pub(crate) struct NeedPlusAfterTraitObjectLifetime { pub(crate) struct ExpectedMutOrConstInRawPointerType { #[primary_span] pub span: Span, - #[suggestion(code("mut ", "const "), applicability = "has-placeholders")] + #[suggestion(code("mut ", "const "), applicability = "has-placeholders", style = "verbose")] pub after_asterisk: Span, } @@ -2497,7 +2625,7 @@ pub(crate) struct ExpectedMutOrConstInRawPointerType { pub(crate) struct LifetimeAfterMut { #[primary_span] pub span: Span, - #[suggestion(code = "&{snippet} mut", applicability = "maybe-incorrect")] + #[suggestion(code = "&{snippet} mut", applicability = "maybe-incorrect", style = "verbose")] pub suggest_lifetime: Option, pub snippet: String, } @@ -2506,7 +2634,7 @@ pub(crate) struct LifetimeAfterMut { #[diag(parse_dyn_after_mut)] pub(crate) struct DynAfterMut { #[primary_span] - #[suggestion(code = "&mut dyn", applicability = "machine-applicable")] + #[suggestion(code = "&mut dyn", applicability = "machine-applicable", style = "verbose")] pub span: Span, } @@ -2515,7 +2643,7 @@ pub(crate) struct DynAfterMut { pub(crate) struct FnPointerCannotBeConst { #[primary_span] pub span: Span, - #[suggestion(code = "", applicability = "maybe-incorrect")] + #[suggestion(code = "", applicability = "maybe-incorrect", style = "verbose")] #[label] pub qualifier: Span, } @@ -2525,7 +2653,7 @@ pub(crate) struct FnPointerCannotBeConst { pub(crate) struct FnPointerCannotBeAsync { #[primary_span] pub span: Span, - #[suggestion(code = "", applicability = "maybe-incorrect")] + #[suggestion(code = "", applicability = "maybe-incorrect", style = "verbose")] #[label] pub qualifier: Span, } @@ -2542,8 +2670,9 @@ pub(crate) struct NestedCVariadicType { #[help] pub(crate) struct InvalidDynKeyword { #[primary_span] - #[suggestion(code = "", applicability = "machine-applicable")] pub span: Span, + #[suggestion(code = "", applicability = "machine-applicable", style = "verbose")] + pub suggestion: Span, } #[derive(Subdiagnostic)] @@ -2584,7 +2713,7 @@ pub struct BoxSyntaxRemoved<'a> { #[diag(parse_bad_return_type_notation_output)] pub(crate) struct BadReturnTypeNotationOutput { #[primary_span] - #[suggestion(code = "", applicability = "maybe-incorrect")] + #[suggestion(code = "", applicability = "maybe-incorrect", style = "verbose")] pub span: Span, } @@ -2655,14 +2784,25 @@ pub(crate) struct ModifierLifetime { pub modifier: &'static str, } +#[derive(Subdiagnostic)] +#[multipart_suggestion( + parse_parenthesized_lifetime_suggestion, + applicability = "machine-applicable" +)] +pub(crate) struct RemoveParens { + #[suggestion_part(code = "")] + pub lo: Span, + #[suggestion_part(code = "")] + pub hi: Span, +} + #[derive(Diagnostic)] #[diag(parse_parenthesized_lifetime)] pub(crate) struct ParenthesizedLifetime { #[primary_span] pub span: Span, - #[suggestion(style = "short", applicability = "machine-applicable", code = "{snippet}")] - pub sugg: Option, - pub snippet: String, + #[subdiagnostic] + pub sugg: RemoveParens, } #[derive(Diagnostic)] @@ -2677,7 +2817,7 @@ pub(crate) struct UnderscoreLiteralSuffix { pub(crate) struct ExpectedLabelFoundIdent { #[primary_span] pub span: Span, - #[suggestion(code = "'", applicability = "machine-applicable", style = "short")] + #[suggestion(code = "'", applicability = "machine-applicable", style = "verbose")] pub start: Span, } @@ -2696,7 +2836,7 @@ pub(crate) struct InappropriateDefault { #[diag(parse_recover_import_as_use)] pub(crate) struct RecoverImportAsUse { #[primary_span] - #[suggestion(code = "use", applicability = "machine-applicable", style = "short")] + #[suggestion(code = "use", applicability = "machine-applicable", style = "verbose")] pub span: Span, pub token_name: String, } @@ -2706,7 +2846,7 @@ pub(crate) struct RecoverImportAsUse { #[note] pub(crate) struct SingleColonImportPath { #[primary_span] - #[suggestion(code = "::", applicability = "machine-applicable", style = "short")] + #[suggestion(code = "::", applicability = "machine-applicable", style = "verbose")] pub span: Span, } @@ -2733,7 +2873,7 @@ pub(crate) struct SingleColonStructType { #[diag(parse_equals_struct_default)] pub(crate) struct EqualsStructDefault { #[primary_span] - #[suggestion(code = "", applicability = "machine-applicable")] + #[suggestion(code = "", applicability = "machine-applicable", style = "verbose")] pub span: Span, } @@ -2750,7 +2890,7 @@ pub(crate) struct MacroRulesMissingBang { #[diag(parse_macro_name_remove_bang)] pub(crate) struct MacroNameRemoveBang { #[primary_span] - #[suggestion(code = "", applicability = "machine-applicable")] + #[suggestion(code = "", applicability = "machine-applicable", style = "verbose")] pub span: Span, } @@ -2758,7 +2898,7 @@ pub(crate) struct MacroNameRemoveBang { #[diag(parse_macro_rules_visibility)] pub(crate) struct MacroRulesVisibility<'a> { #[primary_span] - #[suggestion(code = "#[macro_export]", applicability = "maybe-incorrect")] + #[suggestion(code = "#[macro_export]", applicability = "maybe-incorrect", style = "verbose")] pub span: Span, pub vis: &'a str, } @@ -2768,7 +2908,7 @@ pub(crate) struct MacroRulesVisibility<'a> { #[help] pub(crate) struct MacroInvocationVisibility<'a> { #[primary_span] - #[suggestion(code = "", applicability = "machine-applicable")] + #[suggestion(code = "", applicability = "machine-applicable", style = "verbose")] pub span: Span, pub vis: &'a str, } @@ -2778,7 +2918,7 @@ pub(crate) struct MacroInvocationVisibility<'a> { pub(crate) struct NestedAdt<'a> { #[primary_span] pub span: Span, - #[suggestion(code = "", applicability = "maybe-incorrect")] + #[suggestion(code = "", applicability = "maybe-incorrect", style = "verbose")] pub item: Span, pub keyword: &'a str, pub kw_str: Cow<'a, str>, @@ -2818,7 +2958,7 @@ pub(crate) struct BoxNotPat { #[diag(parse_unmatched_angle)] pub(crate) struct UnmatchedAngle { #[primary_span] - #[suggestion(code = "", applicability = "machine-applicable")] + #[suggestion(code = "", applicability = "machine-applicable", style = "verbose")] pub span: Span, pub plural: bool, } @@ -2858,7 +2998,7 @@ pub(crate) struct IncorrectParensTraitBoundsSugg { #[diag(parse_kw_bad_case)] pub(crate) struct KwBadCase<'a> { #[primary_span] - #[suggestion(code = "{kw}", applicability = "machine-applicable")] + #[suggestion(code = "{kw}", style = "verbose", applicability = "machine-applicable")] pub span: Span, pub kw: &'a str, } @@ -2895,7 +3035,7 @@ pub(crate) struct MetaBadDelimSugg { #[note] pub(crate) struct MalformedCfgAttr { #[primary_span] - #[suggestion(code = "{sugg}")] + #[suggestion(style = "verbose", code = "{sugg}")] pub span: Span, pub sugg: &'static str, } @@ -3000,7 +3140,7 @@ pub(crate) struct AsyncImpl { #[help] pub(crate) struct ExprRArrowCall { #[primary_span] - #[suggestion(style = "short", applicability = "machine-applicable", code = ".")] + #[suggestion(style = "verbose", applicability = "machine-applicable", code = ".")] pub span: Span, } -- cgit 1.4.1-3-g733a5 From c2b3287483fb7fc1be7fdfbfd25044dd7a0320c0 Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Thu, 11 Jul 2024 21:04:01 +0000 Subject: Make `impl` and `!` removal suggestion `short` --- compiler/rustc_parse/src/errors.rs | 4 ++-- tests/ui/impl-trait/extra-impl-in-trait-impl.stderr | 14 ++------------ tests/ui/macros/bang-after-name.stderr | 8 +------- tests/ui/macros/missing-bang-in-decl.stderr | 8 +------- 4 files changed, 6 insertions(+), 28 deletions(-) (limited to 'compiler/rustc_parse/src/errors.rs') diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 0f13a8e5e14..d2a765247ad 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -1784,7 +1784,7 @@ pub(crate) struct ExpectedTraitInTraitImplFoundType { #[diag(parse_extra_impl_keyword_in_trait_impl)] pub(crate) struct ExtraImplKeywordInTraitImpl { #[primary_span] - #[suggestion(code = "", applicability = "maybe-incorrect", style = "verbose")] + #[suggestion(code = "", applicability = "maybe-incorrect", style = "short")] pub extra_impl_kw: Span, #[note] pub impl_trait_span: Span, @@ -2890,7 +2890,7 @@ pub(crate) struct MacroRulesMissingBang { #[diag(parse_macro_name_remove_bang)] pub(crate) struct MacroNameRemoveBang { #[primary_span] - #[suggestion(code = "", applicability = "machine-applicable", style = "verbose")] + #[suggestion(code = "", applicability = "machine-applicable", style = "short")] pub span: Span, } diff --git a/tests/ui/impl-trait/extra-impl-in-trait-impl.stderr b/tests/ui/impl-trait/extra-impl-in-trait-impl.stderr index e4d14c4807c..91c7da5a04f 100644 --- a/tests/ui/impl-trait/extra-impl-in-trait-impl.stderr +++ b/tests/ui/impl-trait/extra-impl-in-trait-impl.stderr @@ -2,35 +2,25 @@ error: unexpected `impl` keyword --> $DIR/extra-impl-in-trait-impl.rs:8:18 | LL | impl impl Default for S { - | ^^^^^ + | ^^^^^ help: remove the extra `impl` | note: this is parsed as an `impl Trait` type, but a trait is expected at this position --> $DIR/extra-impl-in-trait-impl.rs:8:18 | LL | impl impl Default for S { | ^^^^^^^^^^^^ -help: remove the extra `impl` - | -LL - impl impl Default for S { -LL + impl Default for S { - | error: unexpected `impl` keyword --> $DIR/extra-impl-in-trait-impl.rs:14:6 | LL | impl impl Default for S2 { - | ^^^^^ + | ^^^^^ help: remove the extra `impl` | note: this is parsed as an `impl Trait` type, but a trait is expected at this position --> $DIR/extra-impl-in-trait-impl.rs:14:6 | LL | impl impl Default for S2 { | ^^^^^^^^^^^^ -help: remove the extra `impl` - | -LL - impl impl Default for S2 { -LL + impl Default for S2 { - | error: aborting due to 2 previous errors diff --git a/tests/ui/macros/bang-after-name.stderr b/tests/ui/macros/bang-after-name.stderr index 8433c375c01..27853161e4f 100644 --- a/tests/ui/macros/bang-after-name.stderr +++ b/tests/ui/macros/bang-after-name.stderr @@ -2,13 +2,7 @@ error: macro names aren't followed by a `!` --> $DIR/bang-after-name.rs:4:17 | LL | macro_rules! foo! { - | ^ - | -help: remove the `!` - | -LL - macro_rules! foo! { -LL + macro_rules! foo { - | + | ^ help: remove the `!` error: aborting due to 1 previous error diff --git a/tests/ui/macros/missing-bang-in-decl.stderr b/tests/ui/macros/missing-bang-in-decl.stderr index 348a94ec2c0..aa78c9a6906 100644 --- a/tests/ui/macros/missing-bang-in-decl.stderr +++ b/tests/ui/macros/missing-bang-in-decl.stderr @@ -24,13 +24,7 @@ error: macro names aren't followed by a `!` --> $DIR/missing-bang-in-decl.rs:10:16 | LL | macro_rules bar! { - | ^ - | -help: remove the `!` - | -LL - macro_rules bar! { -LL + macro_rules bar { - | + | ^ help: remove the `!` error: aborting due to 3 previous errors -- cgit 1.4.1-3-g733a5 From b5f94c61f72cc85151dbd9bb1081fde2ab78f806 Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Thu, 11 Jul 2024 22:03:08 +0000 Subject: Use more accurate span for `:` to `::` suggestion --- compiler/rustc_parse/src/errors.rs | 4 +++- compiler/rustc_parse/src/parser/path.rs | 2 ++ tests/ui/generics/single-colon-path-not-const-generics.stderr | 2 +- tests/ui/suggestions/type-ascription-instead-of-method.stderr | 2 +- tests/ui/suggestions/type-ascription-instead-of-path.stderr | 2 +- tests/ui/suggestions/type-ascription-instead-of-variant.stderr | 2 +- tests/ui/type/ascription/issue-47666.stderr | 2 +- tests/ui/type/ascription/issue-54516.stderr | 2 +- tests/ui/type/ascription/issue-60933.stderr | 2 +- 9 files changed, 12 insertions(+), 8 deletions(-) (limited to 'compiler/rustc_parse/src/errors.rs') diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index d2a765247ad..18a3153bcd4 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -1562,9 +1562,11 @@ pub(crate) struct ExpectedFnPathFoundFnKeyword { #[diag(parse_path_single_colon)] pub(crate) struct PathSingleColon { #[primary_span] - #[suggestion(applicability = "machine-applicable", code = "::", style = "verbose")] pub span: Span, + #[suggestion(applicability = "machine-applicable", code = ":", style = "verbose")] + pub suggestion: Span, + #[note(parse_type_ascription_removed)] pub type_ascription: Option<()>, } diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index 03c647dd527..b9014dea726 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -258,6 +258,7 @@ impl<'a> Parser<'a> { self.bump(); // bump past the colon self.dcx().emit_err(PathSingleColon { span: self.prev_token.span, + suggestion: self.prev_token.span.shrink_to_hi(), type_ascription: self .psess .unstable_features @@ -329,6 +330,7 @@ impl<'a> Parser<'a> { err.cancel(); err = self.dcx().create_err(PathSingleColon { span: self.token.span, + suggestion: self.prev_token.span.shrink_to_hi(), type_ascription: self .psess .unstable_features diff --git a/tests/ui/generics/single-colon-path-not-const-generics.stderr b/tests/ui/generics/single-colon-path-not-const-generics.stderr index 06203b5e6fe..4e695b2dcd6 100644 --- a/tests/ui/generics/single-colon-path-not-const-generics.stderr +++ b/tests/ui/generics/single-colon-path-not-const-generics.stderr @@ -10,7 +10,7 @@ LL | a: Vec, help: use a double colon instead | LL | a: Vec, - | ~~ + | + error: aborting due to 1 previous error diff --git a/tests/ui/suggestions/type-ascription-instead-of-method.stderr b/tests/ui/suggestions/type-ascription-instead-of-method.stderr index 06f806b9016..0bef1c185db 100644 --- a/tests/ui/suggestions/type-ascription-instead-of-method.stderr +++ b/tests/ui/suggestions/type-ascription-instead-of-method.stderr @@ -8,7 +8,7 @@ LL | let _ = Box:new("foo".to_string()); help: use a double colon instead | LL | let _ = Box::new("foo".to_string()); - | ~~ + | + error: aborting due to 1 previous error diff --git a/tests/ui/suggestions/type-ascription-instead-of-path.stderr b/tests/ui/suggestions/type-ascription-instead-of-path.stderr index 9b09a60c161..8c16acff799 100644 --- a/tests/ui/suggestions/type-ascription-instead-of-path.stderr +++ b/tests/ui/suggestions/type-ascription-instead-of-path.stderr @@ -8,7 +8,7 @@ LL | std:io::stdin(); help: use a double colon instead | LL | std::io::stdin(); - | ~~ + | + error: aborting due to 1 previous error diff --git a/tests/ui/suggestions/type-ascription-instead-of-variant.stderr b/tests/ui/suggestions/type-ascription-instead-of-variant.stderr index 0ecdc82b541..f0b31722e40 100644 --- a/tests/ui/suggestions/type-ascription-instead-of-variant.stderr +++ b/tests/ui/suggestions/type-ascription-instead-of-variant.stderr @@ -8,7 +8,7 @@ LL | let _ = Option:Some(""); help: use a double colon instead | LL | let _ = Option::Some(""); - | ~~ + | + error: aborting due to 1 previous error diff --git a/tests/ui/type/ascription/issue-47666.stderr b/tests/ui/type/ascription/issue-47666.stderr index d76d591ec33..fd825e86675 100644 --- a/tests/ui/type/ascription/issue-47666.stderr +++ b/tests/ui/type/ascription/issue-47666.stderr @@ -8,7 +8,7 @@ LL | let _ = Option:Some(vec![0, 1]); help: use a double colon instead | LL | let _ = Option::Some(vec![0, 1]); - | ~~ + | + error: aborting due to 1 previous error diff --git a/tests/ui/type/ascription/issue-54516.stderr b/tests/ui/type/ascription/issue-54516.stderr index bea2c0d85b3..64fdc1fa24a 100644 --- a/tests/ui/type/ascription/issue-54516.stderr +++ b/tests/ui/type/ascription/issue-54516.stderr @@ -8,7 +8,7 @@ LL | println!("{}", std::mem:size_of::>()); help: use a double colon instead | LL | println!("{}", std::mem::size_of::>()); - | ~~ + | + error: aborting due to 1 previous error diff --git a/tests/ui/type/ascription/issue-60933.stderr b/tests/ui/type/ascription/issue-60933.stderr index a81238bd540..c68394d0504 100644 --- a/tests/ui/type/ascription/issue-60933.stderr +++ b/tests/ui/type/ascription/issue-60933.stderr @@ -8,7 +8,7 @@ LL | let _: usize = std::mem:size_of::(); help: use a double colon instead | LL | let _: usize = std::mem::size_of::(); - | ~~ + | + error: aborting due to 1 previous error -- cgit 1.4.1-3-g733a5 From 377d14be88200d122f699aa989e4d1256f2173d2 Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Thu, 11 Jul 2024 22:07:11 +0000 Subject: More accurate incorrect use of `await` suggestion --- compiler/rustc_parse/messages.ftl | 6 +- compiler/rustc_parse/src/errors.rs | 23 ++++--- compiler/rustc_parse/src/parser/diagnostics.rs | 18 ++--- .../incorrect-syntax-suggestions.stderr | 80 +++++++++++++--------- tests/ui/parser/issues/issue-113203.stderr | 5 +- 5 files changed, 76 insertions(+), 56 deletions(-) (limited to 'compiler/rustc_parse/src/errors.rs') diff --git a/compiler/rustc_parse/messages.ftl b/compiler/rustc_parse/messages.ftl index fd96d95bc2e..c2201b1c41e 100644 --- a/compiler/rustc_parse/messages.ftl +++ b/compiler/rustc_parse/messages.ftl @@ -323,10 +323,10 @@ parse_incorrect_semicolon = .suggestion = remove this semicolon .help = {$name} declarations are not followed by a semicolon -parse_incorrect_use_of_await = - incorrect use of `await` +parse_incorrect_use_of_await = incorrect use of `await` .parentheses_suggestion = `await` is not a method call, remove the parentheses - .postfix_suggestion = `await` is a postfix operation + +parse_incorrect_use_of_await_postfix_suggestion = `await` is a postfix operation parse_incorrect_visibility_restriction = incorrect visibility restriction .help = some possible visibility restrictions are: diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 18a3153bcd4..eee17a73acf 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -103,19 +103,26 @@ pub(crate) struct IncorrectUseOfAwait { pub span: Span, } +#[derive(Subdiagnostic)] +#[multipart_suggestion( + parse_incorrect_use_of_await_postfix_suggestion, + applicability = "machine-applicable" +)] +pub(crate) struct AwaitSuggestion { + #[suggestion_part(code = "")] + pub removal: Span, + #[suggestion_part(code = ".await{question_mark}")] + pub dot_await: Span, + pub question_mark: &'static str, +} + #[derive(Diagnostic)] #[diag(parse_incorrect_use_of_await)] pub(crate) struct IncorrectAwait { #[primary_span] pub span: Span, - #[suggestion( - parse_postfix_suggestion, - style = "verbose", - code = "{expr}.await{question_mark}" - )] - pub sugg_span: (Span, Applicability), - pub expr: String, - pub question_mark: &'static str, + #[subdiagnostic] + pub suggestion: AwaitSuggestion, } #[derive(Diagnostic)] diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 63e4d8a4352..39f1d4e89ec 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -3,8 +3,8 @@ use super::{ BlockMode, CommaRecoveryMode, Parser, PathStyle, Restrictions, SemiColonMode, SeqSep, TokenType, }; use crate::errors::{ - AddParen, AmbiguousPlus, AsyncMoveBlockIn2015, AttributeOnParamType, BadQPathStage2, - BadTypePlus, BadTypePlusSub, ColonAsSemi, ComparisonOperatorsCannotBeChained, + AddParen, AmbiguousPlus, AsyncMoveBlockIn2015, AttributeOnParamType, AwaitSuggestion, + BadQPathStage2, BadTypePlus, BadTypePlusSub, ColonAsSemi, ComparisonOperatorsCannotBeChained, ComparisonOperatorsCannotBeChainedSugg, ConstGenericWithoutBraces, ConstGenericWithoutBracesSugg, DocCommentDoesNotDocumentAnything, DocCommentOnParamType, DoubleColonInBound, ExpectedIdentifier, ExpectedSemi, ExpectedSemiSugg, @@ -1959,18 +1959,14 @@ impl<'a> Parser<'a> { is_question: bool, ) -> (Span, ErrorGuaranteed) { let span = lo.to(hi); - let applicability = match expr.kind { - ExprKind::Try(_) => Applicability::MaybeIncorrect, // `await ?` - _ => Applicability::MachineApplicable, - }; - let guar = self.dcx().emit_err(IncorrectAwait { span, - sugg_span: (span, applicability), - expr: self.span_to_snippet(expr.span).unwrap_or_else(|_| pprust::expr_to_string(expr)), - question_mark: if is_question { "?" } else { "" }, + suggestion: AwaitSuggestion { + removal: lo.until(expr.span), + dot_await: expr.span.shrink_to_hi(), + question_mark: if is_question { "?" } else { "" }, + }, }); - (span, guar) } diff --git a/tests/ui/async-await/await-keyword/incorrect-syntax-suggestions.stderr b/tests/ui/async-await/await-keyword/incorrect-syntax-suggestions.stderr index ac1bc693fab..0ccde7d8709 100644 --- a/tests/ui/async-await/await-keyword/incorrect-syntax-suggestions.stderr +++ b/tests/ui/async-await/await-keyword/incorrect-syntax-suggestions.stderr @@ -6,8 +6,9 @@ LL | let _ = await bar(); | help: `await` is a postfix operation | -LL | let _ = bar().await; - | ~~~~~~~~~~~ +LL - let _ = await bar(); +LL + let _ = bar().await; + | error: incorrect use of `await` --> $DIR/incorrect-syntax-suggestions.rs:12:13 @@ -17,8 +18,9 @@ LL | let _ = await? bar(); | help: `await` is a postfix operation | -LL | let _ = bar().await?; - | ~~~~~~~~~~~~ +LL - let _ = await? bar(); +LL + let _ = bar().await?; + | error: incorrect use of `await` --> $DIR/incorrect-syntax-suggestions.rs:16:13 @@ -28,8 +30,9 @@ LL | let _ = await bar()?; | help: `await` is a postfix operation | -LL | let _ = bar()?.await; - | ~~~~~~~~~~~~ +LL - let _ = await bar()?; +LL + let _ = bar()?.await; + | error: incorrect use of `await` --> $DIR/incorrect-syntax-suggestions.rs:20:13 @@ -39,8 +42,9 @@ LL | let _ = await { bar() }; | help: `await` is a postfix operation | -LL | let _ = { bar() }.await; - | ~~~~~~~~~~~~~~~ +LL - let _ = await { bar() }; +LL + let _ = { bar() }.await; + | error: incorrect use of `await` --> $DIR/incorrect-syntax-suggestions.rs:24:13 @@ -50,8 +54,9 @@ LL | let _ = await(bar()); | help: `await` is a postfix operation | -LL | let _ = (bar()).await; - | ~~~~~~~~~~~~~ +LL - let _ = await(bar()); +LL + let _ = (bar()).await; + | error: incorrect use of `await` --> $DIR/incorrect-syntax-suggestions.rs:28:13 @@ -61,8 +66,9 @@ LL | let _ = await { bar() }?; | help: `await` is a postfix operation | -LL | let _ = { bar() }.await?; - | ~~~~~~~~~~~~~~~ +LL - let _ = await { bar() }?; +LL + let _ = { bar() }.await?; + | error: incorrect use of `await` --> $DIR/incorrect-syntax-suggestions.rs:32:14 @@ -72,8 +78,9 @@ LL | let _ = (await bar())?; | help: `await` is a postfix operation | -LL | let _ = (bar().await)?; - | ~~~~~~~~~~~ +LL - let _ = (await bar())?; +LL + let _ = (bar().await)?; + | error: incorrect use of `await` --> $DIR/incorrect-syntax-suggestions.rs:36:24 @@ -107,8 +114,9 @@ LL | let _ = await bar(); | help: `await` is a postfix operation | -LL | let _ = bar().await; - | ~~~~~~~~~~~ +LL - let _ = await bar(); +LL + let _ = bar().await; + | error: incorrect use of `await` --> $DIR/incorrect-syntax-suggestions.rs:56:13 @@ -118,8 +126,9 @@ LL | let _ = await? bar(); | help: `await` is a postfix operation | -LL | let _ = bar().await?; - | ~~~~~~~~~~~~ +LL - let _ = await? bar(); +LL + let _ = bar().await?; + | error: incorrect use of `await` --> $DIR/incorrect-syntax-suggestions.rs:60:13 @@ -129,8 +138,9 @@ LL | let _ = await bar()?; | help: `await` is a postfix operation | -LL | let _ = bar()?.await; - | ~~~~~~~~~~~~ +LL - let _ = await bar()?; +LL + let _ = bar()?.await; + | error: incorrect use of `await` --> $DIR/incorrect-syntax-suggestions.rs:64:14 @@ -140,8 +150,9 @@ LL | let _ = (await bar())?; | help: `await` is a postfix operation | -LL | let _ = (bar().await)?; - | ~~~~~~~~~~~ +LL - let _ = (await bar())?; +LL + let _ = (bar().await)?; + | error: incorrect use of `await` --> $DIR/incorrect-syntax-suggestions.rs:68:24 @@ -175,8 +186,9 @@ LL | let _ = await!(bar()); | help: `await` is a postfix operation | -LL | let _ = bar().await; - | ~~~~~~~~~~~ +LL - let _ = await!(bar()); +LL + let _ = bar().await); + | error: incorrect use of `await` --> $DIR/incorrect-syntax-suggestions.rs:105:13 @@ -186,8 +198,9 @@ LL | let _ = await!(bar())?; | help: `await` is a postfix operation | -LL | let _ = bar().await?; - | ~~~~~~~~~~~ +LL - let _ = await!(bar())?; +LL + let _ = bar().await)?; + | error: incorrect use of `await` --> $DIR/incorrect-syntax-suggestions.rs:110:17 @@ -197,8 +210,9 @@ LL | let _ = await!(bar())?; | help: `await` is a postfix operation | -LL | let _ = bar().await?; - | ~~~~~~~~~~~ +LL - let _ = await!(bar())?; +LL + let _ = bar().await)?; + | error: incorrect use of `await` --> $DIR/incorrect-syntax-suggestions.rs:117:17 @@ -208,8 +222,9 @@ LL | let _ = await!(bar())?; | help: `await` is a postfix operation | -LL | let _ = bar().await?; - | ~~~~~~~~~~~ +LL - let _ = await!(bar())?; +LL + let _ = bar().await)?; + | error: expected expression, found `=>` --> $DIR/incorrect-syntax-suggestions.rs:124:25 @@ -227,8 +242,9 @@ LL | match await { await => () } | help: `await` is a postfix operation | -LL | match { await => () }.await - | ~~~~~~~~~~~~~~~~~~~~~ +LL - match await { await => () } +LL + match { await => () }.await + | error: expected one of `.`, `?`, `{`, or an operator, found `}` --> $DIR/incorrect-syntax-suggestions.rs:127:1 diff --git a/tests/ui/parser/issues/issue-113203.stderr b/tests/ui/parser/issues/issue-113203.stderr index f9c8ad91280..1ef20ddf726 100644 --- a/tests/ui/parser/issues/issue-113203.stderr +++ b/tests/ui/parser/issues/issue-113203.stderr @@ -6,8 +6,9 @@ LL | await {}() | help: `await` is a postfix operation | -LL | {}.await() - | ~~~~~~~~ +LL - await {}() +LL + {}.await() + | error: aborting due to 1 previous error -- cgit 1.4.1-3-g733a5 From 71f16bdb32feb33762e5245efa37edac2bde724b Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Fri, 12 Jul 2024 03:22:32 +0000 Subject: Make `;` suggestions inline --- compiler/rustc_parse/src/errors.rs | 6 +- .../ui/let-else/let-else-missing-semicolon.stderr | 14 +---- tests/ui/parser/issues/issue-103425.stderr | 21 +------ tests/ui/parser/issues/issue-118530-ice.stderr | 7 +-- tests/ui/parser/issues/issue-3036.stderr | 7 +-- .../issues/issue-87197-missing-semicolon.stderr | 21 +------ tests/ui/parser/macros-no-semicolon.stderr | 14 +---- tests/ui/parser/raw/raw-str-unbalanced.stderr | 7 +-- .../recover-missing-semi-before-item.stderr | 70 ++++------------------ .../ui/parser/recover/recover-missing-semi.stderr | 14 +---- tests/ui/suggestions/missing-semicolon.stderr | 14 +---- ...suggest-semicolon-for-fn-in-extern-block.stderr | 7 +-- 12 files changed, 32 insertions(+), 170 deletions(-) (limited to 'compiler/rustc_parse/src/errors.rs') diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index eee17a73acf..092a2a10ab7 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -1215,14 +1215,14 @@ pub(crate) enum ExpectedSemiSugg { parse_sugg_change_this_to_semi, code = ";", applicability = "machine-applicable", - style = "verbose" + style = "short" )] ChangeToSemi(#[primary_span] Span), #[suggestion( parse_sugg_add_semi, - style = "verbose", code = ";", - applicability = "machine-applicable" + applicability = "machine-applicable", + style = "short" )] AddSemi(#[primary_span] Span), } diff --git a/tests/ui/let-else/let-else-missing-semicolon.stderr b/tests/ui/let-else/let-else-missing-semicolon.stderr index 778a0e244f8..99029ff33fe 100644 --- a/tests/ui/let-else/let-else-missing-semicolon.stderr +++ b/tests/ui/let-else/let-else-missing-semicolon.stderr @@ -2,27 +2,17 @@ error: expected `;`, found keyword `let` --> $DIR/let-else-missing-semicolon.rs:4:6 | LL | } - | ^ + | ^ help: add `;` here LL | let _ = ""; | --- unexpected token - | -help: add `;` here - | -LL | }; - | + error: expected `;`, found `}` --> $DIR/let-else-missing-semicolon.rs:8:6 | LL | } - | ^ + | ^ help: add `;` here LL | } | - unexpected token - | -help: add `;` here - | -LL | }; - | + error: aborting due to 2 previous errors diff --git a/tests/ui/parser/issues/issue-103425.stderr b/tests/ui/parser/issues/issue-103425.stderr index e7e1b7106b0..0efe3e3ca71 100644 --- a/tests/ui/parser/issues/issue-103425.stderr +++ b/tests/ui/parser/issues/issue-103425.stderr @@ -2,43 +2,28 @@ error: expected `;`, found `5.0` --> $DIR/issue-103425.rs:2:6 | LL | 3 - | ^ + | ^ help: add `;` here LL | LL | 5.0 | --- unexpected token - | -help: add `;` here - | -LL | 3; - | + error: expected `;`, found `3_i8` --> $DIR/issue-103425.rs:8:10 | LL | 2_u32 - | ^ + | ^ help: add `;` here LL | LL | 3_i8 | ---- unexpected token - | -help: add `;` here - | -LL | 2_u32; - | + error: expected `;`, found `5.0` --> $DIR/issue-103425.rs:10:9 | LL | 3_i8 - | ^ + | ^ help: add `;` here LL | LL | 5.0 | --- unexpected token - | -help: add `;` here - | -LL | 3_i8; - | + error: aborting due to 3 previous errors diff --git a/tests/ui/parser/issues/issue-118530-ice.stderr b/tests/ui/parser/issues/issue-118530-ice.stderr index a8a2327d0ce..3519fb8777f 100644 --- a/tests/ui/parser/issues/issue-118530-ice.stderr +++ b/tests/ui/parser/issues/issue-118530-ice.stderr @@ -30,11 +30,8 @@ LL | #[feature] | ---------- only `;` terminated statements or tail expressions are allowed after this attribute LL | attr::fn bar() -> String { | ^--- unexpected token - | -help: add `;` here - | -LL | attr::fn; bar() -> String { - | + + | | + | help: add `;` here error: `->` used for field access or method call --> $DIR/issue-118530-ice.rs:5:20 diff --git a/tests/ui/parser/issues/issue-3036.stderr b/tests/ui/parser/issues/issue-3036.stderr index 62a9c1d9752..3dd89b7e828 100644 --- a/tests/ui/parser/issues/issue-3036.stderr +++ b/tests/ui/parser/issues/issue-3036.stderr @@ -2,14 +2,9 @@ error: expected `;`, found `}` --> $DIR/issue-3036.rs:6:15 | LL | let _x = 3 - | ^ + | ^ help: add `;` here LL | } | - unexpected token - | -help: add `;` here - | -LL | let _x = 3; - | + error: aborting due to 1 previous error diff --git a/tests/ui/parser/issues/issue-87197-missing-semicolon.stderr b/tests/ui/parser/issues/issue-87197-missing-semicolon.stderr index 874e7b07163..57772de1e7a 100644 --- a/tests/ui/parser/issues/issue-87197-missing-semicolon.stderr +++ b/tests/ui/parser/issues/issue-87197-missing-semicolon.stderr @@ -2,40 +2,25 @@ error: expected `;`, found `println` --> $DIR/issue-87197-missing-semicolon.rs:6:16 | LL | let x = 100 - | ^ + | ^ help: add `;` here LL | println!("{}", x) | ------- unexpected token - | -help: add `;` here - | -LL | let x = 100; - | + error: expected `;`, found keyword `let` --> $DIR/issue-87197-missing-semicolon.rs:7:22 | LL | println!("{}", x) - | ^ + | ^ help: add `;` here LL | let y = 200 | --- unexpected token - | -help: add `;` here - | -LL | println!("{}", x); - | + error: expected `;`, found `println` --> $DIR/issue-87197-missing-semicolon.rs:8:16 | LL | let y = 200 - | ^ + | ^ help: add `;` here LL | println!("{}", y); | ------- unexpected token - | -help: add `;` here - | -LL | let y = 200; - | + error: aborting due to 3 previous errors diff --git a/tests/ui/parser/macros-no-semicolon.stderr b/tests/ui/parser/macros-no-semicolon.stderr index 4cf01e457d7..f310662dbb0 100644 --- a/tests/ui/parser/macros-no-semicolon.stderr +++ b/tests/ui/parser/macros-no-semicolon.stderr @@ -2,27 +2,17 @@ error: expected `;`, found `assert_eq` --> $DIR/macros-no-semicolon.rs:2:21 | LL | assert_eq!(1, 2) - | ^ + | ^ help: add `;` here LL | assert_eq!(3, 4) | --------- unexpected token - | -help: add `;` here - | -LL | assert_eq!(1, 2); - | + error: expected `;`, found `println` --> $DIR/macros-no-semicolon.rs:3:21 | LL | assert_eq!(3, 4) - | ^ + | ^ help: add `;` here LL | println!("hello"); | ------- unexpected token - | -help: add `;` here - | -LL | assert_eq!(3, 4); - | + error: aborting due to 2 previous errors diff --git a/tests/ui/parser/raw/raw-str-unbalanced.stderr b/tests/ui/parser/raw/raw-str-unbalanced.stderr index d3a9c342c03..eac8c06c1df 100644 --- a/tests/ui/parser/raw/raw-str-unbalanced.stderr +++ b/tests/ui/parser/raw/raw-str-unbalanced.stderr @@ -19,15 +19,10 @@ error: expected `;`, found `#` --> $DIR/raw-str-unbalanced.rs:10:28 | LL | const A: &'static str = r"" - | ^ + | ^ help: add `;` here ... LL | #[test] | - unexpected token - | -help: add `;` here - | -LL | const A: &'static str = r""; - | + error: too many `#` when terminating raw string --> $DIR/raw-str-unbalanced.rs:16:28 diff --git a/tests/ui/parser/recover/recover-missing-semi-before-item.stderr b/tests/ui/parser/recover/recover-missing-semi-before-item.stderr index 8a87d44c959..61c43f2f189 100644 --- a/tests/ui/parser/recover/recover-missing-semi-before-item.stderr +++ b/tests/ui/parser/recover/recover-missing-semi-before-item.stderr @@ -2,132 +2,82 @@ error: expected `;`, found keyword `struct` --> $DIR/recover-missing-semi-before-item.rs:6:16 | LL | let foo = 3 - | ^ + | ^ help: add `;` here LL | struct Foo; | ------ unexpected token - | -help: add `;` here - | -LL | let foo = 3; - | + error: expected `;`, found `union` --> $DIR/recover-missing-semi-before-item.rs:11:16 | LL | let foo = 3 - | ^ + | ^ help: add `;` here LL | union Foo { | ----- unexpected token - | -help: add `;` here - | -LL | let foo = 3; - | + error: expected `;`, found keyword `enum` --> $DIR/recover-missing-semi-before-item.rs:18:16 | LL | let foo = 3 - | ^ + | ^ help: add `;` here LL | enum Foo { | ---- unexpected token - | -help: add `;` here - | -LL | let foo = 3; - | + error: expected `;`, found keyword `fn` --> $DIR/recover-missing-semi-before-item.rs:25:16 | LL | let foo = 3 - | ^ + | ^ help: add `;` here LL | fn foo() {} | -- unexpected token - | -help: add `;` here - | -LL | let foo = 3; - | + error: expected `;`, found keyword `extern` --> $DIR/recover-missing-semi-before-item.rs:30:16 | LL | let foo = 3 - | ^ + | ^ help: add `;` here LL | extern fn foo() {} | ------ unexpected token - | -help: add `;` here - | -LL | let foo = 3; - | + error: expected `;`, found keyword `impl` --> $DIR/recover-missing-semi-before-item.rs:36:16 | LL | let foo = 3 - | ^ + | ^ help: add `;` here LL | impl Foo {} | ---- unexpected token - | -help: add `;` here - | -LL | let foo = 3; - | + error: expected `;`, found keyword `pub` --> $DIR/recover-missing-semi-before-item.rs:41:16 | LL | let foo = 3 - | ^ + | ^ help: add `;` here LL | pub use bar::Bar; | --- unexpected token - | -help: add `;` here - | -LL | let foo = 3; - | + error: expected `;`, found keyword `mod` --> $DIR/recover-missing-semi-before-item.rs:46:16 | LL | let foo = 3 - | ^ + | ^ help: add `;` here LL | mod foo {} | --- unexpected token - | -help: add `;` here - | -LL | let foo = 3; - | + error: expected `;`, found keyword `type` --> $DIR/recover-missing-semi-before-item.rs:51:16 | LL | let foo = 3 - | ^ + | ^ help: add `;` here LL | type Foo = usize; | ---- unexpected token - | -help: add `;` here - | -LL | let foo = 3; - | + error: expected `;`, found keyword `fn` --> $DIR/recover-missing-semi-before-item.rs:59:19 | LL | const X: i32 = 123 - | ^ + | ^ help: add `;` here LL | LL | fn main() {} | -- unexpected token - | -help: add `;` here - | -LL | const X: i32 = 123; - | + error: aborting due to 10 previous errors diff --git a/tests/ui/parser/recover/recover-missing-semi.stderr b/tests/ui/parser/recover/recover-missing-semi.stderr index 3e8cb37160e..ba479828538 100644 --- a/tests/ui/parser/recover/recover-missing-semi.stderr +++ b/tests/ui/parser/recover/recover-missing-semi.stderr @@ -2,29 +2,19 @@ error: expected `;`, found keyword `let` --> $DIR/recover-missing-semi.rs:2:22 | LL | let _: usize = () - | ^ + | ^ help: add `;` here ... LL | let _ = 3; | --- unexpected token - | -help: add `;` here - | -LL | let _: usize = (); - | + error: expected `;`, found keyword `return` --> $DIR/recover-missing-semi.rs:9:22 | LL | let _: usize = () - | ^ + | ^ help: add `;` here ... LL | return 3; | ------ unexpected token - | -help: add `;` here - | -LL | let _: usize = (); - | + error[E0308]: mismatched types --> $DIR/recover-missing-semi.rs:2:20 diff --git a/tests/ui/suggestions/missing-semicolon.stderr b/tests/ui/suggestions/missing-semicolon.stderr index 86404e4511c..54a64f664b5 100644 --- a/tests/ui/suggestions/missing-semicolon.stderr +++ b/tests/ui/suggestions/missing-semicolon.stderr @@ -2,27 +2,17 @@ error: expected `;`, found `}` --> $DIR/missing-semicolon.rs:6:7 | LL | () - | ^ + | ^ help: add `;` here LL | } | - unexpected token - | -help: add `;` here - | -LL | (); - | + error: expected `;`, found `}` --> $DIR/missing-semicolon.rs:32:7 | LL | () - | ^ + | ^ help: add `;` here LL | } | - unexpected token - | -help: add `;` here - | -LL | (); - | + error[E0618]: expected function, found `{integer}` --> $DIR/missing-semicolon.rs:5:13 diff --git a/tests/ui/suggestions/suggest-semicolon-for-fn-in-extern-block.stderr b/tests/ui/suggestions/suggest-semicolon-for-fn-in-extern-block.stderr index 3d6983ec8f9..12da91c20b3 100644 --- a/tests/ui/suggestions/suggest-semicolon-for-fn-in-extern-block.stderr +++ b/tests/ui/suggestions/suggest-semicolon-for-fn-in-extern-block.stderr @@ -2,14 +2,9 @@ error: expected `;`, found `}` --> $DIR/suggest-semicolon-for-fn-in-extern-block.rs:6:11 | LL | fn foo() - | ^ + | ^ help: add `;` here LL | } | - unexpected token - | -help: add `;` here - | -LL | fn foo(); - | + error: aborting due to 1 previous error -- cgit 1.4.1-3-g733a5