Skip to content

Commit 0904f54

Browse files
committed
Auto merge of #6473 - phansch:split-up-ui-test, r=flip1995
UI Tests: Separate suspicious_else_formatting tests Was briefly looking into #3864 when I saw that the tests could benefit from being in their own file. --- changelog: none
2 parents 73feb31 + 8ddf4ce commit 0904f54

File tree

4 files changed

+164
-168
lines changed

4 files changed

+164
-168
lines changed

tests/ui/formatting.rs

Lines changed: 1 addition & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -10,91 +10,6 @@ fn foo() -> bool {
1010

1111
#[rustfmt::skip]
1212
fn main() {
13-
// weird `else` formatting:
14-
if foo() {
15-
} {
16-
}
17-
18-
if foo() {
19-
} if foo() {
20-
}
21-
22-
let _ = { // if as the last expression
23-
let _ = 0;
24-
25-
if foo() {
26-
} if foo() {
27-
}
28-
else {
29-
}
30-
};
31-
32-
let _ = { // if in the middle of a block
33-
if foo() {
34-
} if foo() {
35-
}
36-
else {
37-
}
38-
39-
let _ = 0;
40-
};
41-
42-
if foo() {
43-
} else
44-
{
45-
}
46-
47-
if foo() {
48-
}
49-
else
50-
{
51-
}
52-
53-
if foo() {
54-
} else
55-
if foo() { // the span of the above error should continue here
56-
}
57-
58-
if foo() {
59-
}
60-
else
61-
if foo() { // the span of the above error should continue here
62-
}
63-
64-
// those are ok:
65-
if foo() {
66-
}
67-
{
68-
}
69-
70-
if foo() {
71-
} else {
72-
}
73-
74-
if foo() {
75-
}
76-
else {
77-
}
78-
79-
if foo() {
80-
}
81-
if foo() {
82-
}
83-
84-
if foo() {
85-
} else if foo() {
86-
}
87-
88-
if foo() {
89-
}
90-
else if foo() {
91-
}
92-
93-
if foo() {
94-
}
95-
else if
96-
foo() {}
97-
9813
// weird op_eq formatting:
9914
let mut a = 42;
10015
a =- 35;
@@ -146,7 +61,7 @@ fn main() {
14661

14762
// don't lint if the indentation suggests not to
14863
let _ = &[
149-
1 + 2, 3
64+
1 + 2, 3
15065
- 4, 5
15166
];
15267
// lint if it doesn't

tests/ui/formatting.stderr

Lines changed: 7 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,5 @@
1-
error: this looks like an `else {..}` but the `else` is missing
2-
--> $DIR/formatting.rs:15:6
3-
|
4-
LL | } {
5-
| ^
6-
|
7-
= note: `-D clippy::suspicious-else-formatting` implied by `-D warnings`
8-
= note: to remove this lint, add the missing `else` or add a new line before the next block
9-
10-
error: this looks like an `else if` but the `else` is missing
11-
--> $DIR/formatting.rs:19:6
12-
|
13-
LL | } if foo() {
14-
| ^
15-
|
16-
= note: to remove this lint, add the missing `else` or add a new line before the second `if`
17-
18-
error: this looks like an `else if` but the `else` is missing
19-
--> $DIR/formatting.rs:26:10
20-
|
21-
LL | } if foo() {
22-
| ^
23-
|
24-
= note: to remove this lint, add the missing `else` or add a new line before the second `if`
25-
26-
error: this looks like an `else if` but the `else` is missing
27-
--> $DIR/formatting.rs:34:10
28-
|
29-
LL | } if foo() {
30-
| ^
31-
|
32-
= note: to remove this lint, add the missing `else` or add a new line before the second `if`
33-
34-
error: this is an `else {..}` but the formatting might hide it
35-
--> $DIR/formatting.rs:43:6
36-
|
37-
LL | } else
38-
| ______^
39-
LL | | {
40-
| |____^
41-
|
42-
= note: to remove this lint, remove the `else` or remove the new line between `else` and `{..}`
43-
44-
error: this is an `else {..}` but the formatting might hide it
45-
--> $DIR/formatting.rs:48:6
46-
|
47-
LL | }
48-
| ______^
49-
LL | | else
50-
LL | | {
51-
| |____^
52-
|
53-
= note: to remove this lint, remove the `else` or remove the new line between `else` and `{..}`
54-
55-
error: this is an `else if` but the formatting might hide it
56-
--> $DIR/formatting.rs:54:6
57-
|
58-
LL | } else
59-
| ______^
60-
LL | | if foo() { // the span of the above error should continue here
61-
| |____^
62-
|
63-
= note: to remove this lint, remove the `else` or remove the new line between `else` and `if`
64-
65-
error: this is an `else if` but the formatting might hide it
66-
--> $DIR/formatting.rs:59:6
67-
|
68-
LL | }
69-
| ______^
70-
LL | | else
71-
LL | | if foo() { // the span of the above error should continue here
72-
| |____^
73-
|
74-
= note: to remove this lint, remove the `else` or remove the new line between `else` and `if`
75-
761
error: this looks like you are trying to use `.. -= ..`, but you really are doing `.. = (- ..)`
77-
--> $DIR/formatting.rs:100:6
2+
--> $DIR/formatting.rs:15:6
783
|
794
LL | a =- 35;
805
| ^^^^
@@ -83,23 +8,23 @@ LL | a =- 35;
838
= note: to remove this lint, use either `-=` or `= -`
849

8510
error: this looks like you are trying to use `.. *= ..`, but you really are doing `.. = (* ..)`
86-
--> $DIR/formatting.rs:101:6
11+
--> $DIR/formatting.rs:16:6
8712
|
8813
LL | a =* &191;
8914
| ^^^^
9015
|
9116
= note: to remove this lint, use either `*=` or `= *`
9217

9318
error: this looks like you are trying to use `.. != ..`, but you really are doing `.. = (! ..)`
94-
--> $DIR/formatting.rs:104:6
19+
--> $DIR/formatting.rs:19:6
9520
|
9621
LL | b =! false;
9722
| ^^^^
9823
|
9924
= note: to remove this lint, use either `!=` or `= !`
10025

10126
error: possibly missing a comma here
102-
--> $DIR/formatting.rs:113:19
27+
--> $DIR/formatting.rs:28:19
10328
|
10429
LL | -1, -2, -3 // <= no comma here
10530
| ^
@@ -108,20 +33,20 @@ LL | -1, -2, -3 // <= no comma here
10833
= note: to remove this lint, add a comma or write the expr in a single line
10934

11035
error: possibly missing a comma here
111-
--> $DIR/formatting.rs:117:19
36+
--> $DIR/formatting.rs:32:19
11237
|
11338
LL | -1, -2, -3 // <= no comma here
11439
| ^
11540
|
11641
= note: to remove this lint, add a comma or write the expr in a single line
11742

11843
error: possibly missing a comma here
119-
--> $DIR/formatting.rs:154:11
44+
--> $DIR/formatting.rs:69:11
12045
|
12146
LL | -1
12247
| ^
12348
|
12449
= note: to remove this lint, add a comma or write the expr in a single line
12550

126-
error: aborting due to 14 previous errors
51+
error: aborting due to 6 previous errors
12752

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#![warn(clippy::suspicious_else_formatting)]
2+
3+
fn foo() -> bool {
4+
true
5+
}
6+
7+
#[rustfmt::skip]
8+
fn main() {
9+
// weird `else` formatting:
10+
if foo() {
11+
} {
12+
}
13+
14+
if foo() {
15+
} if foo() {
16+
}
17+
18+
let _ = { // if as the last expression
19+
let _ = 0;
20+
21+
if foo() {
22+
} if foo() {
23+
}
24+
else {
25+
}
26+
};
27+
28+
let _ = { // if in the middle of a block
29+
if foo() {
30+
} if foo() {
31+
}
32+
else {
33+
}
34+
35+
let _ = 0;
36+
};
37+
38+
if foo() {
39+
} else
40+
{
41+
}
42+
43+
if foo() {
44+
}
45+
else
46+
{
47+
}
48+
49+
if foo() {
50+
} else
51+
if foo() { // the span of the above error should continue here
52+
}
53+
54+
if foo() {
55+
}
56+
else
57+
if foo() { // the span of the above error should continue here
58+
}
59+
60+
// those are ok:
61+
if foo() {
62+
}
63+
{
64+
}
65+
66+
if foo() {
67+
} else {
68+
}
69+
70+
if foo() {
71+
}
72+
else {
73+
}
74+
75+
if foo() {
76+
}
77+
if foo() {
78+
}
79+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
error: this looks like an `else {..}` but the `else` is missing
2+
--> $DIR/suspicious_else_formatting.rs:11:6
3+
|
4+
LL | } {
5+
| ^
6+
|
7+
= note: `-D clippy::suspicious-else-formatting` implied by `-D warnings`
8+
= note: to remove this lint, add the missing `else` or add a new line before the next block
9+
10+
error: this looks like an `else if` but the `else` is missing
11+
--> $DIR/suspicious_else_formatting.rs:15:6
12+
|
13+
LL | } if foo() {
14+
| ^
15+
|
16+
= note: to remove this lint, add the missing `else` or add a new line before the second `if`
17+
18+
error: this looks like an `else if` but the `else` is missing
19+
--> $DIR/suspicious_else_formatting.rs:22:10
20+
|
21+
LL | } if foo() {
22+
| ^
23+
|
24+
= note: to remove this lint, add the missing `else` or add a new line before the second `if`
25+
26+
error: this looks like an `else if` but the `else` is missing
27+
--> $DIR/suspicious_else_formatting.rs:30:10
28+
|
29+
LL | } if foo() {
30+
| ^
31+
|
32+
= note: to remove this lint, add the missing `else` or add a new line before the second `if`
33+
34+
error: this is an `else {..}` but the formatting might hide it
35+
--> $DIR/suspicious_else_formatting.rs:39:6
36+
|
37+
LL | } else
38+
| ______^
39+
LL | | {
40+
| |____^
41+
|
42+
= note: to remove this lint, remove the `else` or remove the new line between `else` and `{..}`
43+
44+
error: this is an `else {..}` but the formatting might hide it
45+
--> $DIR/suspicious_else_formatting.rs:44:6
46+
|
47+
LL | }
48+
| ______^
49+
LL | | else
50+
LL | | {
51+
| |____^
52+
|
53+
= note: to remove this lint, remove the `else` or remove the new line between `else` and `{..}`
54+
55+
error: this is an `else if` but the formatting might hide it
56+
--> $DIR/suspicious_else_formatting.rs:50:6
57+
|
58+
LL | } else
59+
| ______^
60+
LL | | if foo() { // the span of the above error should continue here
61+
| |____^
62+
|
63+
= note: to remove this lint, remove the `else` or remove the new line between `else` and `if`
64+
65+
error: this is an `else if` but the formatting might hide it
66+
--> $DIR/suspicious_else_formatting.rs:55:6
67+
|
68+
LL | }
69+
| ______^
70+
LL | | else
71+
LL | | if foo() { // the span of the above error should continue here
72+
| |____^
73+
|
74+
= note: to remove this lint, remove the `else` or remove the new line between `else` and `if`
75+
76+
error: aborting due to 8 previous errors
77+

0 commit comments

Comments
 (0)