]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0499.md
Rollup merge of #62514 - stephaneyfx:box-ffi, r=nikomatsakis
[rust.git] / src / librustc_error_codes / 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. Take a look at
15 https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html for more
16 information. Example:
17
18
19 ```
20 let mut i = 0;
21 let mut x = &mut i; // ok!
22
23 // or:
24 let mut i = 0;
25 let a = &i; // ok!
26 let b = &i; // still ok!
27 let c = &i; // still ok!
28 b;
29 a;
30 ```