]> git.lizzy.rs Git - rust.git/blob - tests/ui/needless_continue.rs
544b7e66a270a73e71adfc15505e6ff11925b0a3
[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     loop {
53         continue;
54     }
55 }
56
57 mod issue_2329 {
58     fn condition() -> bool {
59         unimplemented!()
60     }
61     fn update_condition() {}
62
63     // only the outer loop has a label
64     fn foo() {
65         'outer: loop {
66             println!("Entry");
67             while condition() {
68                 update_condition();
69                 if condition() {
70                     println!("foo-1");
71                 } else {
72                     continue 'outer; // should not lint here
73                 }
74                 println!("foo-2");
75
76                 update_condition();
77                 if condition() {
78                     continue 'outer; // should not lint here
79                 } else {
80                     println!("foo-3");
81                 }
82                 println!("foo-4");
83             }
84         }
85     }
86
87     // both loops have labels
88     fn bar() {
89         'outer: loop {
90             println!("Entry");
91             'inner: while condition() {
92                 update_condition();
93                 if condition() {
94                     println!("bar-1");
95                 } else {
96                     continue 'outer; // should not lint here
97                 }
98                 println!("bar-2");
99
100                 update_condition();
101                 if condition() {
102                     println!("bar-3");
103                 } else {
104                     continue 'inner; // should lint here
105                 }
106                 println!("bar-4");
107
108                 update_condition();
109                 if condition() {
110                     continue; // should lint here
111                 } else {
112                     println!("bar-5");
113                 }
114                 println!("bar-6");
115             }
116         }
117     }
118 }