I am rather confused about the following problem. If I understand it correctly
let x = &42; is expanded internally to
let x_value = 42; let x = &x; I think I have seen this in the Rust book somewhere but I cannot find the reference to it.
My problem is concerning the following code:
let x = 42; let rx = &x; let px = rx as *const i32 as *mut i32; unsafe { *px = 0; } println!("{}", x); As expected this prints 0. However, if I write
let rx = &42; let px = rx as *const i32 as *mut i32; unsafe { println!("Deref"); *px = 0; } println!("{}", x); the program terminates after printing out Deref. Aparently something goes wrong when px gets dereferenced. I guess my first assessment about let x = &42 getting expanded internally is wrong.