Error code E0596

This error occurs because you tried to mutably borrow a non-mutable variable.

Erroneous code example:

let x = 1;
let y = &mut x; // error: cannot borrow mutably
Run

In here, x isn’t mutable, so when we try to mutably borrow it in y, it fails. To fix this error, you need to make x mutable:

let mut x = 1;
let y = &mut x; // ok!
Run

Back to list of error codes