]> git.lizzy.rs Git - rust.git/blob - tests/ui/needless_continue.rs
Don't lint `if_same_then_else` with `if let` conditions
[rust.git] / tests / ui / needless_continue.rs
1 #![warn(clippy::needless_continue)]
2
3 macro_rules! zero {
4     ($x:expr) => {
5         $x == 0
6     };
7 }
8
9 macro_rules! nonzero {
10     ($x:expr) => {
11         !zero!($x)
12     };
13 }
14
15 #[allow(clippy::nonminimal_bool)]
16 fn main() {
17     let mut i = 1;
18     while i < 10 {
19         i += 1;
20
21         if i % 2 == 0 && i % 3 == 0 {
22             println!("{}", i);
23             println!("{}", i + 1);
24             if i % 5 == 0 {
25                 println!("{}", i + 2);
26             }
27             let i = 0;
28             println!("bar {} ", i);
29         } else {
30             continue;
31         }
32
33         println!("bleh");
34         {
35             println!("blah");
36         }
37
38         // some comments that also should ideally be included in the
39         // output of the lint suggestion if possible.
40         if !(!(i == 2) || !(i == 5)) {
41             println!("lama");
42         }
43
44         if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 {
45             continue;
46         } else {
47             println!("Blabber");
48             println!("Jabber");
49         }
50
51         println!("bleh");
52     }
53 }
54
55 fn simple_loop() {
56     loop {
57         continue; // should lint here
58     }
59 }
60
61 fn simple_loop2() {
62     loop {
63         println!("bleh");
64         continue; // should lint here
65     }
66 }
67
68 #[rustfmt::skip]
69 fn simple_loop3() {
70     loop {
71         continue // should lint here
72     }
73 }
74
75 #[rustfmt::skip]
76 fn simple_loop4() {
77     loop {
78         println!("bleh");
79         continue // should lint here
80     }
81 }
82
83 mod issue_2329 {
84     fn condition() -> bool {
85         unimplemented!()
86     }
87     fn update_condition() {}
88
89     // only the outer loop has a label
90     fn foo() {
91         'outer: loop {
92             println!("Entry");
93             while condition() {
94                 update_condition();
95                 if condition() {
96                     println!("foo-1");
97                 } else {
98                     continue 'outer; // should not lint here
99                 }
100                 println!("foo-2");
101
102                 update_condition();
103                 if condition() {
104                     continue 'outer; // should not lint here
105                 } else {
106                     println!("foo-3");
107                 }
108                 println!("foo-4");
109             }
110         }
111     }
112
113     // both loops have labels
114     fn bar() {
115         'outer: loop {
116             println!("Entry");
117             'inner: while condition() {
118                 update_condition();
119                 if condition() {
120                     println!("bar-1");
121                 } else {
122                     continue 'outer; // should not lint here
123                 }
124                 println!("bar-2");
125
126                 update_condition();
127                 if condition() {
128                     println!("bar-3");
129                 } else {
130                     continue 'inner; // should lint here
131                 }
132                 println!("bar-4");
133
134                 update_condition();
135                 if condition() {
136                     continue; // should lint here
137                 } else {
138                     println!("bar-5");
139                 }
140                 println!("bar-6");
141             }
142         }
143     }
144 }