Skip to content

Commit ed4fcc3

Browse files
committed
Fix suggestion span
1 parent c7ecabd commit ed4fcc3

8 files changed

+14
-14
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ impl<'a> Parser<'a> {
621621
}
622622

623623
// Possible missing `struct` or `enum` keyword
624-
if let TokenKind::Ident(symbol, _) = &self.prev_token.kind
624+
if let TokenKind::Ident(_, _) = self.prev_token.kind
625625
&& let TokenKind::OpenDelim(Delimiter::Brace) = self.token.kind
626626
&& let [TokenType::Token(token::Not), TokenType::Token(token::PathSep)] = expected[..]
627627
{
@@ -637,9 +637,9 @@ impl<'a> Parser<'a> {
637637
("an", "enum")
638638
};
639639
err.span_suggestion(
640-
self.prev_token.span,
640+
self.prev_token.span.shrink_to_lo(),
641641
format!("if this is {article} {kw} definition, use the `{kw}` keyword"),
642-
format!("{kw} {symbol}"),
642+
format!("{kw} "),
643643
Applicability::MaybeIncorrect,
644644
);
645645
break;
@@ -648,7 +648,7 @@ impl<'a> Parser<'a> {
648648
}
649649

650650
// Possible missing `fn` keyword
651-
if let TokenKind::Ident(symbol, _) = &self.prev_token.kind
651+
if let TokenKind::Ident(_, _) = self.prev_token.kind
652652
&& let TokenKind::OpenDelim(Delimiter::Parenthesis) = self.token.kind
653653
{
654654
let mut lookahead = self.clone();
@@ -659,9 +659,9 @@ impl<'a> Parser<'a> {
659659
}
660660
if lookahead.token == token::OpenDelim(Delimiter::Brace) {
661661
err.span_suggestion(
662-
self.prev_token.span,
662+
self.prev_token.span.shrink_to_lo(),
663663
"if this is a function definition, use the `fn` keyword",
664-
format!("fn {symbol}"),
664+
"fn ",
665665
Applicability::MaybeIncorrect,
666666
);
667667
break;

tests/ui/did_you_mean/issue-40006.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ LL | }
2525
help: if this is a function definition, use the `fn` keyword
2626
|
2727
LL | fn X() {}
28-
| ~~~~
28+
| ++
2929

3030
error: expected one of `!` or `::`, found `(`
3131
--> $DIR/issue-40006.rs:16:6
@@ -40,7 +40,7 @@ LL | }
4040
help: if this is a function definition, use the `fn` keyword
4141
|
4242
LL | fn X() {}
43-
| ~~~~
43+
| ++
4444

4545
error: expected one of `!` or `[`, found `#`
4646
--> $DIR/issue-40006.rs:19:17

tests/ui/parser/missing-enum-issue-125446.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | Whoops {
77
help: if this is an enum definition, use the `enum` keyword
88
|
99
LL | enum Whoops {
10-
| ~~~~~~~~~~~
10+
| ++++
1111

1212
error: aborting due to 1 previous error
1313

tests/ui/parser/missing-fn-issue-125446.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | whoops() {}
77
help: if this is a function definition, use the `fn` keyword
88
|
99
LL | fn whoops() {}
10-
| ~~~~~~~~~
10+
| ++
1111

1212
error: aborting due to 1 previous error
1313

tests/ui/parser/missing-fn-issue-65381-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | main() {
77
help: if this is a function definition, use the `fn` keyword
88
|
99
LL | fn main() {
10-
| ~~~~~~~
10+
| ++
1111

1212
error: aborting due to 1 previous error
1313

tests/ui/parser/missing-fn-issue-65381-3.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | pub const initial_value() -> Self {
77
help: if this is a function definition, use the `fn` keyword
88
|
99
LL | pub const fn initial_value() -> Self {
10-
| ~~~~~~~~~~~~~~~~
10+
| ++
1111

1212
error: missing type for `const` item
1313
--> $DIR/missing-fn-issue-65381-3.rs:1:24

tests/ui/parser/missing-struct-issue-125446-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | Whoops {
77
help: if this is a struct definition, use the `struct` keyword
88
|
99
LL | struct Whoops {
10-
| ~~~~~~~~~~~~~
10+
| ++++++
1111

1212
error: aborting due to 1 previous error
1313

tests/ui/parser/missing-struct-issue-125446-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | Whoops {}
77
help: if this is a struct definition, use the `struct` keyword
88
|
99
LL | struct Whoops {}
10-
| ~~~~~~~~~~~~~
10+
| ++++++
1111

1212
error: aborting due to 1 previous error
1313

0 commit comments

Comments
 (0)