summaryrefslogtreecommitdiffstats
path: root/tests/ui/borrowck/mut-borrow-in-loop.rs
blob: 22667906e12d6c546e50552042a54b966fc54b51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 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() {
}