diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index c905349771ef..01e84fe2ec86 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -621,7 +621,7 @@ impl<'a> Parser<'a> { } // Possible missing `struct` or `enum` keyword - if let TokenKind::Ident(symbol, _) = &self.prev_token.kind + if let TokenKind::Ident(_, _) = self.prev_token.kind && let TokenKind::OpenDelim(Delimiter::Brace) = self.token.kind && let [TokenType::Token(token::Not), TokenType::Token(token::PathSep)] = expected[..] { @@ -637,9 +637,9 @@ impl<'a> Parser<'a> { ("an", "enum") }; err.span_suggestion( - self.prev_token.span, + self.prev_token.span.shrink_to_lo(), format!("if this is {article} {kw} definition, use the `{kw}` keyword"), - format!("{kw} {symbol}"), + format!("{kw} "), Applicability::MaybeIncorrect, ); break; @@ -648,7 +648,7 @@ impl<'a> Parser<'a> { } // Possible missing `fn` keyword - if let TokenKind::Ident(symbol, _) = &self.prev_token.kind + if let TokenKind::Ident(_, _) = self.prev_token.kind && let TokenKind::OpenDelim(Delimiter::Parenthesis) = self.token.kind { let mut lookahead = self.clone(); @@ -659,9 +659,9 @@ impl<'a> Parser<'a> { } if lookahead.token == token::OpenDelim(Delimiter::Brace) { err.span_suggestion( - self.prev_token.span, + self.prev_token.span.shrink_to_lo(), "if this is a function definition, use the `fn` keyword", - format!("fn {symbol}"), + "fn ", Applicability::MaybeIncorrect, ); break; diff --git a/tests/ui/did_you_mean/issue-40006.stderr b/tests/ui/did_you_mean/issue-40006.stderr index 8bbdba295745..927f50a6af15 100644 --- a/tests/ui/did_you_mean/issue-40006.stderr +++ b/tests/ui/did_you_mean/issue-40006.stderr @@ -25,7 +25,7 @@ LL | } help: if this is a function definition, use the `fn` keyword | LL | fn X() {} - | ~~~~ + | ++ error: expected one of `!` or `::`, found `(` --> $DIR/issue-40006.rs:16:6 @@ -40,7 +40,7 @@ LL | } help: if this is a function definition, use the `fn` keyword | LL | fn X() {} - | ~~~~ + | ++ error: expected one of `!` or `[`, found `#` --> $DIR/issue-40006.rs:19:17 diff --git a/tests/ui/parser/missing-enum-issue-125446.stderr b/tests/ui/parser/missing-enum-issue-125446.stderr index ffd606f4ad3b..a59cb62c93b2 100644 --- a/tests/ui/parser/missing-enum-issue-125446.stderr +++ b/tests/ui/parser/missing-enum-issue-125446.stderr @@ -7,7 +7,7 @@ LL | Whoops { help: if this is an enum definition, use the `enum` keyword | LL | enum Whoops { - | ~~~~~~~~~~~ + | ++++ error: aborting due to 1 previous error diff --git a/tests/ui/parser/missing-fn-issue-125446.stderr b/tests/ui/parser/missing-fn-issue-125446.stderr index 341d617f2e48..63d016ffebbf 100644 --- a/tests/ui/parser/missing-fn-issue-125446.stderr +++ b/tests/ui/parser/missing-fn-issue-125446.stderr @@ -7,7 +7,7 @@ LL | whoops() {} help: if this is a function definition, use the `fn` keyword | LL | fn whoops() {} - | ~~~~~~~~~ + | ++ error: aborting due to 1 previous error diff --git a/tests/ui/parser/missing-fn-issue-65381-1.stderr b/tests/ui/parser/missing-fn-issue-65381-1.stderr index ca1cba09c716..84975f11cccf 100644 --- a/tests/ui/parser/missing-fn-issue-65381-1.stderr +++ b/tests/ui/parser/missing-fn-issue-65381-1.stderr @@ -7,7 +7,7 @@ LL | main() { help: if this is a function definition, use the `fn` keyword | LL | fn main() { - | ~~~~~~~ + | ++ error: aborting due to 1 previous error diff --git a/tests/ui/parser/missing-fn-issue-65381-3.stderr b/tests/ui/parser/missing-fn-issue-65381-3.stderr index 6e2bd01bb6aa..22717124c425 100644 --- a/tests/ui/parser/missing-fn-issue-65381-3.stderr +++ b/tests/ui/parser/missing-fn-issue-65381-3.stderr @@ -7,7 +7,7 @@ LL | pub const initial_value() -> Self { help: if this is a function definition, use the `fn` keyword | LL | pub const fn initial_value() -> Self { - | ~~~~~~~~~~~~~~~~ + | ++ error: missing type for `const` item --> $DIR/missing-fn-issue-65381-3.rs:1:24 diff --git a/tests/ui/parser/missing-struct-issue-125446-1.stderr b/tests/ui/parser/missing-struct-issue-125446-1.stderr index 9548a7d5f08d..0217944d3dba 100644 --- a/tests/ui/parser/missing-struct-issue-125446-1.stderr +++ b/tests/ui/parser/missing-struct-issue-125446-1.stderr @@ -7,7 +7,7 @@ LL | Whoops { help: if this is a struct definition, use the `struct` keyword | LL | struct Whoops { - | ~~~~~~~~~~~~~ + | ++++++ error: aborting due to 1 previous error diff --git a/tests/ui/parser/missing-struct-issue-125446-2.stderr b/tests/ui/parser/missing-struct-issue-125446-2.stderr index a0abd0297ce8..0d7c1e17e8c5 100644 --- a/tests/ui/parser/missing-struct-issue-125446-2.stderr +++ b/tests/ui/parser/missing-struct-issue-125446-2.stderr @@ -7,7 +7,7 @@ LL | Whoops {} help: if this is a struct definition, use the `struct` keyword | LL | struct Whoops {} - | ~~~~~~~~~~~~~ + | ++++++ error: aborting due to 1 previous error