]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/single_element_loop.rs
Merge commit '7f27e2e74ef957baa382dc05cf08df6368165c74' into clippyup
[rust.git] / src / tools / clippy / tests / ui / single_element_loop.rs
1 // run-rustfix
2 // Tests from for_loop.rs that don't have suggestions
3
4 #[warn(clippy::single_element_loop)]
5 fn main() {
6     let item1 = 2;
7     for item in &[item1] {
8         dbg!(item);
9     }
10
11     for item in [item1].iter() {
12         dbg!(item);
13     }
14
15     for item in &[0..5] {
16         dbg!(item);
17     }
18
19     for item in [0..5].iter_mut() {
20         dbg!(item);
21     }
22
23     for item in [0..5] {
24         dbg!(item);
25     }
26
27     for item in [0..5].into_iter() {
28         dbg!(item);
29     }
30
31     // should not lint (issue #10018)
32     for e in [42] {
33         if e > 0 {
34             continue;
35         }
36     }
37
38     // should not lint (issue #10018)
39     for e in [42] {
40         if e > 0 {
41             break;
42         }
43     }
44
45     // should lint (issue #10018)
46     for _ in [42] {
47         let _f = |n: u32| {
48             for i in 0..n {
49                 if i > 10 {
50                     dbg!(i);
51                     break;
52                 }
53             }
54         };
55     }
56 }