rust/tests/ui/borrowck/mut-borrow-in-loop.rs
2023-01-11 09:32:08 +00:00

30 lines
648 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 { //~ WARN denote infinite loops with
(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() {
}