]> git.proxmox.com Git - rustc.git/blame - src/librustc_error_codes/error_codes/E0499.md
New upstream version 1.43.0+dfsg1
[rustc.git] / src / librustc_error_codes / error_codes / E0499.md
CommitLineData
60c5eb7d
XL
1A variable was borrowed as mutable more than once.
2
3Erroneous code example:
4
5```compile_fail,E0499
6let mut i = 0;
7let mut x = &mut i;
8let mut a = &mut i;
9x;
10// error: cannot borrow `i` as mutable more than once at a time
11```
12
74b04a01
XL
13Please note that in Rust, you can either have many immutable references, or one
14mutable 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
19Example:
60c5eb7d
XL
20
21```
22let mut i = 0;
23let mut x = &mut i; // ok!
24
25// or:
26let mut i = 0;
27let a = &i; // ok!
28let b = &i; // still ok!
29let c = &i; // still ok!
30b;
31a;
32```