summaryrefslogtreecommitdiffstats
path: root/tests/ui/borrowck/drop-in-loop.rs
blob: 866c27ef20324221f2bcf7a8bc5393587be5dafa (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
// A version of `issue-70919-drop-in-loop`, but without
// the necessary `drop` call.
//
// This should fail to compile, since the `Drop` impl
// for `WrapperWithDrop` could observe the changed
// `base` value.

struct WrapperWithDrop<'a>(&'a mut bool);
impl<'a> Drop for WrapperWithDrop<'a> {
    fn drop(&mut self) {
    }
}

fn drop_in_loop() {
    let mut base = true;
    let mut wrapper = WrapperWithDrop(&mut base);
    loop {
        base = false; //~ ERROR: cannot assign to `base`
        wrapper = WrapperWithDrop(&mut base);
    }
}

fn main() {
}