Questions about `&mut T` and move semantics, `&mut T` is "move-only"?

Given:

and

I'm inclined to believe that it's just the implicit reborrow that is needed to get Example 4 to work. y is already a mutable reference of the matching type.

// Example 4 - modified with explicit reborrow
fn f(z: &mut i32) {
    *z += 1;
    println!("{}", *z);
}

fn main() {
    let mut x: i32 = 5;
    let y = &mut x;
    
    f(y);               // implicit reborrow
    f(&mut *y);         // explicit reborrow

    *y += 1;
    println!("{}", *y); // '8'
    x += 1;
    println!("{}", x);  // '9'
}
2 Likes