|
7 | 7 | // option. This file may not be copied, modified, or distributed |
8 | 8 | // except according to those terms. |
9 | 9 |
|
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | 10 | use std::collections::*; |
15 | 11 | use std::rc::Rc; |
16 | 12 |
|
17 | 13 | static STATIC: [usize; 4] = [0, 1, 8, 16]; |
18 | 14 | const CONST: [usize; 4] = [0, 1, 8, 16]; |
19 | 15 |
|
20 | 16 | #[warn(clippy::all)] |
21 | | -fn for_loop_over_option_and_result() { |
22 | | - let option = Some(1); |
23 | | - let result = option.ok_or("x not found"); |
24 | | - let v = vec![0, 1, 2]; |
25 | | - |
26 | | - // check FOR_LOOP_OVER_OPTION lint |
27 | | - for x in option { |
28 | | - println!("{}", x); |
29 | | - } |
30 | | - |
31 | | - // check FOR_LOOP_OVER_RESULT lint |
32 | | - for x in result { |
33 | | - println!("{}", x); |
34 | | - } |
35 | | - |
36 | | - for x in option.ok_or("x not found") { |
37 | | - println!("{}", x); |
38 | | - } |
39 | | - |
40 | | - // make sure LOOP_OVER_NEXT lint takes clippy::precedence when next() is the last call |
41 | | - // in the chain |
42 | | - for x in v.iter().next() { |
43 | | - println!("{}", x); |
44 | | - } |
45 | | - |
46 | | - // make sure we lint when next() is not the last call in the chain |
47 | | - for x in v.iter().next().and(Some(0)) { |
48 | | - println!("{}", x); |
49 | | - } |
50 | | - |
51 | | - for x in v.iter().next().ok_or("x not found") { |
52 | | - println!("{}", x); |
53 | | - } |
54 | | - |
55 | | - // check for false positives |
56 | | - |
57 | | - // for loop false positive |
58 | | - for x in v { |
59 | | - println!("{}", x); |
60 | | - } |
61 | | - |
62 | | - // while let false positive for Option |
63 | | - while let Some(x) = option { |
64 | | - println!("{}", x); |
65 | | - break; |
66 | | - } |
67 | | - |
68 | | - // while let false positive for Result |
69 | | - while let Ok(x) = result { |
70 | | - println!("{}", x); |
71 | | - break; |
72 | | - } |
73 | | -} |
74 | | - |
75 | 17 | struct Unrelated(Vec<u8>); |
76 | 18 | impl Unrelated { |
77 | 19 | fn next(&self) -> std::slice::Iter<u8> { |
@@ -379,8 +321,6 @@ fn main() { |
379 | 321 | } |
380 | 322 | println!("index: {}", index); |
381 | 323 |
|
382 | | - for_loop_over_option_and_result(); |
383 | | - |
384 | 324 | let m: HashMap<u64, u64> = HashMap::new(); |
385 | 325 | for (_, v) in &m { |
386 | 326 | let _v = v; |
|
0 commit comments