Skip to content

Commit 745b48d

Browse files
authored
Unrolled build for rust-lang#133060
Rollup merge of rust-lang#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: rust-lang#133031
2 parents 23e7ecb + dd557c9 commit 745b48d

File tree

5 files changed

+31
-15
lines changed

5 files changed

+31
-15
lines changed

compiler/rustc_parse/src/errors.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,9 @@ pub(crate) struct LeftArrowOperator {
650650
#[diag(parse_remove_let)]
651651
pub(crate) struct RemoveLet {
652652
#[primary_span]
653-
#[suggestion(applicability = "machine-applicable", code = "", style = "verbose")]
654653
pub span: Span,
654+
#[suggestion(applicability = "machine-applicable", code = "", style = "verbose")]
655+
pub suggestion: Span,
655656
}
656657

657658
#[derive(Diagnostic)]

compiler/rustc_parse/src/parser/pat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ impl<'a> Parser<'a> {
685685
self.bump();
686686
// Trim extra space after the `let`
687687
let span = lo.with_hi(self.token.span.lo());
688-
self.dcx().emit_err(RemoveLet { span });
688+
self.dcx().emit_err(RemoveLet { span: lo, suggestion: span });
689689
lo = self.token.span;
690690
}
691691

tests/ui/parser/unnecessary-let.fixed

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ run-rustfix
2+
3+
fn main() {
4+
for _x in [1, 2, 3] {}
5+
//~^ ERROR expected pattern, found `let`
6+
//~| ERROR missing `in` in `for` loop
7+
8+
match 1 {
9+
1 => {}
10+
//~^ ERROR expected pattern, found `let`
11+
_ => {}
12+
}
13+
}

tests/ui/parser/unnecessary-let.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
//@ run-rustfix
2+
13
fn main() {
2-
for let x of [1, 2, 3] {}
4+
for let _x of [1, 2, 3] {}
35
//~^ ERROR expected pattern, found `let`
46
//~| ERROR missing `in` in `for` loop
57

tests/ui/parser/unnecessary-let.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
error: expected pattern, found `let`
2-
--> $DIR/unnecessary-let.rs:2:9
2+
--> $DIR/unnecessary-let.rs:4:9
33
|
4-
LL | for let x of [1, 2, 3] {}
5-
| ^^^^
4+
LL | for let _x of [1, 2, 3] {}
5+
| ^^^
66
|
77
help: remove the unnecessary `let` keyword
88
|
9-
LL - for let x of [1, 2, 3] {}
10-
LL + for x of [1, 2, 3] {}
9+
LL - for let _x of [1, 2, 3] {}
10+
LL + for _x of [1, 2, 3] {}
1111
|
1212

1313
error: missing `in` in `for` loop
14-
--> $DIR/unnecessary-let.rs:2:15
14+
--> $DIR/unnecessary-let.rs:4:16
1515
|
16-
LL | for let x of [1, 2, 3] {}
17-
| ^^
16+
LL | for let _x of [1, 2, 3] {}
17+
| ^^
1818
|
1919
help: try using `in` here instead
2020
|
21-
LL | for let x in [1, 2, 3] {}
22-
| ~~
21+
LL | for let _x in [1, 2, 3] {}
22+
| ~~
2323

2424
error: expected pattern, found `let`
25-
--> $DIR/unnecessary-let.rs:7:9
25+
--> $DIR/unnecessary-let.rs:9:9
2626
|
2727
LL | let 1 => {}
28-
| ^^^^
28+
| ^^^
2929
|
3030
help: remove the unnecessary `let` keyword
3131
|

0 commit comments

Comments
 (0)