1
Fork 0

Rollup merge of #133060 - tyrone-wu:removelet-span-suggestion, r=jieyouxu

Trim whitespace in RemoveLet primary span

Separate `RemoveLet` span into primary span for `let` and removal suggestion span for `let `, so that primary span does not include whitespace.

Fixes: #133031
This commit is contained in:
许杰友 Jieyou Xu (Joe) 2024-11-17 23:56:09 +08:00 committed by GitHub
commit 0b157e88d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 31 additions and 15 deletions

View file

@ -650,8 +650,9 @@ pub(crate) struct LeftArrowOperator {
#[diag(parse_remove_let)] #[diag(parse_remove_let)]
pub(crate) struct RemoveLet { pub(crate) struct RemoveLet {
#[primary_span] #[primary_span]
#[suggestion(applicability = "machine-applicable", code = "", style = "verbose")]
pub span: Span, pub span: Span,
#[suggestion(applicability = "machine-applicable", code = "", style = "verbose")]
pub suggestion: Span,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]

View file

@ -685,7 +685,7 @@ impl<'a> Parser<'a> {
self.bump(); self.bump();
// Trim extra space after the `let` // Trim extra space after the `let`
let span = lo.with_hi(self.token.span.lo()); 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; lo = self.token.span;
} }

View file

@ -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`
_ => {}
}
}

View file

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

View file

@ -1,31 +1,31 @@
error: expected pattern, found `let` 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 help: remove the unnecessary `let` keyword
| |
LL - for let x of [1, 2, 3] {} 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 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 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` error: expected pattern, found `let`
--> $DIR/unnecessary-let.rs:7:9 --> $DIR/unnecessary-let.rs:9:9
| |
LL | let 1 => {} LL | let 1 => {}
| ^^^^ | ^^^
| |
help: remove the unnecessary `let` keyword help: remove the unnecessary `let` keyword
| |