@@ -454,6 +454,38 @@ fn foo(a: &mut i32) {
454
454
```
455
455
"## ,
456
456
457
+
458
+ E0502 : r##"
459
+ This error indicates that you are trying to borrow a variable as mutable when it
460
+ has already been borrowed as immutable.
461
+
462
+ Example of erroneous code:
463
+
464
+ ```compile_fail
465
+ fn bar(x: &mut i32) {}
466
+ fn foo(a: &mut i32) {
467
+ let ref y = a; // a is borrowed as immutable.
468
+ bar(a); // error: cannot borrow `*a` as mutable because `a` is also borrowed
469
+ // as immutable
470
+ }
471
+ ```
472
+
473
+ To fix this error, ensure that you don't have any other references to the
474
+ variable before trying to access it mutably:
475
+
476
+ ```
477
+ fn bar(x: &mut i32) {}
478
+ fn foo(a: &mut i32) {
479
+ bar(a);
480
+ let ref y = a; // ok!
481
+ }
482
+ ```
483
+
484
+ For more information on the rust ownership system, take a look at
485
+ https://doc.rust-lang.org/stable/book/references-and-borrowing.html.
486
+ "## ,
487
+
488
+
457
489
E0504 : r##"
458
490
This error occurs when an attempt is made to move a borrowed variable into a
459
491
closure.
@@ -858,7 +890,6 @@ register_diagnostics! {
858
890
E0385 , // {} in an aliasable location
859
891
E0388 , // {} in a static location
860
892
E0500 , // closure requires unique access to `..` but .. is already borrowed
861
- E0502 , // cannot borrow `..`.. as .. because .. is also borrowed as ...
862
893
E0503 , // cannot use `..` because it was mutably borrowed
863
894
E0505 , // cannot move out of `..` because it is borrowed
864
895
E0508 , // cannot move out of type `..`, a non-copy fixed-size array
0 commit comments