This error occurs because you tried to mutably borrow a non-mutable variable.
Erroneous code example:
#![allow(unused)]
fn main() {
let x = 1;
let y = &mut x; // error: cannot borrow mutably
} 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:
#![allow(unused)]
fn main() {
let mut x = 1;
let y = &mut x; // ok!
}
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/error_codes/E0596.html