1 fn fn_val(i: i32) -> i32 {
4 fn fn_constref(i: &i32) -> i32 {
7 fn fn_mutref(i: &mut i32) {
17 #[allow(clippy::many_single_char_names)]
18 fn immutable_condition() {
19 // Should warn when all vars mentioned are immutable
22 println!("KO - y is immutable");
26 while y < 10 && x < 3 {
29 println!("KO - x and y immutable");
34 println!("KO - cond immutable");
38 while y < 10 && i < 3 {
40 println!("OK - i is mutable");
43 let mut mut_cond = false;
44 while !mut_cond || cond {
46 println!("OK - mut_cond is mutable");
50 println!("OK - Fn call results may vary");
54 println!("OK - Fn call results may vary");
61 println!("OK - a is mutable");
69 println!("OK - tup.0 gets mutated")
74 // Should warn when a (mutable) var is not used in while body
75 let (mut i, mut j) = (0, 0);
79 println!("KO - i not mentioned");
82 while i < 3 && j > 0 {
83 println!("KO - i and j not mentioned");
89 println!("KO - shadowed");
92 while i < 3 && j > 0 {
94 println!("OK - i in cond and mentioned");
103 println!("KO - const reference");
108 println!("KO - passed by value");
112 println!("OK - passed by mutable reference");
118 println!("OK - passed by mutable reference");
123 const B: bool = false;
127 println!("Constants are not linted");
131 println!("Constants are not linted");
135 println!("Constants are not linted");
141 fn maybe_i_mutate(i: &Cell<bool>) {
145 fn internally_mutable() {
146 let b = Cell::new(true);
149 // b cannot be silently coerced to `bool`
151 println!("OK - Method call within condition");
164 fn inc_n(&mut self, n: usize) {
165 while self.count < n {
168 println!("OK - self borrowed mutably");
171 fn print_n(&self, n: usize) {
172 while self.count < n {
173 println!("KO - {} is not mutated", self.count);
178 fn while_loop_with_break_and_return() {
184 println!("KO - loop contains break");
191 println!("KO - loop contains return");
195 fn immutable_condition_false_positive(mut n: u64) -> u32 {
207 immutable_condition();
210 internally_mutable();
211 immutable_condition_false_positive(5);
213 let mut c = Counter { count: 0 };
217 while_loop_with_break_and_return();