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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

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 12:13:27 +00: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 12:13:27 +00: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 12:13:27 +00:00
(self.func)(arg) //~ ERROR cannot borrow
}
}
}
fn main() {
}