4 fn fn_val(i: i32) -> i32 { unimplemented!() }
5 fn fn_constref(i: &i32) -> i32 { unimplemented!() }
6 fn fn_mutref(i: &mut i32) { unimplemented!() }
7 fn fooi() -> i32 { unimplemented!() }
8 fn foob() -> bool { unimplemented!() }
10 #[allow(many_single_char_names)]
11 fn immutable_condition() {
12 // Should warn when all vars mentionned are immutable
15 println!("KO - y is immutable");
19 while y < 10 && x < 3 {
22 println!("KO - x and y immutable");
27 println!("KO - cond immutable");
31 while y < 10 && i < 3 {
33 println!("OK - i is mutable");
36 let mut mut_cond = false;
37 while !mut_cond || cond {
39 println!("OK - mut_cond is mutable");
43 println!("OK - Fn call results may vary");
47 println!("OK - Fn call results may vary");
54 println!("OK - a is mutable");
61 // Should warn when a (mutable) var is not used in while body
62 let (mut i, mut j) = (0, 0);
66 println!("KO - i not mentionned");
69 while i < 3 && j > 0 {
70 println!("KO - i and j not mentionned");
76 println!("KO - shadowed");
79 while i < 3 && j > 0 {
81 println!("OK - i in cond and mentionned");
90 println!("KO - const reference");
95 println!("KO - passed by value");
99 println!("OK - passed by mutable reference");
105 println!("OK - passed by mutable reference");
110 const B: bool = false;
114 println!("Constants are not linted");
118 println!("Constants are not linted");
122 println!("Constants are not linted");
128 fn maybe_i_mutate(i: &Cell<bool>) { unimplemented!() }
130 fn internally_mutable() {
131 let b = Cell::new(true);
133 while b.get() { // b cannot be silently coerced to `bool`
135 println!("OK - Method call within condition");
148 fn inc_n(&mut self, n: usize) {
149 while self.count < n {
152 println!("OK - self borrowed mutably");
155 fn print_n(&self, n: usize) {
156 while self.count < n {
157 println!("KO - {} is not mutated", self.count);
163 immutable_condition();
166 internally_mutable();
168 let mut c = Counter { count: 0 };