Skip to content

Trim whitespace in RemoveLet primary span #133060

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

Merged
merged 1 commit into from
Nov 17, 2024
Merged
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
3 changes: 2 additions & 1 deletion compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
@@ -650,8 +650,9 @@ pub(crate) struct LeftArrowOperator {
#[diag(parse_remove_let)]
pub(crate) struct RemoveLet {
#[primary_span]
#[suggestion(applicability = "machine-applicable", code = "", style = "verbose")]
pub span: Span,
#[suggestion(applicability = "machine-applicable", code = "", style = "verbose")]
pub suggestion: Span,
}

#[derive(Diagnostic)]
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/pat.rs
Original file line number Diff line number Diff line change
@@ -685,7 +685,7 @@ impl<'a> Parser<'a> {
self.bump();
// Trim extra space after the `let`
let span = lo.with_hi(self.token.span.lo());
self.dcx().emit_err(RemoveLet { span });
self.dcx().emit_err(RemoveLet { span: lo, suggestion: span });
lo = self.token.span;
}

13 changes: 13 additions & 0 deletions tests/ui/parser/unnecessary-let.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//@ run-rustfix

fn main() {
for _x in [1, 2, 3] {}
//~^ ERROR expected pattern, found `let`
//~| ERROR missing `in` in `for` loop

match 1 {
1 => {}
//~^ ERROR expected pattern, found `let`
_ => {}
}
}
4 changes: 3 additions & 1 deletion tests/ui/parser/unnecessary-let.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//@ run-rustfix

fn main() {
for let x of [1, 2, 3] {}
for let _x of [1, 2, 3] {}
//~^ ERROR expected pattern, found `let`
//~| ERROR missing `in` in `for` loop

24 changes: 12 additions & 12 deletions tests/ui/parser/unnecessary-let.stderr
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
error: expected pattern, found `let`
--> $DIR/unnecessary-let.rs:2:9
--> $DIR/unnecessary-let.rs:4:9
|
LL | for let x of [1, 2, 3] {}
| ^^^^
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 let _x of [1, 2, 3] {}
LL + for _x of [1, 2, 3] {}
|

error: missing `in` in `for` loop
--> $DIR/unnecessary-let.rs:2:15
--> $DIR/unnecessary-let.rs:4:16
|
LL | for let x of [1, 2, 3] {}
| ^^
LL | for let _x of [1, 2, 3] {}
| ^^
|
help: try using `in` here instead
|
LL | for let x in [1, 2, 3] {}
| ~~
LL | for let _x in [1, 2, 3] {}
| ~~

error: expected pattern, found `let`
--> $DIR/unnecessary-let.rs:7:9
--> $DIR/unnecessary-let.rs:9:9
|
LL | let 1 => {}
| ^^^^
| ^^^
|
help: remove the unnecessary `let` keyword
|
Loading