Skip to content

Commit 584eaef

Browse files
authored
Unrolled build for #145124
Rollup merge of #145124 - compiler-errors:for-eq, r=lqd Recover `for PAT = EXPR {}` I type this constantly, and the existing suggestion to put `in` before the `=` is misleading.
2 parents 2de2456 + b2d524c commit 584eaef

File tree

6 files changed

+33
-22
lines changed

6 files changed

+33
-22
lines changed

compiler/rustc_parse/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ parse_missing_for_in_trait_impl = missing `for` in a trait impl
642642
.suggestion = add `for` here
643643
644644
parse_missing_in_in_for_loop = missing `in` in `for` loop
645-
.use_in_not_of = try using `in` here instead
645+
.use_in = try using `in` here instead
646646
.add_in = try adding `in` here
647647
648648
parse_missing_let_before_mut = missing keyword

compiler/rustc_parse/src/errors.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -585,14 +585,13 @@ pub(crate) struct MissingInInForLoop {
585585

586586
#[derive(Subdiagnostic)]
587587
pub(crate) enum MissingInInForLoopSub {
588+
// User wrote `for pat of expr {}`
588589
// Has been misleading, at least in the past (closed Issue #48492), thus maybe-incorrect
589-
#[suggestion(
590-
parse_use_in_not_of,
591-
style = "verbose",
592-
applicability = "maybe-incorrect",
593-
code = "in"
594-
)]
590+
#[suggestion(parse_use_in, style = "verbose", applicability = "maybe-incorrect", code = "in")]
595591
InNotOf(#[primary_span] Span),
592+
// User wrote `for pat = expr {}`
593+
#[suggestion(parse_use_in, style = "verbose", applicability = "maybe-incorrect", code = "in")]
594+
InNotEq(#[primary_span] Span),
596595
#[suggestion(parse_add_in, style = "verbose", applicability = "maybe-incorrect", code = " in ")]
597596
AddIn(#[primary_span] Span),
598597
}

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3028,6 +3028,8 @@ impl<'a> Parser<'a> {
30283028
let span = self.token.span;
30293029
self.bump();
30303030
(span, errors::MissingInInForLoopSub::InNotOf)
3031+
} else if self.eat(exp!(Eq)) {
3032+
(self.prev_token.span, errors::MissingInInForLoopSub::InNotEq)
30313033
} else {
30323034
(self.prev_token.span.between(self.token.span), errors::MissingInInForLoopSub::AddIn)
30333035
};
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//@ run-rustfix
22

33
fn main() {
4-
for _i in 0..2 { //~ ERROR missing `in`
5-
}
6-
for _i in 0..2 { //~ ERROR missing `in`
7-
}
4+
for _i in 0..2 {} //~ ERROR missing `in`
5+
for _i in 0..2 {} //~ ERROR missing `in`
6+
for _i in 0..2 {} //~ ERROR missing `in`
87
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//@ run-rustfix
22

33
fn main() {
4-
for _i 0..2 { //~ ERROR missing `in`
5-
}
6-
for _i of 0..2 { //~ ERROR missing `in`
7-
}
4+
for _i 0..2 {} //~ ERROR missing `in`
5+
for _i of 0..2 {} //~ ERROR missing `in`
6+
for _i = 0..2 {} //~ ERROR missing `in`
87
}
Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
11
error: missing `in` in `for` loop
22
--> $DIR/for-loop-missing-in.rs:4:11
33
|
4-
LL | for _i 0..2 {
4+
LL | for _i 0..2 {}
55
| ^
66
|
77
help: try adding `in` here
88
|
9-
LL | for _i in 0..2 {
9+
LL | for _i in 0..2 {}
1010
| ++
1111

1212
error: missing `in` in `for` loop
13-
--> $DIR/for-loop-missing-in.rs:6:12
13+
--> $DIR/for-loop-missing-in.rs:5:12
1414
|
15-
LL | for _i of 0..2 {
15+
LL | for _i of 0..2 {}
1616
| ^^
1717
|
1818
help: try using `in` here instead
1919
|
20-
LL - for _i of 0..2 {
21-
LL + for _i in 0..2 {
20+
LL - for _i of 0..2 {}
21+
LL + for _i in 0..2 {}
22+
|
23+
24+
error: missing `in` in `for` loop
25+
--> $DIR/for-loop-missing-in.rs:6:12
26+
|
27+
LL | for _i = 0..2 {}
28+
| ^
29+
|
30+
help: try using `in` here instead
31+
|
32+
LL - for _i = 0..2 {}
33+
LL + for _i in 0..2 {}
2234
|
2335

24-
error: aborting due to 2 previous errors
36+
error: aborting due to 3 previous errors
2537

0 commit comments

Comments
 (0)