Skip to content

Commit 86220d6

Browse files
committed
Fix rustfix panic on test
`run-rustfix` applies all suggestions regardless of their Applicability. There's a flag, `rustfix-only-machine-applicable`, that does what it says, but then the produced `.fixed` file would have invalid code from the suggestions that weren't applied. So, I moved the cases of postfix increment, in which case multiple suggestions are given, to the `-notfixed` test, which does not run rustfix. I also changed the Applicability to Unspecified since MaybeIncorrect requires that the code be valid, even if it's incorrect.
1 parent 725cde4 commit 86220d6

File tree

6 files changed

+135
-114
lines changed

6 files changed

+135
-114
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ impl<'a> Parser<'a> {
13261326
MultiSugg::emit_many(
13271327
&mut err,
13281328
"use `+= 1` instead",
1329-
Applicability::MaybeIncorrect,
1329+
Applicability::Unspecified,
13301330
[sugg1, sugg2].into_iter(),
13311331
)
13321332
}
+14-19
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
// run-rustfix
22

3-
fn post_regular() {
4-
let mut i = 0;
5-
{ let tmp = i; i += 1; tmp }; //~ ERROR Rust has no postfix increment operator
6-
println!("{}", i);
7-
}
8-
9-
fn post_while() {
10-
let mut i = 0;
11-
while { let tmp = i; i += 1; tmp } < 5 {
12-
//~^ ERROR Rust has no postfix increment operator
13-
println!("{}", i);
14-
}
15-
}
16-
173
fn pre_regular() {
184
let mut i = 0;
195
i += 1; //~ ERROR Rust has no prefix increment operator
@@ -28,9 +14,18 @@ fn pre_while() {
2814
}
2915
}
3016

31-
fn main() {
32-
post_regular();
33-
post_while();
34-
pre_regular();
35-
pre_while();
17+
fn pre_regular_tmp() {
18+
let mut tmp = 0;
19+
tmp += 1; //~ ERROR Rust has no prefix increment operator
20+
println!("{}", tmp);
3621
}
22+
23+
fn pre_while_tmp() {
24+
let mut tmp = 0;
25+
while { tmp += 1; tmp } < 5 {
26+
//~^ ERROR Rust has no prefix increment operator
27+
println!("{}", tmp);
28+
}
29+
}
30+
31+
fn main() {}
+11-32
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,31 @@
11
// run-rustfix
22

3-
fn post_regular() {
3+
fn pre_regular() {
44
let mut i = 0;
5-
i++; //~ ERROR Rust has no postfix increment operator
5+
++i; //~ ERROR Rust has no prefix increment operator
66
println!("{}", i);
77
}
88

9-
fn post_while() {
9+
fn pre_while() {
1010
let mut i = 0;
11-
while i++ < 5 {
12-
//~^ ERROR Rust has no postfix increment operator
11+
while ++i < 5 {
12+
//~^ ERROR Rust has no prefix increment operator
1313
println!("{}", i);
1414
}
1515
}
1616

17-
fn post_regular_tmp() {
17+
fn pre_regular_tmp() {
1818
let mut tmp = 0;
19-
tmp++; //~ ERROR Rust has no postfix increment operator
19+
++tmp; //~ ERROR Rust has no prefix increment operator
2020
println!("{}", tmp);
2121
}
2222

23-
fn post_while_tmp() {
23+
fn pre_while_tmp() {
2424
let mut tmp = 0;
25-
while tmp++ < 5 {
26-
//~^ ERROR Rust has no postfix increment operator
27-
println!("{}", tmp);
28-
}
29-
}
30-
31-
fn pre_regular() {
32-
let mut i = 0;
33-
++i; //~ ERROR Rust has no prefix increment operator
34-
println!("{}", i);
35-
}
36-
37-
fn pre_while() {
38-
let mut i = 0;
39-
while ++i < 5 {
25+
while ++tmp < 5 {
4026
//~^ ERROR Rust has no prefix increment operator
41-
println!("{}", i);
27+
println!("{}", tmp);
4228
}
4329
}
4430

45-
fn main() {
46-
post_regular();
47-
post_while();
48-
post_regular_tmp();
49-
post_while_tmp();
50-
pre_regular();
51-
pre_while();
52-
}
31+
fn main() {}
+20-53
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,48 @@
1-
error: Rust has no postfix increment operator
2-
--> $DIR/increment-autofix.rs:5:6
1+
error: Rust has no prefix increment operator
2+
--> $DIR/increment-autofix.rs:5:5
33
|
4-
LL | i++;
5-
| ^^ not a valid postfix operator
4+
LL | ++i;
5+
| ^^ not a valid prefix operator
66
|
77
help: use `+= 1` instead
88
|
9-
LL | { let tmp = i; i += 1; tmp };
10-
| +++++++++++ ~~~~~~~~~~~~~~~
11-
LL - i++;
9+
LL - ++i;
1210
LL + i += 1;
1311
|
1412

15-
error: Rust has no postfix increment operator
16-
--> $DIR/increment-autofix.rs:11:12
17-
|
18-
LL | while i++ < 5 {
19-
| ^^ not a valid postfix operator
20-
|
21-
help: use `+= 1` instead
22-
|
23-
LL | while { let tmp = i; i += 1; tmp } < 5 {
24-
| +++++++++++ ~~~~~~~~~~~~~~~
25-
LL - while i++ < 5 {
26-
LL + while i += 1 < 5 {
27-
|
28-
29-
error: Rust has no postfix increment operator
30-
--> $DIR/increment-autofix.rs:19:8
31-
|
32-
LL | tmp++;
33-
| ^^ not a valid postfix operator
34-
|
35-
help: use `+= 1` instead
36-
|
37-
LL | { let tmp_ = tmp; tmp += 1; tmp_ };
38-
| ++++++++++++ ~~~~~~~~~~~~~~~~~~
39-
LL - tmp++;
40-
LL + tmp += 1;
41-
|
42-
43-
error: Rust has no postfix increment operator
44-
--> $DIR/increment-autofix.rs:25:14
13+
error: Rust has no prefix increment operator
14+
--> $DIR/increment-autofix.rs:11:11
4515
|
46-
LL | while tmp++ < 5 {
47-
| ^^ not a valid postfix operator
16+
LL | while ++i < 5 {
17+
| ^^ not a valid prefix operator
4818
|
4919
help: use `+= 1` instead
5020
|
51-
LL | while { let tmp_ = tmp; tmp += 1; tmp_ } < 5 {
52-
| ++++++++++++ ~~~~~~~~~~~~~~~~~~
53-
LL - while tmp++ < 5 {
54-
LL + while tmp += 1 < 5 {
55-
|
21+
LL | while { i += 1; i } < 5 {
22+
| ~ +++++++++
5623

5724
error: Rust has no prefix increment operator
58-
--> $DIR/increment-autofix.rs:33:5
25+
--> $DIR/increment-autofix.rs:19:5
5926
|
60-
LL | ++i;
27+
LL | ++tmp;
6128
| ^^ not a valid prefix operator
6229
|
6330
help: use `+= 1` instead
6431
|
65-
LL - ++i;
66-
LL + i += 1;
32+
LL - ++tmp;
33+
LL + tmp += 1;
6734
|
6835

6936
error: Rust has no prefix increment operator
70-
--> $DIR/increment-autofix.rs:39:11
37+
--> $DIR/increment-autofix.rs:25:11
7138
|
72-
LL | while ++i < 5 {
39+
LL | while ++tmp < 5 {
7340
| ^^ not a valid prefix operator
7441
|
7542
help: use `+= 1` instead
7643
|
77-
LL | while { i += 1; i } < 5 {
78-
| ~ +++++++++
44+
LL | while { tmp += 1; tmp } < 5 {
45+
| ~ +++++++++++
7946

80-
error: aborting due to 6 previous errors
47+
error: aborting due to 4 previous errors
8148

src/test/ui/parser/increment-notfixed.rs

+29-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,34 @@ struct Bar {
66
qux: i32,
77
}
88

9+
fn post_regular() {
10+
let mut i = 0;
11+
i++; //~ ERROR Rust has no postfix increment operator
12+
println!("{}", i);
13+
}
14+
15+
fn post_while() {
16+
let mut i = 0;
17+
while i++ < 5 {
18+
//~^ ERROR Rust has no postfix increment operator
19+
println!("{}", i);
20+
}
21+
}
22+
23+
fn post_regular_tmp() {
24+
let mut tmp = 0;
25+
tmp++; //~ ERROR Rust has no postfix increment operator
26+
println!("{}", tmp);
27+
}
28+
29+
fn post_while_tmp() {
30+
let mut tmp = 0;
31+
while tmp++ < 5 {
32+
//~^ ERROR Rust has no postfix increment operator
33+
println!("{}", tmp);
34+
}
35+
}
36+
937
fn post_field() {
1038
let foo = Foo { bar: Bar { qux: 0 } };
1139
foo.bar.qux++;
@@ -30,8 +58,4 @@ fn pre_field() {
3058
println!("{}", foo.bar.qux);
3159
}
3260

33-
fn main() {
34-
post_field();
35-
post_field_tmp();
36-
pre_field();
37-
}
61+
fn main() {}

src/test/ui/parser/increment-notfixed.stderr

+60-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,61 @@
11
error: Rust has no postfix increment operator
2-
--> $DIR/increment-notfixed.rs:11:16
2+
--> $DIR/increment-notfixed.rs:11:6
3+
|
4+
LL | i++;
5+
| ^^ not a valid postfix operator
6+
|
7+
help: use `+= 1` instead
8+
|
9+
LL | { let tmp = i; i += 1; tmp };
10+
| +++++++++++ ~~~~~~~~~~~~~~~
11+
LL - i++;
12+
LL + i += 1;
13+
|
14+
15+
error: Rust has no postfix increment operator
16+
--> $DIR/increment-notfixed.rs:17:12
17+
|
18+
LL | while i++ < 5 {
19+
| ^^ not a valid postfix operator
20+
|
21+
help: use `+= 1` instead
22+
|
23+
LL | while { let tmp = i; i += 1; tmp } < 5 {
24+
| +++++++++++ ~~~~~~~~~~~~~~~
25+
LL - while i++ < 5 {
26+
LL + while i += 1 < 5 {
27+
|
28+
29+
error: Rust has no postfix increment operator
30+
--> $DIR/increment-notfixed.rs:25:8
31+
|
32+
LL | tmp++;
33+
| ^^ not a valid postfix operator
34+
|
35+
help: use `+= 1` instead
36+
|
37+
LL | { let tmp_ = tmp; tmp += 1; tmp_ };
38+
| ++++++++++++ ~~~~~~~~~~~~~~~~~~
39+
LL - tmp++;
40+
LL + tmp += 1;
41+
|
42+
43+
error: Rust has no postfix increment operator
44+
--> $DIR/increment-notfixed.rs:31:14
45+
|
46+
LL | while tmp++ < 5 {
47+
| ^^ not a valid postfix operator
48+
|
49+
help: use `+= 1` instead
50+
|
51+
LL | while { let tmp_ = tmp; tmp += 1; tmp_ } < 5 {
52+
| ++++++++++++ ~~~~~~~~~~~~~~~~~~
53+
LL - while tmp++ < 5 {
54+
LL + while tmp += 1 < 5 {
55+
|
56+
57+
error: Rust has no postfix increment operator
58+
--> $DIR/increment-notfixed.rs:39:16
359
|
460
LL | foo.bar.qux++;
561
| ^^ not a valid postfix operator
@@ -13,7 +69,7 @@ LL + foo.bar.qux += 1;
1369
|
1470

1571
error: Rust has no postfix increment operator
16-
--> $DIR/increment-notfixed.rs:21:10
72+
--> $DIR/increment-notfixed.rs:49:10
1773
|
1874
LL | s.tmp++;
1975
| ^^ not a valid postfix operator
@@ -27,7 +83,7 @@ LL + s.tmp += 1;
2783
|
2884

2985
error: Rust has no prefix increment operator
30-
--> $DIR/increment-notfixed.rs:28:5
86+
--> $DIR/increment-notfixed.rs:56:5
3187
|
3288
LL | ++foo.bar.qux;
3389
| ^^ not a valid prefix operator
@@ -38,5 +94,5 @@ LL - ++foo.bar.qux;
3894
LL + foo.bar.qux += 1;
3995
|
4096

41-
error: aborting due to 3 previous errors
97+
error: aborting due to 7 previous errors
4298

0 commit comments

Comments
 (0)