rust/src/test/ui/borrowck/mut-borrow-in-loop.rs
2018-12-25 21:08:33 -07:00

31 lines
613 B
Rust

// produce special borrowck message inside all kinds of loops
struct FuncWrapper<'a, T : 'a> {
func : fn(&'a mut T) -> ()
}
impl<'a, T : 'a> FuncWrapper<'a, T> {
fn in_loop(self, arg : &'a mut T) {
loop {
(self.func)(arg) //~ ERROR cannot borrow
}
}
fn in_while(self, arg : &'a mut T) {
while true {
(self.func)(arg) //~ ERROR cannot borrow
}
}
fn in_for(self, arg : &'a mut T) {
let v : Vec<()> = vec![];
for _ in v.iter() {
(self.func)(arg) //~ ERROR cannot borrow
}
}
}
fn main() {
}