]>
Commit | Line | Data |
---|---|---|
60c5eb7d XL |
1 | A variable was borrowed as mutable more than once. |
2 | ||
3 | Erroneous code example: | |
4 | ||
5 | ```compile_fail,E0499 | |
6 | let mut i = 0; | |
7 | let mut x = &mut i; | |
8 | let mut a = &mut i; | |
9 | x; | |
10 | // error: cannot borrow `i` as mutable more than once at a time | |
11 | ``` | |
12 | ||
74b04a01 XL |
13 | Please note that in Rust, you can either have many immutable references, or one |
14 | mutable reference. For more details you may want to read the | |
15 | [References & Borrowing][references-and-borrowing] section of the Book. | |
60c5eb7d | 16 | |
74b04a01 XL |
17 | [references-and-borrowing]: https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html |
18 | ||
19 | Example: | |
60c5eb7d XL |
20 | |
21 | ``` | |
22 | let mut i = 0; | |
23 | let mut x = &mut i; // ok! | |
24 | ||
25 | // or: | |
26 | let mut i = 0; | |
27 | let a = &i; // ok! | |
28 | let b = &i; // still ok! | |
29 | let c = &i; // still ok! | |
30 | b; | |
31 | a; | |
32 | ``` |