]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0499.md
Rollup merge of #93556 - dtolnay:trailingcomma, r=cjgillot
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0499.md
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
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.
16
17 [references-and-borrowing]: https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html
18
19 Example:
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 ```