1 #![allow(trivially_copy_pass_by_ref)]
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");
62 println!("OK - tup.0 gets mutated")
67 // Should warn when a (mutable) var is not used in while body
68 let (mut i, mut j) = (0, 0);
72 println!("KO - i not mentionned");
75 while i < 3 && j > 0 {
76 println!("KO - i and j not mentionned");
82 println!("KO - shadowed");
85 while i < 3 && j > 0 {
87 println!("OK - i in cond and mentionned");
96 println!("KO - const reference");
101 println!("KO - passed by value");
105 println!("OK - passed by mutable reference");
111 println!("OK - passed by mutable reference");
116 const B: bool = false;
120 println!("Constants are not linted");
124 println!("Constants are not linted");
128 println!("Constants are not linted");
134 fn maybe_i_mutate(i: &Cell<bool>) { unimplemented!() }
136 fn internally_mutable() {
137 let b = Cell::new(true);
139 while b.get() { // b cannot be silently coerced to `bool`
141 println!("OK - Method call within condition");
154 fn inc_n(&mut self, n: usize) {
155 while self.count < n {
158 println!("OK - self borrowed mutably");
161 fn print_n(&self, n: usize) {
162 while self.count < n {
163 println!("KO - {} is not mutated", self.count);
169 immutable_condition();
172 internally_mutable();
174 let mut c = Counter { count: 0 };