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