Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
clippy 0.0.201 - Docs.rs
[go: Go Back, main page]

clippy 0.0.201

A bunch of helpful lints to avoid common pitfalls in Rust
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
error: for loop over `option`, which is an `Option`. This is more readably written as an `if let` statement.
  --> $DIR/for_loop.rs:17:14
   |
17 |     for x in option {
   |              ^^^^^^
   |
   = note: `-D for-loop-over-option` implied by `-D warnings`
   = help: consider replacing `for x in option` with `if let Some(x) = option`

error: for loop over `result`, which is a `Result`. This is more readably written as an `if let` statement.
  --> $DIR/for_loop.rs:22:14
   |
22 |     for x in result {
   |              ^^^^^^
   |
   = note: `-D for-loop-over-result` implied by `-D warnings`
   = help: consider replacing `for x in result` with `if let Ok(x) = result`

error: for loop over `option.ok_or("x not found")`, which is a `Result`. This is more readably written as an `if let` statement.
  --> $DIR/for_loop.rs:26:14
   |
26 |     for x in option.ok_or("x not found") {
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: consider replacing `for x in option.ok_or("x not found")` with `if let Ok(x) = option.ok_or("x not found")`

error: you are iterating over `Iterator::next()` which is an Option; this will compile but is probably not what you want
  --> $DIR/for_loop.rs:32:14
   |
32 |     for x in v.iter().next() {
   |              ^^^^^^^^^^^^^^^
   |
   = note: `-D iter-next-loop` implied by `-D warnings`

error: for loop over `v.iter().next().and(Some(0))`, which is an `Option`. This is more readably written as an `if let` statement.
  --> $DIR/for_loop.rs:37:14
   |
37 |     for x in v.iter().next().and(Some(0)) {
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: consider replacing `for x in v.iter().next().and(Some(0))` with `if let Some(x) = v.iter().next().and(Some(0))`

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.
  --> $DIR/for_loop.rs:41:14
   |
41 |     for x in v.iter().next().ok_or("x not found") {
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = 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")`

error: this loop never actually loops
  --> $DIR/for_loop.rs:53:5
   |
53 | /     while let Some(x) = option {
54 | |         println!("{}", x);
55 | |         break;
56 | |     }
   | |_____^
   |
   = note: `-D never-loop` implied by `-D warnings`

error: this loop never actually loops
  --> $DIR/for_loop.rs:59:5
   |
59 | /     while let Ok(x) = result {
60 | |         println!("{}", x);
61 | |         break;
62 | |     }
   | |_____^

error: the loop variable `i` is only used to index `vec`.
  --> $DIR/for_loop.rs:86:14
   |
86 |     for i in 0..vec.len() {
   |              ^^^^^^^^^^^^
   |
   = note: `-D needless-range-loop` implied by `-D warnings`
help: consider using an iterator
   |
86 |     for <item> in &vec {
   |

error: the loop variable `i` is only used to index `vec`.
  --> $DIR/for_loop.rs:95:14
   |
95 |     for i in 0..vec.len() {
   |              ^^^^^^^^^^^^
help: consider using an iterator
   |
95 |     for <item> in &vec {
   |

error: the loop variable `j` is only used to index `STATIC`.
   --> $DIR/for_loop.rs:100:14
    |
100 |     for j in 0..4 {
    |              ^^^^
help: consider using an iterator
    |
100 |     for <item> in STATIC.iter().take(4) {
    |

error: the loop variable `j` is only used to index `CONST`.
   --> $DIR/for_loop.rs:104:14
    |
104 |     for j in 0..4 {
    |              ^^^^
help: consider using an iterator
    |
104 |     for <item> in CONST.iter().take(4) {
    |

error: the loop variable `i` is used to index `vec`
   --> $DIR/for_loop.rs:108:14
    |
108 |     for i in 0..vec.len() {
    |              ^^^^^^^^^^^^
help: consider using an iterator
    |
108 |     for (i, <item>) in vec.iter().enumerate() {
    |

error: the loop variable `i` is only used to index `vec2`.
   --> $DIR/for_loop.rs:116:14
    |
116 |     for i in 0..vec.len() {
    |              ^^^^^^^^^^^^
help: consider using an iterator
    |
116 |     for <item> in vec2.iter().take(vec.len()) {
    |

error: the loop variable `i` is only used to index `vec`.
   --> $DIR/for_loop.rs:120:14
    |
120 |     for i in 5..vec.len() {
    |              ^^^^^^^^^^^^
help: consider using an iterator
    |
120 |     for <item> in vec.iter().skip(5) {
    |

error: the loop variable `i` is only used to index `vec`.
   --> $DIR/for_loop.rs:124:14
    |
124 |     for i in 0..MAX_LEN {
    |              ^^^^^^^^^^
help: consider using an iterator
    |
124 |     for <item> in vec.iter().take(MAX_LEN) {
    |

error: the loop variable `i` is only used to index `vec`.
   --> $DIR/for_loop.rs:128:14
    |
128 |     for i in 0..=MAX_LEN {
    |              ^^^^^^^^^^^
help: consider using an iterator
    |
128 |     for <item> in vec.iter().take(MAX_LEN + 1) {
    |

error: the loop variable `i` is only used to index `vec`.
   --> $DIR/for_loop.rs:132:14
    |
132 |     for i in 5..10 {
    |              ^^^^^
help: consider using an iterator
    |
132 |     for <item> in vec.iter().take(10).skip(5) {
    |

error: the loop variable `i` is only used to index `vec`.
   --> $DIR/for_loop.rs:136:14
    |
136 |     for i in 5..=10 {
    |              ^^^^^^
help: consider using an iterator
    |
136 |     for <item> in vec.iter().take(10 + 1).skip(5) {
    |

error: the loop variable `i` is used to index `vec`
   --> $DIR/for_loop.rs:140:14
    |
140 |     for i in 5..vec.len() {
    |              ^^^^^^^^^^^^
help: consider using an iterator
    |
140 |     for (i, <item>) in vec.iter().enumerate().skip(5) {
    |

error: the loop variable `i` is used to index `vec`
   --> $DIR/for_loop.rs:144:14
    |
144 |     for i in 5..10 {
    |              ^^^^^
help: consider using an iterator
    |
144 |     for (i, <item>) in vec.iter().enumerate().take(10).skip(5) {
    |

error: this range is empty so this for loop will never run
   --> $DIR/for_loop.rs:148:14
    |
148 |     for i in 10..0 {
    |              ^^^^^
    |
    = note: `-D reverse-range-loop` implied by `-D warnings`
help: consider using the following if you are attempting to iterate over this range in reverse
    |
148 |     for i in (0..10).rev() {
    |              ^^^^^^^^^^^^^

error: this range is empty so this for loop will never run
   --> $DIR/for_loop.rs:152:14
    |
152 |     for i in 10..=0 {
    |              ^^^^^^
help: consider using the following if you are attempting to iterate over this range in reverse
    |
152 |     for i in (0...10).rev() {
    |              ^^^^^^^^^^^^^^

error: this range is empty so this for loop will never run
   --> $DIR/for_loop.rs:156:14
    |
156 |     for i in MAX_LEN..0 {
    |              ^^^^^^^^^^
help: consider using the following if you are attempting to iterate over this range in reverse
    |
156 |     for i in (0..MAX_LEN).rev() {
    |              ^^^^^^^^^^^^^^^^^^

error: this range is empty so this for loop will never run
   --> $DIR/for_loop.rs:160:14
    |
160 |     for i in 5..5 {
    |              ^^^^

error: this range is empty so this for loop will never run
   --> $DIR/for_loop.rs:185:14
    |
185 |     for i in 10..5 + 4 {
    |              ^^^^^^^^^
help: consider using the following if you are attempting to iterate over this range in reverse
    |
185 |     for i in (5 + 4..10).rev() {
    |              ^^^^^^^^^^^^^^^^^

error: this range is empty so this for loop will never run
   --> $DIR/for_loop.rs:189:14
    |
189 |     for i in (5 + 2)..(3 - 1) {
    |              ^^^^^^^^^^^^^^^^
help: consider using the following if you are attempting to iterate over this range in reverse
    |
189 |     for i in ((3 - 1)..(5 + 2)).rev() {
    |              ^^^^^^^^^^^^^^^^^^^^^^^^

error: this range is empty so this for loop will never run
   --> $DIR/for_loop.rs:193:14
    |
193 |     for i in (5 + 2)..(8 - 1) {
    |              ^^^^^^^^^^^^^^^^

error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
   --> $DIR/for_loop.rs:215:15
    |
215 |     for _v in vec.iter() {}
    |               ^^^^^^^^^^ help: to write this more concisely, try: `&vec`
    |
    = note: `-D explicit-iter-loop` implied by `-D warnings`

error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
   --> $DIR/for_loop.rs:217:15
    |
217 |     for _v in vec.iter_mut() {}
    |               ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut vec`

error: it is more idiomatic to loop over containers instead of using explicit iteration methods`
   --> $DIR/for_loop.rs:220:15
    |
220 |     for _v in out_vec.into_iter() {}
    |               ^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `out_vec`
    |
    = note: `-D explicit-into-iter-loop` implied by `-D warnings`

error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
   --> $DIR/for_loop.rs:223:15
    |
223 |     for _v in array.into_iter() {}
    |               ^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&array`

error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
   --> $DIR/for_loop.rs:228:15
    |
228 |     for _v in [1, 2, 3].iter() {}
    |               ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[1, 2, 3]`

error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
   --> $DIR/for_loop.rs:232:15
    |
232 |     for _v in [0; 32].iter() {}
    |               ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[0; 32]`

error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
   --> $DIR/for_loop.rs:237:15
    |
237 |     for _v in ll.iter() {}
    |               ^^^^^^^^^ help: to write this more concisely, try: `&ll`

error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
   --> $DIR/for_loop.rs:240:15
    |
240 |     for _v in vd.iter() {}
    |               ^^^^^^^^^ help: to write this more concisely, try: `&vd`

error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
   --> $DIR/for_loop.rs:243:15
    |
243 |     for _v in bh.iter() {}
    |               ^^^^^^^^^ help: to write this more concisely, try: `&bh`

error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
   --> $DIR/for_loop.rs:246:15
    |
246 |     for _v in hm.iter() {}
    |               ^^^^^^^^^ help: to write this more concisely, try: `&hm`

error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
   --> $DIR/for_loop.rs:249:15
    |
249 |     for _v in bt.iter() {}
    |               ^^^^^^^^^ help: to write this more concisely, try: `&bt`

error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
   --> $DIR/for_loop.rs:252:15
    |
252 |     for _v in hs.iter() {}
    |               ^^^^^^^^^ help: to write this more concisely, try: `&hs`

error: it is more idiomatic to loop over references to containers instead of using explicit iteration methods
   --> $DIR/for_loop.rs:255:15
    |
255 |     for _v in bs.iter() {}
    |               ^^^^^^^^^ help: to write this more concisely, try: `&bs`

error: you are iterating over `Iterator::next()` which is an Option; this will compile but is probably not what you want
   --> $DIR/for_loop.rs:257:15
    |
257 |     for _v in vec.iter().next() {}
    |               ^^^^^^^^^^^^^^^^^

error: you are collect()ing an iterator and throwing away the result. Consider using an explicit for loop to exhaust the iterator
   --> $DIR/for_loop.rs:264:5
    |
264 |     vec.iter().cloned().map(|x| out.push(x)).collect::<Vec<_>>();
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `-D unused-collect` implied by `-D warnings`

error: the variable `_index` is used as a loop counter. Consider using `for (_index, item) in &vec.enumerate()` or similar iterators
   --> $DIR/for_loop.rs:269:15
    |
269 |     for _v in &vec {
    |               ^^^^
    |
    = note: `-D explicit-counter-loop` implied by `-D warnings`

error: the variable `_index` is used as a loop counter. Consider using `for (_index, item) in &vec.enumerate()` or similar iterators
   --> $DIR/for_loop.rs:275:15
    |
275 |     for _v in &vec {
    |               ^^^^

error: you seem to want to iterate on a map's values
   --> $DIR/for_loop.rs:385:19
    |
385 |     for (_, v) in &m {
    |                   ^^
    |
    = note: `-D for-kv-map` implied by `-D warnings`
help: use the corresponding method
    |
385 |     for v in m.values() {
    |

error: you seem to want to iterate on a map's values
   --> $DIR/for_loop.rs:390:19
    |
390 |     for (_, v) in &*m {
    |                   ^^^
help: use the corresponding method
    |
390 |     for v in (*m).values() {
    |

error: you seem to want to iterate on a map's values
   --> $DIR/for_loop.rs:398:19
    |
398 |     for (_, v) in &mut m {
    |                   ^^^^^^
help: use the corresponding method
    |
398 |     for v in m.values_mut() {
    |

error: you seem to want to iterate on a map's values
   --> $DIR/for_loop.rs:403:19
    |
403 |     for (_, v) in &mut *m {
    |                   ^^^^^^^
help: use the corresponding method
    |
403 |     for v in (*m).values_mut() {
    |

error: you seem to want to iterate on a map's keys
   --> $DIR/for_loop.rs:409:24
    |
409 |     for (k, _value) in rm {
    |                        ^^
help: use the corresponding method
    |
409 |     for k in rm.keys() {
    |

error: it looks like you're manually copying between slices
   --> $DIR/for_loop.rs:462:14
    |
462 |     for i in 0..src.len() {
    |              ^^^^^^^^^^^^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[..])`
    |
    = note: `-D manual-memcpy` implied by `-D warnings`

error: it looks like you're manually copying between slices
   --> $DIR/for_loop.rs:467:14
    |
467 |     for i in 0..src.len() {
    |              ^^^^^^^^^^^^ help: try replacing the loop by: `dst[10..(src.len() + 10)].clone_from_slice(&src[..])`

error: it looks like you're manually copying between slices
   --> $DIR/for_loop.rs:472:14
    |
472 |     for i in 0..src.len() {
    |              ^^^^^^^^^^^^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[10..])`

error: it looks like you're manually copying between slices
   --> $DIR/for_loop.rs:477:14
    |
477 |     for i in 11..src.len() {
    |              ^^^^^^^^^^^^^ help: try replacing the loop by: `dst[11..src.len()].clone_from_slice(&src[(11 - 10)..(src.len() - 10)])`

error: it looks like you're manually copying between slices
   --> $DIR/for_loop.rs:482:14
    |
482 |     for i in 0..dst.len() {
    |              ^^^^^^^^^^^^ help: try replacing the loop by: `dst.clone_from_slice(&src[..dst.len()])`

error: it looks like you're manually copying between slices
   --> $DIR/for_loop.rs:495:14
    |
495 |     for i in 10..256 {
    |              ^^^^^^^
help: try replacing the loop by
    |
495 |     for i in dst[10..256].clone_from_slice(&src[(10 - 5)..(256 - 5)])
496 |     dst2[(10 + 500)..(256 + 500)].clone_from_slice(&src[10..256]) {
    |

error: it looks like you're manually copying between slices
   --> $DIR/for_loop.rs:507:14
    |
507 |     for i in 10..LOOP_OFFSET {
    |              ^^^^^^^^^^^^^^^ 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)])`

error: it looks like you're manually copying between slices
   --> $DIR/for_loop.rs:520:14
    |
520 |     for i in 0..src_vec.len() {
    |              ^^^^^^^^^^^^^^^^ help: try replacing the loop by: `dst_vec[..src_vec.len()].clone_from_slice(&src_vec[..])`

error: it looks like you're manually copying between slices
   --> $DIR/for_loop.rs:547:14
    |
547 |     for i in 0..src.len() {
    |              ^^^^^^^^^^^^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[..])`

error: aborting due to 59 previous errors