summaryrefslogtreecommitdiffstats
path: root/tests/ui/borrowck/issue-81365-11.rs
blob: 6b558c65d3d614250c4c86fff089715ad9e2a185 (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
30
31
32
use std::ops::{Deref, DerefMut};

struct DerefTarget {
    target_field: bool,
}
struct Container {
    target: DerefTarget,
    container_field: bool,
}

impl Deref for Container {
    type Target = DerefTarget;
    fn deref(&self) -> &Self::Target {
        &self.target
    }
}

impl DerefMut for Container {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.target
    }
}

impl Container {
    fn bad_borrow(&mut self) {
        let first = &mut self.target_field;
        self.container_field = true; //~ ERROR E0506
        first;
    }
}

fn main() {}