Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim extra space when suggesting removing bad let #132996

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/rustc_parse/src/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,9 @@ impl<'a> Parser<'a> {
})
{
self.bump();
self.dcx().emit_err(RemoveLet { span: lo });
// Trim extra space after the `let`
let span = lo.with_hi(self.token.span.lo());
self.dcx().emit_err(RemoveLet { span });
lo = self.token.span;
}

Expand Down
8 changes: 4 additions & 4 deletions tests/ui/parser/unnecessary-let.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ error: expected pattern, found `let`
--> $DIR/unnecessary-let.rs:2:9
|
LL | for let x of [1, 2, 3] {}
| ^^^
| ^^^^
|
help: remove the unnecessary `let` keyword
|
LL - for let x of [1, 2, 3] {}
LL + for x of [1, 2, 3] {}
LL + for x of [1, 2, 3] {}
|

error: missing `in` in `for` loop
Expand All @@ -25,12 +25,12 @@ error: expected pattern, found `let`
--> $DIR/unnecessary-let.rs:7:9
|
LL | let 1 => {}
| ^^^
| ^^^^
Comment on lines 27 to +28
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we'd modify RemoveLet to have two separate spans, one for the let and another for the let removal suggestion so that the primary span doesn't point at unnecessary whitespace. We can address that as follow up.

|
help: remove the unnecessary `let` keyword
|
LL - let 1 => {}
LL + 1 => {}
LL + 1 => {}
|

error: aborting due to 3 previous errors
Expand Down
Loading