summaryrefslogtreecommitdiffstats
path: root/tests/ui/issues/issue-40288.rs
blob: 60204c11754763c432fd749c9e9951f3ed746ad7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn save_ref<'a>(refr: &'a i32, to: &mut [&'a i32]) {
    for val in &mut *to {
        *val = refr;
    }
}

fn main() {
    let ref init = 0i32;
    let ref mut refr = 1i32;

    let mut out = [init];

    save_ref(&*refr, &mut out);

    // This shouldn't be allowed as `refr` is borrowed
    *refr = 3; //~ ERROR cannot assign to `*refr` because it is borrowed

    // Prints 3?!
    println!("{:?}", out[0]);
}