Skip to content

Commit 3a95c71

Browse files
committed
Add rustfix test and fix test name.
1 parent 4c1d892 commit 3a95c71

6 files changed

+220
-127
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// compile-flags: --error-format pretty-json -Zunstable-options
2+
// build-pass (FIXME(62277): could be check-pass?)
3+
// run-rustfix
4+
5+
// The output for humans should just highlight the whole span without showing
6+
// the suggested replacement, but we also want to test that suggested
7+
// replacement only removes one set of parentheses, rather than naïvely
8+
// stripping away any starting or ending parenthesis characters—hence this
9+
// test of the JSON error format.
10+
11+
#![warn(unused_parens)]
12+
#![allow(unreachable_code)]
13+
14+
fn main() {
15+
// We want to suggest the properly-balanced expression `1 / (2 + 3)`, not
16+
// the malformed `1 / (2 + 3`
17+
let _a = 1 / (2 + 3);
18+
f();
19+
}
20+
21+
fn f() -> bool {
22+
loop {
23+
if (break { return true }) {
24+
}
25+
}
26+
false
27+
}

src/test/ui/lint/unused_parens_json_suggestion.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// compile-flags: --error-format pretty-json -Zunstable-options
22
// build-pass (FIXME(62277): could be check-pass?)
3+
// run-rustfix
34

45
// The output for humans should just highlight the whole span without showing
56
// the suggested replacement, but we also want to test that suggested
@@ -8,6 +9,7 @@
89
// test of the JSON error format.
910

1011
#![warn(unused_parens)]
12+
#![allow(unreachable_code)]
1113

1214
fn main() {
1315
// We want to suggest the properly-balanced expression `1 / (2 + 3)`, not

src/test/ui/lint/unused_parens_json_suggestion.stderr

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
"spans": [
99
{
1010
"file_name": "$DIR/unused_parens_json_suggestion.rs",
11-
"byte_start": 611,
12-
"byte_end": 624,
13-
"line_start": 15,
14-
"line_end": 15,
11+
"byte_start": 654,
12+
"byte_end": 667,
13+
"line_start": 17,
14+
"line_end": 17,
1515
"column_start": 14,
1616
"column_end": 27,
1717
"is_primary": true,
@@ -36,10 +36,10 @@
3636
"spans": [
3737
{
3838
"file_name": "$DIR/unused_parens_json_suggestion.rs",
39-
"byte_start": 457,
40-
"byte_end": 470,
41-
"line_start": 10,
42-
"line_end": 10,
39+
"byte_start": 472,
40+
"byte_end": 485,
41+
"line_start": 11,
42+
"line_end": 11,
4343
"column_start": 9,
4444
"column_end": 22,
4545
"is_primary": true,
@@ -66,10 +66,10 @@
6666
"spans": [
6767
{
6868
"file_name": "$DIR/unused_parens_json_suggestion.rs",
69-
"byte_start": 611,
70-
"byte_end": 624,
71-
"line_start": 15,
72-
"line_end": 15,
69+
"byte_start": 654,
70+
"byte_end": 667,
71+
"line_start": 17,
72+
"line_end": 17,
7373
"column_start": 14,
7474
"column_end": 27,
7575
"is_primary": true,
@@ -91,13 +91,13 @@
9191
}
9292
],
9393
"rendered": "warning: unnecessary parentheses around assigned value
94-
--> $DIR/unused_parens_json_suggestion.rs:15:14
94+
--> $DIR/unused_parens_json_suggestion.rs:17:14
9595
|
9696
LL | let _a = (1 / (2 + 3));
9797
| ^^^^^^^^^^^^^ help: remove these parentheses
9898
|
9999
note: lint level defined here
100-
--> $DIR/unused_parens_json_suggestion.rs:10:9
100+
--> $DIR/unused_parens_json_suggestion.rs:11:9
101101
|
102102
LL | #![warn(unused_parens)]
103103
| ^^^^^^^^^^^^^
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// compile-flags: --error-format pretty-json -Zunstable-options
2+
// build-pass
3+
// run-rustfix
4+
5+
// The output for humans should just highlight the whole span without showing
6+
// the suggested replacement, but we also want to test that suggested
7+
// replacement only removes one set of parentheses, rather than naïvely
8+
// stripping away any starting or ending parenthesis characters—hence this
9+
// test of the JSON error format.
10+
11+
#![warn(unused_parens)]
12+
#![allow(unreachable_code)]
13+
14+
fn main() {
15+
16+
let _b = false;
17+
18+
if _b {
19+
println!("hello");
20+
}
21+
22+
f();
23+
24+
}
25+
26+
fn f() -> bool {
27+
let c = false;
28+
29+
if c {
30+
println!("next");
31+
}
32+
33+
if c {
34+
println!("prev");
35+
}
36+
37+
while false && true {
38+
if c {
39+
println!("norm");
40+
}
41+
42+
}
43+
44+
while true && false {
45+
for _ in 0 .. 3 {
46+
println!("e~")
47+
}
48+
}
49+
50+
for _ in 0 .. 3 {
51+
while true && false {
52+
println!("e~")
53+
}
54+
}
55+
56+
57+
loop {
58+
if (break { return true }) {
59+
}
60+
}
61+
false
62+
}

src/test/ui/lint/used_parens_remove_json_suggestion.rs renamed to src/test/ui/lint/unused_parens_remove_json_suggestion.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// compile-flags: --error-format pretty-json -Zunstable-options
22
// build-pass
3+
// run-rustfix
34

45
// The output for humans should just highlight the whole span without showing
56
// the suggested replacement, but we also want to test that suggested
@@ -8,6 +9,7 @@
89
// test of the JSON error format.
910

1011
#![warn(unused_parens)]
12+
#![allow(unreachable_code)]
1113

1214
fn main() {
1315

@@ -40,12 +42,12 @@ fn f() -> bool {
4042
}
4143

4244
while(true && false) {
43-
for i in (0 .. 3){
45+
for _ in (0 .. 3){
4446
println!("e~")
4547
}
4648
}
4749

48-
for i in (0 .. 3) {
50+
for _ in (0 .. 3) {
4951
while (true && false) {
5052
println!("e~")
5153
}

0 commit comments

Comments
 (0)