Skip to content

Commit b96c432

Browse files
author
Michael Wright
committed
Add #[rustfmt::skip] to methods tests
Many people run rustfmt automatically on save. Format-dependent tests should be marked with `#[rustfmt::skip]` to prevent accidental reformatting from this. As a bonus the rest of the code can the formatted.
1 parent 027dde9 commit b96c432

File tree

2 files changed

+42
-39
lines changed

2 files changed

+42
-39
lines changed

tests/ui/methods.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ impl Mul<T> for T {
103103
/// * `OPTION_MAP_UNWRAP_OR`
104104
/// * `OPTION_MAP_UNWRAP_OR_ELSE`
105105
/// * `OPTION_MAP_OR_NONE`
106+
#[rustfmt::skip]
106107
fn option_methods() {
107108
let opt = Some(1);
108109

@@ -175,6 +176,7 @@ impl HasIter {
175176
}
176177

177178
/// Checks implementation of `FILTER_NEXT` lint
179+
#[rustfmt::skip]
178180
fn filter_next() {
179181
let v = vec![3, 2, 1, 0, -1, -2, -3];
180182

@@ -193,6 +195,7 @@ fn filter_next() {
193195
}
194196

195197
/// Checks implementation of `SEARCH_IS_SOME` lint
198+
#[rustfmt::skip]
196199
fn search_is_some() {
197200
let v = vec![3, 2, 1, 0, -1, -2, -3];
198201

tests/ui/methods.stderr

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ LL | fn new(self) -> Self { unimplemented!(); }
2727
| ^^^^
2828

2929
error: called `map(f).unwrap_or(a)` on an Option value. This can be done more directly by calling `map_or(a, f)` instead
30-
--> $DIR/methods.rs:111:13
30+
--> $DIR/methods.rs:112:13
3131
|
3232
LL | let _ = opt.map(|x| x + 1)
3333
| _____________^
@@ -39,7 +39,7 @@ LL | | .unwrap_or(0); // should lint even though this call is on
3939
= note: replace `map(|x| x + 1).unwrap_or(0)` with `map_or(0, |x| x + 1)`
4040

4141
error: called `map(f).unwrap_or(a)` on an Option value. This can be done more directly by calling `map_or(a, f)` instead
42-
--> $DIR/methods.rs:115:13
42+
--> $DIR/methods.rs:116:13
4343
|
4444
LL | let _ = opt.map(|x| {
4545
| _____________^
@@ -49,7 +49,7 @@ LL | | ).unwrap_or(0);
4949
| |____________________________^
5050

5151
error: called `map(f).unwrap_or(a)` on an Option value. This can be done more directly by calling `map_or(a, f)` instead
52-
--> $DIR/methods.rs:119:13
52+
--> $DIR/methods.rs:120:13
5353
|
5454
LL | let _ = opt.map(|x| x + 1)
5555
| _____________^
@@ -59,15 +59,15 @@ LL | | });
5959
| |__________________^
6060

6161
error: called `map(f).unwrap_or(None)` on an Option value. This can be done more directly by calling `and_then(f)` instead
62-
--> $DIR/methods.rs:124:13
62+
--> $DIR/methods.rs:125:13
6363
|
6464
LL | let _ = opt.map(|x| Some(x + 1)).unwrap_or(None);
6565
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6666
|
6767
= note: replace `map(|x| Some(x + 1)).unwrap_or(None)` with `and_then(|x| Some(x + 1))`
6868

6969
error: called `map(f).unwrap_or(None)` on an Option value. This can be done more directly by calling `and_then(f)` instead
70-
--> $DIR/methods.rs:126:13
70+
--> $DIR/methods.rs:127:13
7171
|
7272
LL | let _ = opt.map(|x| {
7373
| _____________^
@@ -77,7 +77,7 @@ LL | | ).unwrap_or(None);
7777
| |_____________________^
7878

7979
error: called `map(f).unwrap_or(None)` on an Option value. This can be done more directly by calling `and_then(f)` instead
80-
--> $DIR/methods.rs:130:13
80+
--> $DIR/methods.rs:131:13
8181
|
8282
LL | let _ = opt
8383
| _____________^
@@ -88,7 +88,7 @@ LL | | .unwrap_or(None);
8888
= note: replace `map(|x| Some(x + 1)).unwrap_or(None)` with `and_then(|x| Some(x + 1))`
8989

9090
error: called `map(f).unwrap_or_else(g)` on an Option value. This can be done more directly by calling `map_or_else(g, f)` instead
91-
--> $DIR/methods.rs:138:13
91+
--> $DIR/methods.rs:139:13
9292
|
9393
LL | let _ = opt.map(|x| x + 1)
9494
| _____________^
@@ -100,7 +100,7 @@ LL | | .unwrap_or_else(|| 0); // should lint even though this cal
100100
= note: replace `map(|x| x + 1).unwrap_or_else(|| 0)` with `map_or_else(|| 0, |x| x + 1)`
101101

102102
error: called `map(f).unwrap_or_else(g)` on an Option value. This can be done more directly by calling `map_or_else(g, f)` instead
103-
--> $DIR/methods.rs:142:13
103+
--> $DIR/methods.rs:143:13
104104
|
105105
LL | let _ = opt.map(|x| {
106106
| _____________^
@@ -110,7 +110,7 @@ LL | | ).unwrap_or_else(|| 0);
110110
| |____________________________________^
111111

112112
error: called `map(f).unwrap_or_else(g)` on an Option value. This can be done more directly by calling `map_or_else(g, f)` instead
113-
--> $DIR/methods.rs:146:13
113+
--> $DIR/methods.rs:147:13
114114
|
115115
LL | let _ = opt.map(|x| x + 1)
116116
| _____________^
@@ -120,15 +120,15 @@ LL | | );
120120
| |_________________^
121121

122122
error: called `map_or(None, f)` on an Option value. This can be done more directly by calling `and_then(f)` instead
123-
--> $DIR/methods.rs:155:13
123+
--> $DIR/methods.rs:156:13
124124
|
125125
LL | let _ = opt.map_or(None, |x| Some(x + 1));
126126
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using and_then instead: `opt.and_then(|x| Some(x + 1))`
127127
|
128128
= note: `-D clippy::option-map-or-none` implied by `-D warnings`
129129

130130
error: called `map_or(None, f)` on an Option value. This can be done more directly by calling `and_then(f)` instead
131-
--> $DIR/methods.rs:157:13
131+
--> $DIR/methods.rs:158:13
132132
|
133133
LL | let _ = opt.map_or(None, |x| {
134134
| _____________^
@@ -144,7 +144,7 @@ LL | });
144144
|
145145

146146
error: called `filter(p).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(p)` instead.
147-
--> $DIR/methods.rs:182:13
147+
--> $DIR/methods.rs:184:13
148148
|
149149
LL | let _ = v.iter().filter(|&x| *x < 0).next();
150150
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -153,7 +153,7 @@ LL | let _ = v.iter().filter(|&x| *x < 0).next();
153153
= note: replace `filter(|&x| *x < 0).next()` with `find(|&x| *x < 0)`
154154

155155
error: called `filter(p).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(p)` instead.
156-
--> $DIR/methods.rs:185:13
156+
--> $DIR/methods.rs:187:13
157157
|
158158
LL | let _ = v.iter().filter(|&x| {
159159
| _____________^
@@ -163,7 +163,7 @@ LL | | ).next();
163163
| |___________________________^
164164

165165
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
166-
--> $DIR/methods.rs:200:13
166+
--> $DIR/methods.rs:203:13
167167
|
168168
LL | let _ = v.iter().find(|&x| *x < 0).is_some();
169169
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -172,7 +172,7 @@ LL | let _ = v.iter().find(|&x| *x < 0).is_some();
172172
= note: replace `find(|&x| *x < 0).is_some()` with `any(|&x| *x < 0)`
173173

174174
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
175-
--> $DIR/methods.rs:203:13
175+
--> $DIR/methods.rs:206:13
176176
|
177177
LL | let _ = v.iter().find(|&x| {
178178
| _____________^
@@ -182,15 +182,15 @@ LL | | ).is_some();
182182
| |______________________________^
183183

184184
error: called `is_some()` after searching an `Iterator` with position. This is more succinctly expressed by calling `any()`.
185-
--> $DIR/methods.rs:209:13
185+
--> $DIR/methods.rs:212:13
186186
|
187187
LL | let _ = v.iter().position(|&x| x < 0).is_some();
188188
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
189189
|
190190
= note: replace `position(|&x| x < 0).is_some()` with `any(|&x| x < 0)`
191191

192192
error: called `is_some()` after searching an `Iterator` with position. This is more succinctly expressed by calling `any()`.
193-
--> $DIR/methods.rs:212:13
193+
--> $DIR/methods.rs:215:13
194194
|
195195
LL | let _ = v.iter().position(|&x| {
196196
| _____________^
@@ -200,15 +200,15 @@ LL | | ).is_some();
200200
| |______________________________^
201201

202202
error: called `is_some()` after searching an `Iterator` with rposition. This is more succinctly expressed by calling `any()`.
203-
--> $DIR/methods.rs:218:13
203+
--> $DIR/methods.rs:221:13
204204
|
205205
LL | let _ = v.iter().rposition(|&x| x < 0).is_some();
206206
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
207207
|
208208
= note: replace `rposition(|&x| x < 0).is_some()` with `any(|&x| x < 0)`
209209

210210
error: called `is_some()` after searching an `Iterator` with rposition. This is more succinctly expressed by calling `any()`.
211-
--> $DIR/methods.rs:221:13
211+
--> $DIR/methods.rs:224:13
212212
|
213213
LL | let _ = v.iter().rposition(|&x| {
214214
| _____________^
@@ -218,125 +218,125 @@ LL | | ).is_some();
218218
| |______________________________^
219219

220220
error: use of `unwrap_or` followed by a function call
221-
--> $DIR/methods.rs:256:22
221+
--> $DIR/methods.rs:259:22
222222
|
223223
LL | with_constructor.unwrap_or(make());
224224
| ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(make)`
225225
|
226226
= note: `-D clippy::or-fun-call` implied by `-D warnings`
227227

228228
error: use of `unwrap_or` followed by a call to `new`
229-
--> $DIR/methods.rs:259:5
229+
--> $DIR/methods.rs:262:5
230230
|
231231
LL | with_new.unwrap_or(Vec::new());
232232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_new.unwrap_or_default()`
233233

234234
error: use of `unwrap_or` followed by a function call
235-
--> $DIR/methods.rs:262:21
235+
--> $DIR/methods.rs:265:21
236236
|
237237
LL | with_const_args.unwrap_or(Vec::with_capacity(12));
238238
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| Vec::with_capacity(12))`
239239

240240
error: use of `unwrap_or` followed by a function call
241-
--> $DIR/methods.rs:265:14
241+
--> $DIR/methods.rs:268:14
242242
|
243243
LL | with_err.unwrap_or(make());
244244
| ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| make())`
245245

246246
error: use of `unwrap_or` followed by a function call
247-
--> $DIR/methods.rs:268:19
247+
--> $DIR/methods.rs:271:19
248248
|
249249
LL | with_err_args.unwrap_or(Vec::with_capacity(12));
250250
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| Vec::with_capacity(12))`
251251

252252
error: use of `unwrap_or` followed by a call to `default`
253-
--> $DIR/methods.rs:271:5
253+
--> $DIR/methods.rs:274:5
254254
|
255255
LL | with_default_trait.unwrap_or(Default::default());
256256
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_default_trait.unwrap_or_default()`
257257

258258
error: use of `unwrap_or` followed by a call to `default`
259-
--> $DIR/methods.rs:274:5
259+
--> $DIR/methods.rs:277:5
260260
|
261261
LL | with_default_type.unwrap_or(u64::default());
262262
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_default_type.unwrap_or_default()`
263263

264264
error: use of `unwrap_or` followed by a function call
265-
--> $DIR/methods.rs:277:14
265+
--> $DIR/methods.rs:280:14
266266
|
267267
LL | with_vec.unwrap_or(vec![]);
268268
| ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| vec![])`
269269

270270
error: use of `unwrap_or` followed by a function call
271-
--> $DIR/methods.rs:282:21
271+
--> $DIR/methods.rs:285:21
272272
|
273273
LL | without_default.unwrap_or(Foo::new());
274274
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(Foo::new)`
275275

276276
error: use of `or_insert` followed by a function call
277-
--> $DIR/methods.rs:285:19
277+
--> $DIR/methods.rs:288:19
278278
|
279279
LL | map.entry(42).or_insert(String::new());
280280
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_insert_with(String::new)`
281281

282282
error: use of `or_insert` followed by a function call
283-
--> $DIR/methods.rs:288:21
283+
--> $DIR/methods.rs:291:21
284284
|
285285
LL | btree.entry(42).or_insert(String::new());
286286
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_insert_with(String::new)`
287287

288288
error: use of `unwrap_or` followed by a function call
289-
--> $DIR/methods.rs:291:21
289+
--> $DIR/methods.rs:294:21
290290
|
291291
LL | let _ = stringy.unwrap_or("".to_owned());
292292
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| "".to_owned())`
293293

294294
error: called `.iter().nth()` on a Vec. Calling `.get()` is both faster and more readable
295-
--> $DIR/methods.rs:302:23
295+
--> $DIR/methods.rs:305:23
296296
|
297297
LL | let bad_vec = some_vec.iter().nth(3);
298298
| ^^^^^^^^^^^^^^^^^^^^^^
299299
|
300300
= note: `-D clippy::iter-nth` implied by `-D warnings`
301301

302302
error: called `.iter().nth()` on a slice. Calling `.get()` is both faster and more readable
303-
--> $DIR/methods.rs:303:26
303+
--> $DIR/methods.rs:306:26
304304
|
305305
LL | let bad_slice = &some_vec[..].iter().nth(3);
306306
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
307307

308308
error: called `.iter().nth()` on a slice. Calling `.get()` is both faster and more readable
309-
--> $DIR/methods.rs:304:31
309+
--> $DIR/methods.rs:307:31
310310
|
311311
LL | let bad_boxed_slice = boxed_slice.iter().nth(3);
312312
| ^^^^^^^^^^^^^^^^^^^^^^^^^
313313

314314
error: called `.iter().nth()` on a VecDeque. Calling `.get()` is both faster and more readable
315-
--> $DIR/methods.rs:305:29
315+
--> $DIR/methods.rs:308:29
316316
|
317317
LL | let bad_vec_deque = some_vec_deque.iter().nth(3);
318318
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
319319

320320
error: called `.iter_mut().nth()` on a Vec. Calling `.get_mut()` is both faster and more readable
321-
--> $DIR/methods.rs:310:23
321+
--> $DIR/methods.rs:313:23
322322
|
323323
LL | let bad_vec = some_vec.iter_mut().nth(3);
324324
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
325325

326326
error: called `.iter_mut().nth()` on a slice. Calling `.get_mut()` is both faster and more readable
327-
--> $DIR/methods.rs:313:26
327+
--> $DIR/methods.rs:316:26
328328
|
329329
LL | let bad_slice = &some_vec[..].iter_mut().nth(3);
330330
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
331331

332332
error: called `.iter_mut().nth()` on a VecDeque. Calling `.get_mut()` is both faster and more readable
333-
--> $DIR/methods.rs:316:29
333+
--> $DIR/methods.rs:319:29
334334
|
335335
LL | let bad_vec_deque = some_vec_deque.iter_mut().nth(3);
336336
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
337337

338338
error: used unwrap() on an Option value. If you don't want to handle the None case gracefully, consider using expect() to provide a better panic message
339-
--> $DIR/methods.rs:328:13
339+
--> $DIR/methods.rs:331:13
340340
|
341341
LL | let _ = opt.unwrap();
342342
| ^^^^^^^^^^^^

0 commit comments

Comments
 (0)