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