fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1// run-rustfix 2#![allow(unused)] 3struct S; 4 5impl S { 6 fn call(&mut self, f: impl FnOnce((), &mut Self)) { 7 // change state or something ... 8 f((), self); 9 // change state or something ... 10 } 11 12 fn get(&self) {} 13 fn set(&mut self) {} 14} 15 16fn main() { 17 let mut v = S; 18 19 v.call(|(), this: &mut S| this.get()); 20 //~^ error: cannot borrow `v` as mutable because it is also borrowed as immutable 21 v.call(|(), this: &mut S| this.set()); 22 //~^ error: cannot borrow `v` as mutable more than once at a time 23 //~| error: cannot borrow `v` as mutable more than once at a time 24 25 v.call(|(), this: &mut S| { 26 //~^ error: cannot borrow `v` as mutable more than once at a time 27 //~| error: cannot borrow `v` as mutable more than once at a time 28 29 _ = this; 30 this.set(); 31 this.get(); 32 S::get(&this); 33 34 use std::ops::Add; 35 let v = 0u32; 36 _ = v + v; 37 _ = v.add(3); 38 }); 39}