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