About reference


#1

Hi all,

I am confused about the following example where y is no longer a mutable reference to x, but the compiler still issues an error at Line 6, saying that:

cannot borrow x as mutable more than once at a time

fn main() {
    let mut x = 1;
    let mut z = 2;
    let mut y = &mut x;
    y = &mut z;// Line 5
    let mut p = &mut x;// Line 6
}

#2

This is a limitation of the existing borrow checker; it’ll be fixed with non-lexical lifetimes (NLL).