rust/tests/ui/borrowck/mut-borrow-in-loop.rs

30 lines
648 B
Rust
Raw Normal View History

// 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 {
2017-11-20 06:13:27 -06:00
(self.func)(arg) //~ ERROR cannot borrow
}
}
fn in_while(self, arg : &'a mut T) {
while true { //~ WARN denote infinite loops with
2017-11-20 06:13:27 -06:00
(self.func)(arg) //~ ERROR cannot borrow
}
}
fn in_for(self, arg : &'a mut T) {
let v : Vec<()> = vec![];
for _ in v.iter() {
2017-11-20 06:13:27 -06:00
(self.func)(arg) //~ ERROR cannot borrow
}
}
}
fn main() {
}