I'm working on my understanding of Rust's ownership- and borrowing-model and am confused by the following:
let mut x: i32 = 1;
let ref_x = &mut x;
let refref_x = &mut *ref_x;
*refref_x = 2;
*ref_x = 3;
To my knowledge, I am effectively creating two separate mutable references to x
. Why is this code legal when avoiding the indirection through pointers and just changing line 3 to
let refref_x = &mut x;
is obviously not? Am I misunderstanding central concepts or is the compiler adding some magic in the background?