Skip to content

Commit

Permalink
Fix suggestion span
Browse files Browse the repository at this point in the history
  • Loading branch information
trevyn committed Jul 6, 2024
1 parent c7ecabd commit ed4fcc3
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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[..]
{
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/did_you_mean/issue-40006.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/parser/missing-enum-issue-125446.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion tests/ui/parser/missing-fn-issue-125446.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion tests/ui/parser/missing-fn-issue-65381-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion tests/ui/parser/missing-fn-issue-65381-3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/parser/missing-struct-issue-125446-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion tests/ui/parser/missing-struct-issue-125446-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ed4fcc3

Please sign in to comment.