1 fn fn_val(i: i32) -> i32 {
4 fn fn_constref(i: &i32) -> i32 {
7 fn fn_mutref(i: &mut i32) {
17 fn immutable_condition() {
18 // Should warn when all vars mentioned are immutable
21 println!("KO - y is immutable");
25 while y < 10 && x < 3 {
28 println!("KO - x and y immutable");
33 println!("KO - cond immutable");
37 while y < 10 && i < 3 {
39 println!("OK - i is mutable");
42 let mut mut_cond = false;
43 while !mut_cond || cond {
45 println!("OK - mut_cond is mutable");
49 println!("OK - Fn call results may vary");
53 println!("OK - Fn call results may vary");
60 println!("OK - a is mutable");
68 println!("OK - tup.0 gets mutated")
73 // Should warn when a (mutable) var is not used in while body
74 let (mut i, mut j) = (0, 0);
78 println!("KO - i not mentioned");
81 while i < 3 && j > 0 {
82 println!("KO - i and j not mentioned");
88 println!("KO - shadowed");
91 while i < 3 && j > 0 {
93 println!("OK - i in cond and mentioned");
102 println!("KO - const reference");
107 println!("KO - passed by value");
111 println!("OK - passed by mutable reference");
117 println!("OK - passed by mutable reference");
122 const B: bool = false;
126 println!("Constants are not linted");
130 println!("Constants are not linted");
134 println!("Constants are not linted");
140 fn maybe_i_mutate(i: &Cell<bool>) {
144 fn internally_mutable() {
145 let b = Cell::new(true);
148 // b cannot be silently coerced to `bool`
150 println!("OK - Method call within condition");
163 fn inc_n(&mut self, n: usize) {
164 while self.count < n {
167 println!("OK - self borrowed mutably");
170 fn print_n(&self, n: usize) {
171 while self.count < n {
172 println!("KO - {} is not mutated", self.count);
177 fn while_loop_with_break_and_return() {
183 println!("KO - loop contains break");
190 println!("KO - loop contains return");
194 fn immutable_condition_false_positive(mut n: u64) -> u32 {
206 immutable_condition();
209 internally_mutable();
210 immutable_condition_false_positive(5);
212 let mut c = Counter { count: 0 };
216 while_loop_with_break_and_return();