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