1 #![feature(tool_lints)]
3 #![allow(clippy::trivially_copy_pass_by_ref)]
6 fn fn_val(i: i32) -> i32 { unimplemented!() }
7 fn fn_constref(i: &i32) -> i32 { unimplemented!() }
8 fn fn_mutref(i: &mut i32) { unimplemented!() }
9 fn fooi() -> i32 { unimplemented!() }
10 fn foob() -> bool { unimplemented!() }
12 #[allow(clippy::many_single_char_names)]
13 fn immutable_condition() {
14 // Should warn when all vars mentioned are immutable
17 println!("KO - y is immutable");
21 while y < 10 && x < 3 {
24 println!("KO - x and y immutable");
29 println!("KO - cond immutable");
33 while y < 10 && i < 3 {
35 println!("OK - i is mutable");
38 let mut mut_cond = false;
39 while !mut_cond || cond {
41 println!("OK - mut_cond is mutable");
45 println!("OK - Fn call results may vary");
49 println!("OK - Fn call results may vary");
56 println!("OK - a is mutable");
64 println!("OK - tup.0 gets mutated")
69 // Should warn when a (mutable) var is not used in while body
70 let (mut i, mut j) = (0, 0);
74 println!("KO - i not mentioned");
77 while i < 3 && j > 0 {
78 println!("KO - i and j not mentioned");
84 println!("KO - shadowed");
87 while i < 3 && j > 0 {
89 println!("OK - i in cond and mentioned");
98 println!("KO - const reference");
103 println!("KO - passed by value");
107 println!("OK - passed by mutable reference");
113 println!("OK - passed by mutable reference");
118 const B: bool = false;
122 println!("Constants are not linted");
126 println!("Constants are not linted");
130 println!("Constants are not linted");
136 fn maybe_i_mutate(i: &Cell<bool>) { unimplemented!() }
138 fn internally_mutable() {
139 let b = Cell::new(true);
141 while b.get() { // b cannot be silently coerced to `bool`
143 println!("OK - Method call within condition");
156 fn inc_n(&mut self, n: usize) {
157 while self.count < n {
160 println!("OK - self borrowed mutably");
163 fn print_n(&self, n: usize) {
164 while self.count < n {
165 println!("KO - {} is not mutated", self.count);
171 immutable_condition();
174 internally_mutable();
176 let mut c = Counter { count: 0 };