]>
Commit | Line | Data |
---|---|---|
60c5eb7d XL |
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 | ``` |