Skip to content

Commit f7dd769

Browse files
authored
Merge pull request #1873 from uHOOCCOOHu/fix-tests
Fix tests.
2 parents e88c29c + a80db63 commit f7dd769

File tree

4 files changed

+85
-106
lines changed

4 files changed

+85
-106
lines changed

clippy_tests/examples/for_loop.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(plugin, step_by, inclusive_range_syntax)]
1+
#![feature(plugin, inclusive_range_syntax)]
22
#![plugin(clippy)]
33

44
use std::collections::*;
@@ -189,10 +189,6 @@ fn main() {
189189
println!("{}", i);
190190
}
191191

192-
for i in (10..8).step_by(-1) {
193-
println!("{}", i);
194-
}
195-
196192
let x = 42;
197193
for i in x..10 { // no error, not constant-foldable
198194
println!("{}", i);

clippy_tests/examples/for_loop.stderr

+57-65
Original file line numberDiff line numberDiff line change
@@ -292,183 +292,175 @@ error: this range is empty so this for loop will never run
292292
186 | | }
293293
| |_____^
294294

295-
error: use of deprecated item: replaced by `Iterator::step_by`
296-
--> for_loop.rs:192:22
297-
|
298-
192 | for i in (10..8).step_by(-1) {
299-
| ^^^^^^^
300-
|
301-
= note: `-D deprecated` implied by `-D warnings`
302-
303295
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
304-
--> for_loop.rs:207:15
296+
--> for_loop.rs:203:15
305297
|
306-
207 | for _v in vec.iter() { }
298+
203 | for _v in vec.iter() { }
307299
| ^^^^^^^^^^ help: to write this more concisely, try `&vec`
308300
|
309301
= note: `-D explicit-iter-loop` implied by `-D warnings`
310302

311303
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
312-
--> for_loop.rs:209:15
304+
--> for_loop.rs:205:15
313305
|
314-
209 | for _v in vec.iter_mut() { }
306+
205 | for _v in vec.iter_mut() { }
315307
| ^^^^^^^^^^^^^^ help: to write this more concisely, try `&mut vec`
316308

317309
error: it is more idiomatic to loop over containers instead of using explicit iteration methods`
318-
--> for_loop.rs:212:15
310+
--> for_loop.rs:208:15
319311
|
320-
212 | for _v in out_vec.into_iter() { }
312+
208 | for _v in out_vec.into_iter() { }
321313
| ^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try `out_vec`
322314
|
323315
= note: `-D explicit-into-iter-loop` implied by `-D warnings`
324316

325317
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
326-
--> for_loop.rs:215:15
318+
--> for_loop.rs:211:15
327319
|
328-
215 | for _v in array.into_iter() {}
320+
211 | for _v in array.into_iter() {}
329321
| ^^^^^^^^^^^^^^^^^ help: to write this more concisely, try `&array`
330322

331323
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
332-
--> for_loop.rs:220:15
324+
--> for_loop.rs:216:15
333325
|
334-
220 | for _v in [1, 2, 3].iter() { }
326+
216 | for _v in [1, 2, 3].iter() { }
335327
| ^^^^^^^^^^^^^^^^ help: to write this more concisely, try `&[1, 2, 3]`
336328

337329
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
338-
--> for_loop.rs:224:15
330+
--> for_loop.rs:220:15
339331
|
340-
224 | for _v in [0; 32].iter() {}
332+
220 | for _v in [0; 32].iter() {}
341333
| ^^^^^^^^^^^^^^ help: to write this more concisely, try `&[0; 32]`
342334

343335
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
344-
--> for_loop.rs:229:15
336+
--> for_loop.rs:225:15
345337
|
346-
229 | for _v in ll.iter() { }
338+
225 | for _v in ll.iter() { }
347339
| ^^^^^^^^^ help: to write this more concisely, try `&ll`
348340

349341
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
350-
--> for_loop.rs:232:15
342+
--> for_loop.rs:228:15
351343
|
352-
232 | for _v in vd.iter() { }
344+
228 | for _v in vd.iter() { }
353345
| ^^^^^^^^^ help: to write this more concisely, try `&vd`
354346

355347
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
356-
--> for_loop.rs:235:15
348+
--> for_loop.rs:231:15
357349
|
358-
235 | for _v in bh.iter() { }
350+
231 | for _v in bh.iter() { }
359351
| ^^^^^^^^^ help: to write this more concisely, try `&bh`
360352

361353
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
362-
--> for_loop.rs:238:15
354+
--> for_loop.rs:234:15
363355
|
364-
238 | for _v in hm.iter() { }
356+
234 | for _v in hm.iter() { }
365357
| ^^^^^^^^^ help: to write this more concisely, try `&hm`
366358

367359
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
368-
--> for_loop.rs:241:15
360+
--> for_loop.rs:237:15
369361
|
370-
241 | for _v in bt.iter() { }
362+
237 | for _v in bt.iter() { }
371363
| ^^^^^^^^^ help: to write this more concisely, try `&bt`
372364

373365
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
374-
--> for_loop.rs:244:15
366+
--> for_loop.rs:240:15
375367
|
376-
244 | for _v in hs.iter() { }
368+
240 | for _v in hs.iter() { }
377369
| ^^^^^^^^^ help: to write this more concisely, try `&hs`
378370

379371
error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
380-
--> for_loop.rs:247:15
372+
--> for_loop.rs:243:15
381373
|
382-
247 | for _v in bs.iter() { }
374+
243 | for _v in bs.iter() { }
383375
| ^^^^^^^^^ help: to write this more concisely, try `&bs`
384376

385377
error: you are iterating over `Iterator::next()` which is an Option; this will compile but is probably not what you want
386-
--> for_loop.rs:249:5
378+
--> for_loop.rs:245:5
387379
|
388-
249 | for _v in vec.iter().next() { }
380+
245 | for _v in vec.iter().next() { }
389381
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
390382

391383
error: you are collect()ing an iterator and throwing away the result. Consider using an explicit for loop to exhaust the iterator
392-
--> for_loop.rs:256:5
384+
--> for_loop.rs:252:5
393385
|
394-
256 | vec.iter().map(|x| out.push(x)).collect::<Vec<_>>();
386+
252 | vec.iter().map(|x| out.push(x)).collect::<Vec<_>>();
395387
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
396388
|
397389
= note: `-D unused-collect` implied by `-D warnings`
398390

399391
error: the variable `_index` is used as a loop counter. Consider using `for (_index, item) in &vec.enumerate()` or similar iterators
400-
--> for_loop.rs:261:5
392+
--> for_loop.rs:257:5
401393
|
402-
261 | for _v in &vec { _index += 1 }
394+
257 | for _v in &vec { _index += 1 }
403395
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
404396
|
405397
= note: `-D explicit-counter-loop` implied by `-D warnings`
406398

407399
error: the variable `_index` is used as a loop counter. Consider using `for (_index, item) in &vec.enumerate()` or similar iterators
408-
--> for_loop.rs:265:5
400+
--> for_loop.rs:261:5
409401
|
410-
265 | for _v in &vec { _index += 1 }
402+
261 | for _v in &vec { _index += 1 }
411403
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
412404

413405
error: you seem to want to iterate on a map's values
414-
--> for_loop.rs:325:5
406+
--> for_loop.rs:321:5
415407
|
416-
325 | / for (_, v) in &m {
417-
326 | | let _v = v;
418-
327 | | }
408+
321 | / for (_, v) in &m {
409+
322 | | let _v = v;
410+
323 | | }
419411
| |_____^
420412
|
421413
= note: `-D for-kv-map` implied by `-D warnings`
422414
help: use the corresponding method
423415
| for v in m.values() {
424416

425417
error: you seem to want to iterate on a map's values
426-
--> for_loop.rs:330:5
418+
--> for_loop.rs:326:5
427419
|
428-
330 | / for (_, v) in &*m {
429-
331 | | let _v = v;
430-
332 | | // Here the `*` is not actually necesarry, but the test tests that we don't suggest
431-
333 | | // `in *m.values()` as we used to
432-
334 | | }
420+
326 | / for (_, v) in &*m {
421+
327 | | let _v = v;
422+
328 | | // Here the `*` is not actually necesarry, but the test tests that we don't suggest
423+
329 | | // `in *m.values()` as we used to
424+
330 | | }
433425
| |_____^
434426
|
435427
help: use the corresponding method
436428
| for v in (*m).values() {
437429

438430
error: you seem to want to iterate on a map's values
439-
--> for_loop.rs:337:5
431+
--> for_loop.rs:333:5
440432
|
441-
337 | / for (_, v) in &mut m {
442-
338 | | let _v = v;
443-
339 | | }
433+
333 | / for (_, v) in &mut m {
434+
334 | | let _v = v;
435+
335 | | }
444436
| |_____^
445437
|
446438
help: use the corresponding method
447439
| for v in m.values_mut() {
448440

449441
error: you seem to want to iterate on a map's values
450-
--> for_loop.rs:342:5
442+
--> for_loop.rs:338:5
451443
|
452-
342 | / for (_, v) in &mut *m {
453-
343 | | let _v = v;
454-
344 | | }
444+
338 | / for (_, v) in &mut *m {
445+
339 | | let _v = v;
446+
340 | | }
455447
| |_____^
456448
|
457449
help: use the corresponding method
458450
| for v in (*m).values_mut() {
459451

460452
error: you seem to want to iterate on a map's keys
461-
--> for_loop.rs:348:5
453+
--> for_loop.rs:344:5
462454
|
463-
348 | / for (k, _value) in rm {
464-
349 | | let _k = k;
465-
350 | | }
455+
344 | / for (k, _value) in rm {
456+
345 | | let _k = k;
457+
346 | | }
466458
| |_____^
467459
|
468460
help: use the corresponding method
469461
| for k in rm.keys() {
470462

471-
error: aborting due to 52 previous errors
463+
error: aborting due to 51 previous errors
472464

473465

474466
To learn more, run the command again with --verbose.

clippy_tests/examples/range.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(iterator_step_by)]
2-
#![feature(step_by)]
32
#![feature(inclusive_range_syntax)]
43
#![feature(plugin)]
54
#![plugin(clippy)]
@@ -11,15 +10,15 @@ impl NotARange {
1110

1211
#[warn(iterator_step_by_zero, range_zip_with_len)]
1312
fn main() {
14-
(0..1).step_by(0);
13+
let _ = (0..1).step_by(0);
1514
// No warning for non-zero step
16-
(0..1).step_by(1);
15+
let _ = (0..1).step_by(1);
1716

18-
(1..).step_by(0);
19-
(1...2).step_by(0);
17+
let _ = (1..).step_by(0);
18+
let _ = (1...2).step_by(0);
2019

2120
let x = 0..1;
22-
x.step_by(0);
21+
let _ = x.step_by(0);
2322

2423
// No error, not a range.
2524
let y = NotARange;

clippy_tests/examples/range.stderr

+22-30
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,44 @@
1-
error: use of deprecated item: replaced by `Iterator::step_by`
2-
--> range.rs:14:12
3-
|
4-
14 | (0..1).step_by(0);
5-
| ^^^^^^^
1+
error: Iterator::step_by(0) will panic at runtime
2+
--> range.rs:13:13
63
|
7-
= note: `-D deprecated` implied by `-D warnings`
8-
9-
error: use of deprecated item: replaced by `Iterator::step_by`
10-
--> range.rs:16:12
4+
13 | let _ = (0..1).step_by(0);
5+
| ^^^^^^^^^^^^^^^^^
116
|
12-
16 | (0..1).step_by(1);
13-
| ^^^^^^^
7+
= note: `-D iterator-step-by-zero` implied by `-D warnings`
148

15-
error: use of deprecated item: replaced by `Iterator::step_by`
16-
--> range.rs:18:11
9+
error: Iterator::step_by(0) will panic at runtime
10+
--> range.rs:17:13
1711
|
18-
18 | (1..).step_by(0);
19-
| ^^^^^^^
12+
17 | let _ = (1..).step_by(0);
13+
| ^^^^^^^^^^^^^^^^
2014

21-
error: use of deprecated item: replaced by `Iterator::step_by`
22-
--> range.rs:19:13
15+
error: Iterator::step_by(0) will panic at runtime
16+
--> range.rs:18:13
2317
|
24-
19 | (1...2).step_by(0);
25-
| ^^^^^^^
18+
18 | let _ = (1...2).step_by(0);
19+
| ^^^^^^^^^^^^^^^^^^
2620

27-
error: use of deprecated item: replaced by `Iterator::step_by`
28-
--> range.rs:22:7
21+
error: Iterator::step_by(0) will panic at runtime
22+
--> range.rs:21:13
2923
|
30-
22 | x.step_by(0);
31-
| ^^^^^^^
24+
21 | let _ = x.step_by(0);
25+
| ^^^^^^^^^^^^
3226

3327
error: It is more idiomatic to use v1.iter().enumerate()
34-
--> range.rs:30:14
28+
--> range.rs:29:14
3529
|
36-
30 | let _x = v1.iter().zip(0..v1.len());
30+
29 | let _x = v1.iter().zip(0..v1.len());
3731
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
3832
|
3933
= note: `-D range-zip-with-len` implied by `-D warnings`
4034

4135
error: Iterator::step_by(0) will panic at runtime
42-
--> range.rs:34:13
36+
--> range.rs:33:13
4337
|
44-
34 | let _ = v1.iter().step_by(2/3);
38+
33 | let _ = v1.iter().step_by(2/3);
4539
| ^^^^^^^^^^^^^^^^^^^^^^
46-
|
47-
= note: `-D iterator-step-by-zero` implied by `-D warnings`
4840

49-
error: aborting due to 7 previous errors
41+
error: aborting due to 6 previous errors
5042

5143

5244
To learn more, run the command again with --verbose.

0 commit comments

Comments
 (0)