Skip to content

Commit 0a6e568

Browse files
committed
test formatting: don't format tests/ui/formatting.rs
1 parent 7bcc2cd commit 0a6e568

File tree

3 files changed

+135
-49
lines changed

3 files changed

+135
-49
lines changed

ci/base-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ set +ex
3535

3636
# some lints are sensitive to formatting, exclude some files
3737
needs_formatting=false
38-
for file in `find tests -not -path "tests/ui/methods.rs" -not -path "tests/ui/format.rs" -not -path "tests/ui/empty_line_after_outer_attribute.rs" -not -path "tests/ui/double_parens.rs" -not -path "tests/ui/doc.rs" -not -path "tests/ui/unused_unit.rs" | grep "\.rs$"` ; do
38+
for file in `find tests -not -path "tests/ui/methods.rs" -not -path "tests/ui/format.rs" -not -path "tests/ui/formatting.rs" -not -path "tests/ui/empty_line_after_outer_attribute.rs" -not -path "tests/ui/double_parens.rs" -not -path "tests/ui/doc.rs" -not -path "tests/ui/unused_unit.rs" | grep "\.rs$"` ; do
3939
rustfmt ${file} --check || echo "${file} needs reformatting!" ; needs_formatting=true
4040
done
4141

tests/ui/formatting.rs

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,74 +7,82 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10+
11+
12+
13+
1014
#![warn(clippy::all)]
1115
#![allow(unused_variables)]
1216
#![allow(unused_assignments)]
1317
#![allow(clippy::if_same_then_else)]
1418
#![allow(clippy::deref_addrof)]
1519

16-
fn foo() -> bool {
17-
true
18-
}
20+
fn foo() -> bool { true }
1921

2022
fn main() {
2123
// weird `else if` formatting:
22-
if foo() {}
23-
if foo() {}
24+
if foo() {
25+
} if foo() {
26+
}
2427

25-
let _ = {
26-
// if as the last expression
28+
let _ = { // if as the last expression
2729
let _ = 0;
2830

29-
if foo() {}
3031
if foo() {
31-
} else {
32+
} if foo() {
33+
}
34+
else {
3235
}
3336
};
3437

35-
let _ = {
36-
// if in the middle of a block
37-
if foo() {}
38+
let _ = { // if in the middle of a block
3839
if foo() {
39-
} else {
40+
} if foo() {
41+
}
42+
else {
4043
}
4144

4245
let _ = 0;
4346
};
4447

4548
if foo() {
46-
} else if foo() {
47-
// the span of the above error should continue here
49+
} else
50+
if foo() { // the span of the above error should continue here
4851
}
4952

5053
if foo() {
51-
} else if foo() {
52-
// the span of the above error should continue here
54+
}
55+
else
56+
if foo() { // the span of the above error should continue here
5357
}
5458

5559
// those are ok:
56-
if foo() {}
57-
if foo() {}
60+
if foo() {
61+
}
62+
if foo() {
63+
}
5864

5965
if foo() {
6066
} else if foo() {
6167
}
6268

6369
if foo() {
64-
} else if foo() {
70+
}
71+
else if foo() {
6572
}
6673

6774
if foo() {
68-
} else if foo() {
6975
}
76+
else if
77+
foo() {}
7078

7179
// weird op_eq formatting:
7280
let mut a = 42;
73-
a = -35;
74-
a = *&191;
81+
a =- 35;
82+
a =* &191;
7583

7684
let mut b = true;
77-
b = !false;
85+
b =! false;
7886

7987
// those are ok:
8088
a = -35;
@@ -83,30 +91,37 @@ fn main() {
8391

8492
// possible missing comma in an array
8593
let _ = &[
86-
-1,
87-
-2,
88-
-3 // <= no comma here
89-
-4,
90-
-5,
91-
-6,
94+
-1, -2, -3 // <= no comma here
95+
-4, -5, -6
9296
];
9397
let _ = &[
94-
-1,
95-
-2,
96-
-3 // <= no comma here
97-
*4,
98-
-5,
99-
-6,
98+
-1, -2, -3 // <= no comma here
99+
*4, -5, -6
100100
];
101101

102102
// those are ok:
103-
let _ = &[-1, -2, -3, -4, -5, -6];
104-
let _ = &[-1, -2, -3, -4, -5, -6];
105-
let _ = &[1 + 2, 3 + 4, 5 + 6];
103+
let _ = &[
104+
-1, -2, -3,
105+
-4, -5, -6
106+
];
107+
let _ = &[
108+
-1, -2, -3,
109+
-4, -5, -6,
110+
];
111+
let _ = &[
112+
1 + 2, 3 +
113+
4, 5 + 6,
114+
];
106115

107116
// don't lint for bin op without unary equiv
108117
// issue 3244
109-
vec![1 / 2];
118+
vec![
119+
1
120+
/ 2,
121+
];
110122
// issue 3396
111-
vec![true | false];
123+
vec![
124+
true
125+
| false,
126+
];
112127
}

tests/ui/formatting.stderr

Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,90 @@
1+
error: this looks like an `else if` but the `else` is missing
2+
--> $DIR/formatting.rs:25:6
3+
|
4+
25 | } if foo() {
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 second `if`
9+
10+
error: this looks like an `else if` but the `else` is missing
11+
--> $DIR/formatting.rs:32:10
12+
|
13+
32 | } 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:40:10
20+
|
21+
40 | } 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 is an `else if` but the formatting might hide it
27+
--> $DIR/formatting.rs:49:6
28+
|
29+
49 | } else
30+
| ______^
31+
50 | | if foo() { // the span of the above error should continue here
32+
| |____^
33+
|
34+
= note: to remove this lint, remove the `else` or remove the new line between `else` and `if`
35+
36+
error: this is an `else if` but the formatting might hide it
37+
--> $DIR/formatting.rs:54:6
38+
|
39+
54 | }
40+
| ______^
41+
55 | | else
42+
56 | | if foo() { // the span of the above error should continue here
43+
| |____^
44+
|
45+
= note: to remove this lint, remove the `else` or remove the new line between `else` and `if`
46+
47+
error: this looks like you are trying to use `.. -= ..`, but you really are doing `.. = (- ..)`
48+
--> $DIR/formatting.rs:81:6
49+
|
50+
81 | a =- 35;
51+
| ^^^^
52+
|
53+
= note: `-D clippy::suspicious-assignment-formatting` implied by `-D warnings`
54+
= note: to remove this lint, use either `-=` or `= -`
55+
56+
error: this looks like you are trying to use `.. *= ..`, but you really are doing `.. = (* ..)`
57+
--> $DIR/formatting.rs:82:6
58+
|
59+
82 | a =* &191;
60+
| ^^^^
61+
|
62+
= note: to remove this lint, use either `*=` or `= *`
63+
64+
error: this looks like you are trying to use `.. != ..`, but you really are doing `.. = (! ..)`
65+
--> $DIR/formatting.rs:85:6
66+
|
67+
85 | b =! false;
68+
| ^^^^
69+
|
70+
= note: to remove this lint, use either `!=` or `= !`
71+
172
error: possibly missing a comma here
2-
--> $DIR/formatting.rs:88:11
73+
--> $DIR/formatting.rs:94:19
374
|
4-
88 | -3 // <= no comma here
5-
| ^
75+
94 | -1, -2, -3 // <= no comma here
76+
| ^
677
|
778
= note: `-D clippy::possible-missing-comma` implied by `-D warnings`
879
= note: to remove this lint, add a comma or write the expr in a single line
980

1081
error: possibly missing a comma here
11-
--> $DIR/formatting.rs:96:11
82+
--> $DIR/formatting.rs:98:19
1283
|
13-
96 | -3 // <= no comma here
14-
| ^
84+
98 | -1, -2, -3 // <= no comma here
85+
| ^
1586
|
1687
= note: to remove this lint, add a comma or write the expr in a single line
1788

18-
error: aborting due to 2 previous errors
89+
error: aborting due to 10 previous errors
1990

0 commit comments

Comments
 (0)