Iām a rust beginner, this code succeeds to compile. If uncomment line L2, there is an error , because y_i32_ref continues to mutable borrow y_num_ref even if y_i32_ref is not used . But line L1 has no problem? I think x_i32_ref should borrow x_num_ref as y_i32_ref. Could anyone explain
It's because when you have nested references, the compiler will automatically convert &'short &'long T into &'short &short T, but it will not make that conversion for mutable references. The two kinds of references are not treated the same.