fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1// run-rustfix 2struct Test { 3 a: u32 4} 5 6impl Test { 7 pub fn add(&mut self, value: u32) { 8 self.a += value; 9 } 10 11 pub fn print_value(&self) { 12 println!("Value of a is: {}", self.a); 13 } 14} 15 16fn main() { 17 let mut tests = Vec::new(); 18 for i in 0..=10 { 19 tests.push(Test {a: i}); 20 } 21 for test in &mut tests { 22 test.add(2); //~ ERROR cannot borrow `*test` as mutable, as it is behind a `&` reference 23 } 24 for test in &mut tests { 25 test.add(2); 26 } 27 for test in &tests { 28 test.print_value(); 29 } 30}