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