Skip to content

Commit 0d89372

Browse files
committed
Auto merge of #3850 - mikerite:rustfmt-tests, r=phansch
More test improvements
2 parents 00baf7a + 7b94823 commit 0d89372

File tree

6 files changed

+92
-41
lines changed

6 files changed

+92
-41
lines changed

ci/base-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ rustup override set nightly
5959
# avoid loop spam and allow cmds with exit status != 0
6060
set +ex
6161

62-
for file in `find tests -not -path "tests/ui/doc.rs" -not -path "tests/ui/unused_unit.rs" | grep "\.rs$"` ; do
62+
for file in `find tests | grep "\.rs$"` ; do
6363
rustfmt ${file} --check
6464
if [ $? -ne 0 ]; then
6565
echo "${file} needs reformatting!"

tests/ui/doc.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
33
#![allow(dead_code)]
44
#![warn(clippy::doc_markdown)]
5+
#![feature(custom_inner_attributes)]
6+
#![rustfmt::skip]
57

68
/// The foo_bar function does _nothing_. See also foo::bar. (note the dot there)
79
/// Markdown is _weird_. I mean _really weird_. This \_ is ok. So is `_`. But not Foo::some_fun

tests/ui/doc.stderr

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,181 +7,181 @@ LL | //! This file tests for the DOC_MARKDOWN lint
77
= note: `-D clippy::doc-markdown` implied by `-D warnings`
88

99
error: you should put `foo_bar` between ticks in the documentation
10-
--> $DIR/doc.rs:6:9
10+
--> $DIR/doc.rs:8:9
1111
|
1212
LL | /// The foo_bar function does _nothing_. See also foo::bar. (note the dot there)
1313
| ^^^^^^^
1414

1515
error: you should put `foo::bar` between ticks in the documentation
16-
--> $DIR/doc.rs:6:51
16+
--> $DIR/doc.rs:8:51
1717
|
1818
LL | /// The foo_bar function does _nothing_. See also foo::bar. (note the dot there)
1919
| ^^^^^^^^
2020

2121
error: you should put `Foo::some_fun` between ticks in the documentation
22-
--> $DIR/doc.rs:7:84
22+
--> $DIR/doc.rs:9:84
2323
|
2424
LL | /// Markdown is _weird_. I mean _really weird_. This /_ is ok. So is `_`. But not Foo::some_fun
2525
| ^^^^^^^^^^^^^
2626

2727
error: you should put `a::global:path` between ticks in the documentation
28-
--> $DIR/doc.rs:9:15
28+
--> $DIR/doc.rs:11:15
2929
|
3030
LL | /// Here be ::a::global:path.
3131
| ^^^^^^^^^^^^^^
3232

3333
error: you should put `NotInCodeBlock` between ticks in the documentation
34-
--> $DIR/doc.rs:10:22
34+
--> $DIR/doc.rs:12:22
3535
|
3636
LL | /// That's not code ~NotInCodeBlock~.
3737
| ^^^^^^^^^^^^^^
3838

3939
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
40-
--> $DIR/doc.rs:11:5
40+
--> $DIR/doc.rs:13:5
4141
|
4242
LL | /// be_sure_we_got_to_the_end_of_it
4343
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4444

4545
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
46-
--> $DIR/doc.rs:25:5
46+
--> $DIR/doc.rs:27:5
4747
|
4848
LL | /// be_sure_we_got_to_the_end_of_it
4949
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5050

5151
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
52-
--> $DIR/doc.rs:32:5
52+
--> $DIR/doc.rs:34:5
5353
|
5454
LL | /// be_sure_we_got_to_the_end_of_it
5555
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5656

5757
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
58-
--> $DIR/doc.rs:46:5
58+
--> $DIR/doc.rs:48:5
5959
|
6060
LL | /// be_sure_we_got_to_the_end_of_it
6161
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6262

6363
error: you should put `link_with_underscores` between ticks in the documentation
64-
--> $DIR/doc.rs:50:22
64+
--> $DIR/doc.rs:52:22
6565
|
6666
LL | /// This test has [a link_with_underscores][chunked-example] inside it. See #823.
6767
| ^^^^^^^^^^^^^^^^^^^^^
6868

6969
error: you should put `inline_link2` between ticks in the documentation
70-
--> $DIR/doc.rs:53:21
70+
--> $DIR/doc.rs:55:21
7171
|
7272
LL | /// It can also be [inline_link2].
7373
| ^^^^^^^^^^^^
7474

7575
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
76-
--> $DIR/doc.rs:63:5
76+
--> $DIR/doc.rs:65:5
7777
|
7878
LL | /// be_sure_we_got_to_the_end_of_it
7979
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8080

8181
error: you should put `CamelCaseThing` between ticks in the documentation
82-
--> $DIR/doc.rs:71:8
82+
--> $DIR/doc.rs:73:8
8383
|
8484
LL | /// ## CamelCaseThing
8585
| ^^^^^^^^^^^^^^
8686

8787
error: you should put `CamelCaseThing` between ticks in the documentation
88-
--> $DIR/doc.rs:74:7
88+
--> $DIR/doc.rs:76:7
8989
|
9090
LL | /// # CamelCaseThing
9191
| ^^^^^^^^^^^^^^
9292

9393
error: you should put `CamelCaseThing` between ticks in the documentation
94-
--> $DIR/doc.rs:76:22
94+
--> $DIR/doc.rs:78:22
9595
|
9696
LL | /// Not a title #897 CamelCaseThing
9797
| ^^^^^^^^^^^^^^
9898

9999
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
100-
--> $DIR/doc.rs:77:5
100+
--> $DIR/doc.rs:79:5
101101
|
102102
LL | /// be_sure_we_got_to_the_end_of_it
103103
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
104104

105105
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
106-
--> $DIR/doc.rs:84:5
106+
--> $DIR/doc.rs:86:5
107107
|
108108
LL | /// be_sure_we_got_to_the_end_of_it
109109
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
110110

111111
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
112-
--> $DIR/doc.rs:97:5
112+
--> $DIR/doc.rs:99:5
113113
|
114114
LL | /// be_sure_we_got_to_the_end_of_it
115115
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
116116

117117
error: you should put `FooBar` between ticks in the documentation
118-
--> $DIR/doc.rs:108:42
118+
--> $DIR/doc.rs:110:42
119119
|
120120
LL | /** E.g. serialization of an empty list: FooBar
121121
| ^^^^^^
122122

123123
error: you should put `BarQuz` between ticks in the documentation
124-
--> $DIR/doc.rs:113:5
124+
--> $DIR/doc.rs:115:5
125125
|
126126
LL | And BarQuz too.
127127
| ^^^^^^
128128

129129
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
130-
--> $DIR/doc.rs:114:1
130+
--> $DIR/doc.rs:116:1
131131
|
132132
LL | be_sure_we_got_to_the_end_of_it
133133
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
134134

135135
error: you should put `FooBar` between ticks in the documentation
136-
--> $DIR/doc.rs:119:42
136+
--> $DIR/doc.rs:121:42
137137
|
138138
LL | /** E.g. serialization of an empty list: FooBar
139139
| ^^^^^^
140140

141141
error: you should put `BarQuz` between ticks in the documentation
142-
--> $DIR/doc.rs:124:5
142+
--> $DIR/doc.rs:126:5
143143
|
144144
LL | And BarQuz too.
145145
| ^^^^^^
146146

147147
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
148-
--> $DIR/doc.rs:125:1
148+
--> $DIR/doc.rs:127:1
149149
|
150150
LL | be_sure_we_got_to_the_end_of_it
151151
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
152152

153153
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
154-
--> $DIR/doc.rs:136:5
154+
--> $DIR/doc.rs:138:5
155155
|
156156
LL | /// be_sure_we_got_to_the_end_of_it
157157
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
158158

159159
error: you should put bare URLs between `<`/`>` or make a proper Markdown link
160-
--> $DIR/doc.rs:163:13
160+
--> $DIR/doc.rs:165:13
161161
|
162162
LL | /// Not ok: http://www.unicode.org
163163
| ^^^^^^^^^^^^^^^^^^^^^^
164164

165165
error: you should put bare URLs between `<`/`>` or make a proper Markdown link
166-
--> $DIR/doc.rs:164:13
166+
--> $DIR/doc.rs:166:13
167167
|
168168
LL | /// Not ok: https://www.unicode.org
169169
| ^^^^^^^^^^^^^^^^^^^^^^^
170170

171171
error: you should put bare URLs between `<`/`>` or make a proper Markdown link
172-
--> $DIR/doc.rs:165:13
172+
--> $DIR/doc.rs:167:13
173173
|
174174
LL | /// Not ok: http://www.unicode.org/
175175
| ^^^^^^^^^^^^^^^^^^^^^^
176176

177177
error: you should put bare URLs between `<`/`>` or make a proper Markdown link
178-
--> $DIR/doc.rs:166:13
178+
--> $DIR/doc.rs:168:13
179179
|
180180
LL | /// Not ok: http://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels
181181
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
182182

183183
error: you should put `mycrate::Collection` between ticks in the documentation
184-
--> $DIR/doc.rs:172:22
184+
--> $DIR/doc.rs:174:22
185185
|
186186
LL | /// An iterator over mycrate::Collection's values.
187187
| ^^^^^^^^^^^^^^^^^^^

tests/ui/unused_unit.fixed

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// run-rustfix
2+
3+
// The output for humans should just highlight the whole span without showing
4+
// the suggested replacement, but we also want to test that suggested
5+
// replacement only removes one set of parentheses, rather than naïvely
6+
// stripping away any starting or ending parenthesis characters—hence this
7+
// test of the JSON error format.
8+
9+
#![feature(custom_inner_attributes)]
10+
#![rustfmt::skip]
11+
12+
#![deny(clippy::unused_unit)]
13+
14+
struct Unitter;
15+
impl Unitter {
16+
// try to disorient the lint with multiple unit returns and newlines
17+
#[allow(clippy::no_effect)]
18+
pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G)
19+
where G: Fn() -> () {
20+
let _y: &Fn() -> () = &f;
21+
(); // this should not lint, as it's not in return type position
22+
}
23+
}
24+
25+
impl Into<()> for Unitter {
26+
#[rustfmt::skip]
27+
fn into(self) {
28+
29+
}
30+
}
31+
32+
fn return_unit() { }
33+
34+
#[allow(clippy::needless_return)]
35+
#[allow(clippy::never_loop)]
36+
fn main() {
37+
let u = Unitter;
38+
assert_eq!(u.get_unit(|| {}, return_unit), u.into());
39+
return_unit();
40+
loop {
41+
break;
42+
}
43+
return;
44+
}

tests/ui/unused_unit.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
// compile-pass
1+
// run-rustfix
22

33
// The output for humans should just highlight the whole span without showing
44
// the suggested replacement, but we also want to test that suggested
55
// replacement only removes one set of parentheses, rather than naïvely
66
// stripping away any starting or ending parenthesis characters—hence this
77
// test of the JSON error format.
88

9+
#![feature(custom_inner_attributes)]
10+
#![rustfmt::skip]
11+
912
#![deny(clippy::unused_unit)]
10-
#![allow(clippy::needless_return)]
1113

1214
struct Unitter;
1315
impl Unitter {
1416
// try to disorient the lint with multiple unit returns and newlines
17+
#[allow(clippy::no_effect)]
1518
pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) ->
1619
()
1720
where G: Fn() -> () {
@@ -29,6 +32,8 @@ impl Into<()> for Unitter {
2932

3033
fn return_unit() -> () { () }
3134

35+
#[allow(clippy::needless_return)]
36+
#[allow(clippy::never_loop)]
3237
fn main() {
3338
let u = Unitter;
3439
assert_eq!(u.get_unit(|| {}, return_unit), u.into());

tests/ui/unused_unit.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
error: unneeded unit return type
2-
--> $DIR/unused_unit.rs:15:59
2+
--> $DIR/unused_unit.rs:18:59
33
|
44
LL | pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) ->
55
| ___________________________________________________________^
66
LL | | ()
77
| |__________^ help: remove the `-> ()`
88
|
99
note: lint level defined here
10-
--> $DIR/unused_unit.rs:9:9
10+
--> $DIR/unused_unit.rs:12:9
1111
|
1212
LL | #![deny(clippy::unused_unit)]
1313
| ^^^^^^^^^^^^^^^^^^^
1414

1515
error: unneeded unit return type
16-
--> $DIR/unused_unit.rs:25:19
16+
--> $DIR/unused_unit.rs:28:19
1717
|
1818
LL | fn into(self) -> () {
1919
| ^^^^^ help: remove the `-> ()`
2020

2121
error: unneeded unit expression
22-
--> $DIR/unused_unit.rs:26:9
22+
--> $DIR/unused_unit.rs:29:9
2323
|
2424
LL | ()
2525
| ^^ help: remove the final `()`
2626

2727
error: unneeded unit return type
28-
--> $DIR/unused_unit.rs:30:18
28+
--> $DIR/unused_unit.rs:33:18
2929
|
3030
LL | fn return_unit() -> () { () }
3131
| ^^^^^ help: remove the `-> ()`
3232

3333
error: unneeded unit expression
34-
--> $DIR/unused_unit.rs:30:26
34+
--> $DIR/unused_unit.rs:33:26
3535
|
3636
LL | fn return_unit() -> () { () }
3737
| ^^ help: remove the final `()`
3838

3939
error: unneeded `()`
40-
--> $DIR/unused_unit.rs:37:14
40+
--> $DIR/unused_unit.rs:42:14
4141
|
4242
LL | break();
4343
| ^^ help: remove the `()`
4444

4545
error: unneeded `()`
46-
--> $DIR/unused_unit.rs:39:11
46+
--> $DIR/unused_unit.rs:44:11
4747
|
4848
LL | return();
4949
| ^^ help: remove the `()`

0 commit comments

Comments
 (0)