]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0596.md
Rollup merge of #92310 - ehuss:rustdoc-ice, r=estebank
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0596.md
1 This error occurs because you tried to mutably borrow a non-mutable variable.
2
3 Erroneous code example:
4
5 ```compile_fail,E0596
6 let x = 1;
7 let y = &mut x; // error: cannot borrow mutably
8 ```
9
10 In here, `x` isn't mutable, so when we try to mutably borrow it in `y`, it
11 fails. To fix this error, you need to make `x` mutable:
12
13 ```
14 let mut x = 1;
15 let y = &mut x; // ok!
16 ```