]> git.lizzy.rs Git - rust.git/blob - tests/ui/for_loop.stderr
Reduce the hackiness of cargo-clippy
[rust.git] / tests / ui / for_loop.stderr
1 error: for loop over `option`, which is an `Option`. This is more readably written as an `if let` statement.
2   --> $DIR/for_loop.rs:17:14
3    |
4 17 |     for x in option {
5    |              ^^^^^^
6    |
7    = note: `-D for-loop-over-option` implied by `-D warnings`
8    = help: consider replacing `for x in option` with `if let Some(x) = option`
9
10 error: for loop over `result`, which is a `Result`. This is more readably written as an `if let` statement.
11   --> $DIR/for_loop.rs:22:14
12    |
13 22 |     for x in result {
14    |              ^^^^^^
15    |
16    = note: `-D for-loop-over-result` implied by `-D warnings`
17    = help: consider replacing `for x in result` with `if let Ok(x) = result`
18
19 error: for loop over `option.ok_or("x not found")`, which is a `Result`. This is more readably written as an `if let` statement.
20   --> $DIR/for_loop.rs:26:14
21    |
22 26 |     for x in option.ok_or("x not found") {
23    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
24    |
25    = help: consider replacing `for x in option.ok_or("x not found")` with `if let Ok(x) = option.ok_or("x not found")`
26
27 error: you are iterating over `Iterator::next()` which is an Option; this will compile but is probably not what you want
28   --> $DIR/for_loop.rs:32:5
29    |
30 32 | /     for x in v.iter().next() {
31 33 | |         println!("{}", x);
32 34 | |     }
33    | |_____^
34    |
35    = note: `-D iter-next-loop` implied by `-D warnings`
36
37 error: for loop over `v.iter().next().and(Some(0))`, which is an `Option`. This is more readably written as an `if let` statement.
38   --> $DIR/for_loop.rs:37:14
39    |
40 37 |     for x in v.iter().next().and(Some(0)) {
41    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42    |
43    = help: consider replacing `for x in v.iter().next().and(Some(0))` with `if let Some(x) = v.iter().next().and(Some(0))`
44
45 error: for loop over `v.iter().next().ok_or("x not found")`, which is a `Result`. This is more readably written as an `if let` statement.
46   --> $DIR/for_loop.rs:41:14
47    |
48 41 |     for x in v.iter().next().ok_or("x not found") {
49    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
50    |
51    = help: consider replacing `for x in v.iter().next().ok_or("x not found")` with `if let Ok(x) = v.iter().next().ok_or("x not found")`
52
53 error: this loop never actually loops
54   --> $DIR/for_loop.rs:53:5
55    |
56 53 | /     while let Some(x) = option {
57 54 | |         println!("{}", x);
58 55 | |         break;
59 56 | |     }
60    | |_____^
61    |
62    = note: `-D never-loop` implied by `-D warnings`
63
64 error: this loop never actually loops
65   --> $DIR/for_loop.rs:59:5
66    |
67 59 | /     while let Ok(x) = result {
68 60 | |         println!("{}", x);
69 61 | |         break;
70 62 | |     }
71    | |_____^
72
73 error: the loop variable `i` is only used to index `vec`.
74   --> $DIR/for_loop.rs:86:5
75    |
76 86 | /     for i in 0..vec.len() {
77 87 | |         println!("{}", vec[i]);
78 88 | |     }
79    | |_____^
80    |
81    = note: `-D needless-range-loop` implied by `-D warnings`
82 help: consider using an iterator
83    |
84 86 |     for <item> in &vec {
85    |         ^^^^^^
86
87 error: the loop variable `i` is only used to index `vec`.
88   --> $DIR/for_loop.rs:95:5
89    |
90 95 | /     for i in 0..vec.len() {
91 96 | |         let _ = vec[i];
92 97 | |     }
93    | |_____^
94    |
95 help: consider using an iterator
96    |
97 95 |     for <item> in &vec {
98    |         ^^^^^^
99
100 error: the loop variable `j` is only used to index `STATIC`.
101    --> $DIR/for_loop.rs:100:5
102     |
103 100 | /     for j in 0..4 {
104 101 | |         println!("{:?}", STATIC[j]);
105 102 | |     }
106     | |_____^
107     |
108 help: consider using an iterator
109     |
110 100 |     for <item> in STATIC.iter().take(4) {
111     |         ^^^^^^
112
113 error: the loop variable `j` is only used to index `CONST`.
114    --> $DIR/for_loop.rs:104:5
115     |
116 104 | /     for j in 0..4 {
117 105 | |         println!("{:?}", CONST[j]);
118 106 | |     }
119     | |_____^
120     |
121 help: consider using an iterator
122     |
123 104 |     for <item> in CONST.iter().take(4) {
124     |         ^^^^^^
125
126 error: the loop variable `i` is used to index `vec`
127    --> $DIR/for_loop.rs:108:5
128     |
129 108 | /     for i in 0..vec.len() {
130 109 | |         println!("{} {}", vec[i], i);
131 110 | |     }
132     | |_____^
133     |
134 help: consider using an iterator
135     |
136 108 |     for (i, <item>) in vec.iter().enumerate() {
137     |         ^^^^^^^^^^^
138
139 error: the loop variable `i` is only used to index `vec2`.
140    --> $DIR/for_loop.rs:116:5
141     |
142 116 | /     for i in 0..vec.len() {
143 117 | |         println!("{}", vec2[i]);
144 118 | |     }
145     | |_____^
146     |
147 help: consider using an iterator
148     |
149 116 |     for <item> in vec2.iter().take(vec.len()) {
150     |         ^^^^^^
151
152 error: the loop variable `i` is only used to index `vec`.
153    --> $DIR/for_loop.rs:120:5
154     |
155 120 | /     for i in 5..vec.len() {
156 121 | |         println!("{}", vec[i]);
157 122 | |     }
158     | |_____^
159     |
160 help: consider using an iterator
161     |
162 120 |     for <item> in vec.iter().skip(5) {
163     |         ^^^^^^
164
165 error: the loop variable `i` is only used to index `vec`.
166    --> $DIR/for_loop.rs:124:5
167     |
168 124 | /     for i in 0..MAX_LEN {
169 125 | |         println!("{}", vec[i]);
170 126 | |     }
171     | |_____^
172     |
173 help: consider using an iterator
174     |
175 124 |     for <item> in vec.iter().take(MAX_LEN) {
176     |         ^^^^^^
177
178 error: the loop variable `i` is only used to index `vec`.
179    --> $DIR/for_loop.rs:128:5
180     |
181 128 | /     for i in 0..=MAX_LEN {
182 129 | |         println!("{}", vec[i]);
183 130 | |     }
184     | |_____^
185     |
186 help: consider using an iterator
187     |
188 128 |     for <item> in vec.iter().take(MAX_LEN + 1) {
189     |         ^^^^^^
190
191 error: the loop variable `i` is only used to index `vec`.
192    --> $DIR/for_loop.rs:132:5
193     |
194 132 | /     for i in 5..10 {
195 133 | |         println!("{}", vec[i]);
196 134 | |     }
197     | |_____^
198     |
199 help: consider using an iterator
200     |
201 132 |     for <item> in vec.iter().take(10).skip(5) {
202     |         ^^^^^^
203
204 error: the loop variable `i` is only used to index `vec`.
205    --> $DIR/for_loop.rs:136:5
206     |
207 136 | /     for i in 5..=10 {
208 137 | |         println!("{}", vec[i]);
209 138 | |     }
210     | |_____^
211     |
212 help: consider using an iterator
213     |
214 136 |     for <item> in vec.iter().take(10 + 1).skip(5) {
215     |         ^^^^^^
216
217 error: the loop variable `i` is used to index `vec`
218    --> $DIR/for_loop.rs:140:5
219     |
220 140 | /     for i in 5..vec.len() {
221 141 | |         println!("{} {}", vec[i], i);
222 142 | |     }
223     | |_____^
224     |
225 help: consider using an iterator
226     |
227 140 |     for (i, <item>) in vec.iter().enumerate().skip(5) {
228     |         ^^^^^^^^^^^
229
230 error: the loop variable `i` is used to index `vec`
231    --> $DIR/for_loop.rs:144:5
232     |
233 144 | /     for i in 5..10 {
234 145 | |         println!("{} {}", vec[i], i);
235 146 | |     }
236     | |_____^
237     |
238 help: consider using an iterator
239     |
240 144 |     for (i, <item>) in vec.iter().enumerate().take(10).skip(5) {
241     |         ^^^^^^^^^^^
242
243 error: this range is empty so this for loop will never run
244    --> $DIR/for_loop.rs:148:5
245     |
246 148 | /     for i in 10..0 {
247 149 | |         println!("{}", i);
248 150 | |     }
249     | |_____^
250     |
251     = note: `-D reverse-range-loop` implied by `-D warnings`
252 help: consider using the following if you are attempting to iterate over this range in reverse
253     |
254 148 |     for i in (0..10).rev() {
255     |              ^^^^^^^^^^^^^
256
257 error: this range is empty so this for loop will never run
258    --> $DIR/for_loop.rs:152:5
259     |
260 152 | /     for i in 10..=0 {
261 153 | |         println!("{}", i);
262 154 | |     }
263     | |_____^
264     |
265 help: consider using the following if you are attempting to iterate over this range in reverse
266     |
267 152 |     for i in (0...10).rev() {
268     |              ^^^^^^^^^^^^^^
269
270 error: this range is empty so this for loop will never run
271    --> $DIR/for_loop.rs:156:5
272     |
273 156 | /     for i in MAX_LEN..0 {
274 157 | |         println!("{}", i);
275 158 | |     }
276     | |_____^
277     |
278 help: consider using the following if you are attempting to iterate over this range in reverse
279     |
280 156 |     for i in (0..MAX_LEN).rev() {
281     |              ^^^^^^^^^^^^^^^^^^
282
283 error: this range is empty so this for loop will never run
284    --> $DIR/for_loop.rs:160:5
285     |
286 160 | /     for i in 5..5 {
287 161 | |         println!("{}", i);
288 162 | |     }
289     | |_____^
290
291 error: this range is empty so this for loop will never run
292    --> $DIR/for_loop.rs:185:5
293     |
294 185 | /     for i in 10..5 + 4 {
295 186 | |         println!("{}", i);
296 187 | |     }
297     | |_____^
298     |
299 help: consider using the following if you are attempting to iterate over this range in reverse
300     |
301 185 |     for i in (5 + 4..10).rev() {
302     |              ^^^^^^^^^^^^^^^^^
303
304 error: this range is empty so this for loop will never run
305    --> $DIR/for_loop.rs:189:5
306     |
307 189 | /     for i in (5 + 2)..(3 - 1) {
308 190 | |         println!("{}", i);
309 191 | |     }
310     | |_____^
311     |
312 help: consider using the following if you are attempting to iterate over this range in reverse
313     |
314 189 |     for i in ((3 - 1)..(5 + 2)).rev() {
315     |              ^^^^^^^^^^^^^^^^^^^^^^^^
316
317 error: this range is empty so this for loop will never run
318    --> $DIR/for_loop.rs:193:5
319     |
320 193 | /     for i in (5 + 2)..(8 - 1) {
321 194 | |         println!("{}", i);
322 195 | |     }
323     | |_____^
324
325 error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
326    --> $DIR/for_loop.rs:215:15
327     |
328 215 |     for _v in vec.iter() {}
329     |               ^^^^^^^^^^ help: to write this more concisely, try: `&vec`
330     |
331     = note: `-D explicit-iter-loop` implied by `-D warnings`
332
333 error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
334    --> $DIR/for_loop.rs:217:15
335     |
336 217 |     for _v in vec.iter_mut() {}
337     |               ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut vec`
338
339 error: it is more idiomatic to loop over containers instead of using explicit iteration methods`
340    --> $DIR/for_loop.rs:220:15
341     |
342 220 |     for _v in out_vec.into_iter() {}
343     |               ^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `out_vec`
344     |
345     = note: `-D explicit-into-iter-loop` implied by `-D warnings`
346
347 error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
348    --> $DIR/for_loop.rs:223:15
349     |
350 223 |     for _v in array.into_iter() {}
351     |               ^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&array`
352
353 error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
354    --> $DIR/for_loop.rs:228:15
355     |
356 228 |     for _v in [1, 2, 3].iter() {}
357     |               ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[1, 2, 3]`
358
359 error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
360    --> $DIR/for_loop.rs:232:15
361     |
362 232 |     for _v in [0; 32].iter() {}
363     |               ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[0; 32]`
364
365 error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
366    --> $DIR/for_loop.rs:237:15
367     |
368 237 |     for _v in ll.iter() {}
369     |               ^^^^^^^^^ help: to write this more concisely, try: `&ll`
370
371 error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
372    --> $DIR/for_loop.rs:240:15
373     |
374 240 |     for _v in vd.iter() {}
375     |               ^^^^^^^^^ help: to write this more concisely, try: `&vd`
376
377 error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
378    --> $DIR/for_loop.rs:243:15
379     |
380 243 |     for _v in bh.iter() {}
381     |               ^^^^^^^^^ help: to write this more concisely, try: `&bh`
382
383 error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
384    --> $DIR/for_loop.rs:246:15
385     |
386 246 |     for _v in hm.iter() {}
387     |               ^^^^^^^^^ help: to write this more concisely, try: `&hm`
388
389 error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
390    --> $DIR/for_loop.rs:249:15
391     |
392 249 |     for _v in bt.iter() {}
393     |               ^^^^^^^^^ help: to write this more concisely, try: `&bt`
394
395 error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
396    --> $DIR/for_loop.rs:252:15
397     |
398 252 |     for _v in hs.iter() {}
399     |               ^^^^^^^^^ help: to write this more concisely, try: `&hs`
400
401 error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
402    --> $DIR/for_loop.rs:255:15
403     |
404 255 |     for _v in bs.iter() {}
405     |               ^^^^^^^^^ help: to write this more concisely, try: `&bs`
406
407 error: you are iterating over `Iterator::next()` which is an Option; this will compile but is probably not what you want
408    --> $DIR/for_loop.rs:257:5
409     |
410 257 |     for _v in vec.iter().next() {}
411     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
412
413 error: you are collect()ing an iterator and throwing away the result. Consider using an explicit for loop to exhaust the iterator
414    --> $DIR/for_loop.rs:264:5
415     |
416 264 |     vec.iter().cloned().map(|x| out.push(x)).collect::<Vec<_>>();
417     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
418     |
419     = note: `-D unused-collect` implied by `-D warnings`
420
421 error: the variable `_index` is used as a loop counter. Consider using `for (_index, item) in &vec.enumerate()` or similar iterators
422    --> $DIR/for_loop.rs:269:5
423     |
424 269 | /     for _v in &vec {
425 270 | |         _index += 1
426 271 | |     }
427     | |_____^
428     |
429     = note: `-D explicit-counter-loop` implied by `-D warnings`
430
431 error: the variable `_index` is used as a loop counter. Consider using `for (_index, item) in &vec.enumerate()` or similar iterators
432    --> $DIR/for_loop.rs:275:5
433     |
434 275 | /     for _v in &vec {
435 276 | |         _index += 1
436 277 | |     }
437     | |_____^
438
439 error: you seem to want to iterate on a map's values
440    --> $DIR/for_loop.rs:385:5
441     |
442 385 | /     for (_, v) in &m {
443 386 | |         let _v = v;
444 387 | |     }
445     | |_____^
446     |
447     = note: `-D for-kv-map` implied by `-D warnings`
448 help: use the corresponding method
449     |
450 385 |     for v in m.values() {
451     |         ^
452
453 error: you seem to want to iterate on a map's values
454    --> $DIR/for_loop.rs:390:5
455     |
456 390 | /     for (_, v) in &*m {
457 391 | |         let _v = v;
458 392 | |         // Here the `*` is not actually necesarry, but the test tests that we don't
459 393 | |         // suggest
460 394 | |         // `in *m.values()` as we used to
461 395 | |     }
462     | |_____^
463     |
464 help: use the corresponding method
465     |
466 390 |     for v in (*m).values() {
467     |         ^
468
469 error: you seem to want to iterate on a map's values
470    --> $DIR/for_loop.rs:398:5
471     |
472 398 | /     for (_, v) in &mut m {
473 399 | |         let _v = v;
474 400 | |     }
475     | |_____^
476     |
477 help: use the corresponding method
478     |
479 398 |     for v in m.values_mut() {
480     |         ^
481
482 error: you seem to want to iterate on a map's values
483    --> $DIR/for_loop.rs:403:5
484     |
485 403 | /     for (_, v) in &mut *m {
486 404 | |         let _v = v;
487 405 | |     }
488     | |_____^
489     |
490 help: use the corresponding method
491     |
492 403 |     for v in (*m).values_mut() {
493     |         ^
494
495 error: you seem to want to iterate on a map's keys
496    --> $DIR/for_loop.rs:409:5
497     |
498 409 | /     for (k, _value) in rm {
499 410 | |         let _k = k;
500 411 | |     }
501     | |_____^
502     |
503 help: use the corresponding method
504     |
505 409 |     for k in rm.keys() {
506     |         ^
507
508 error: it looks like you're manually copying between slices
509    --> $DIR/for_loop.rs:462:5
510     |
511 462 | /     for i in 0..src.len() {
512 463 | |         dst[i] = src[i];
513 464 | |     }
514     | |_____^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[..])`
515     |
516     = note: `-D manual-memcpy` implied by `-D warnings`
517
518 error: it looks like you're manually copying between slices
519    --> $DIR/for_loop.rs:467:5
520     |
521 467 | /     for i in 0..src.len() {
522 468 | |         dst[i + 10] = src[i];
523 469 | |     }
524     | |_____^ help: try replacing the loop by: `dst[10..(src.len() + 10)].clone_from_slice(&src[..])`
525
526 error: it looks like you're manually copying between slices
527    --> $DIR/for_loop.rs:472:5
528     |
529 472 | /     for i in 0..src.len() {
530 473 | |         dst[i] = src[i + 10];
531 474 | |     }
532     | |_____^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[10..])`
533
534 error: it looks like you're manually copying between slices
535    --> $DIR/for_loop.rs:477:5
536     |
537 477 | /     for i in 11..src.len() {
538 478 | |         dst[i] = src[i - 10];
539 479 | |     }
540     | |_____^ help: try replacing the loop by: `dst[11..src.len()].clone_from_slice(&src[(11 - 10)..(src.len() - 10)])`
541
542 error: it looks like you're manually copying between slices
543    --> $DIR/for_loop.rs:482:5
544     |
545 482 | /     for i in 0..dst.len() {
546 483 | |         dst[i] = src[i];
547 484 | |     }
548     | |_____^ help: try replacing the loop by: `dst.clone_from_slice(&src[..dst.len()])`
549
550 error: it looks like you're manually copying between slices
551    --> $DIR/for_loop.rs:495:5
552     |
553 495 | /     for i in 10..256 {
554 496 | |         dst[i] = src[i - 5];
555 497 | |         dst2[i + 500] = src[i]
556 498 | |     }
557     | |_____^
558     |
559 help: try replacing the loop by
560     |
561 495 |     dst[10..256].clone_from_slice(&src[(10 - 5)..(256 - 5)])
562 496 |     dst2[(10 + 500)..(256 + 500)].clone_from_slice(&src[10..256])
563     |
564
565 error: it looks like you're manually copying between slices
566    --> $DIR/for_loop.rs:507:5
567     |
568 507 | /     for i in 10..LOOP_OFFSET {
569 508 | |         dst[i + LOOP_OFFSET] = src[i - some_var];
570 509 | |     }
571     | |_____^ help: try replacing the loop by: `dst[(10 + LOOP_OFFSET)..(LOOP_OFFSET + LOOP_OFFSET)].clone_from_slice(&src[(10 - some_var)..(LOOP_OFFSET - some_var)])`
572
573 error: it looks like you're manually copying between slices
574    --> $DIR/for_loop.rs:520:5
575     |
576 520 | /     for i in 0..src_vec.len() {
577 521 | |         dst_vec[i] = src_vec[i];
578 522 | |     }
579     | |_____^ help: try replacing the loop by: `dst_vec[..src_vec.len()].clone_from_slice(&src_vec[..])`
580
581 error: it looks like you're manually copying between slices
582    --> $DIR/for_loop.rs:547:5
583     |
584 547 | /     for i in 0..src.len() {
585 548 | |         dst[i] = src[i].clone();
586 549 | |     }
587     | |_____^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[..])`
588