Why a mutable reference needs to be preceded with &mut

53 points No_Direction_5276 29 comments

I'm following the Rust Book and I came across the following

fn main() {
    let mut s = String::from("hello");

    change(&mut s);
}

fn change(some_string: &mut String) {
    some_string.push_str(", world");
}

My question is, if the variable s is already a mut, what's the need for &mut in change(&mut s);

I can only assume they both serve/hint to a different purpose in the compiler

I'd like to annotate the meaning of each of these

let x;
let mut y;
&x
&y
&mut x
&mut y