File tree 1 file changed +27
-1
lines changed
1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -501,6 +501,33 @@ fn foo(a: &mut i32) {
501
501
```
502
502
"## ,
503
503
504
+ E0502 : r##"
505
+ This error indicates that you are trying to borrow a variable as mutable when it
506
+ has already been borrowed as immutable.
507
+
508
+ Example of erroneous code:
509
+
510
+ ```compile_fail
511
+ fn bar(x: &mut i32) {}
512
+ fn foo(a: &mut i32) {
513
+ let ref y = a; // a is borrowed as immutable.
514
+ bar(a); // error: cannot borrow `*a` as mutable because `a` is also borrowed
515
+ // as immutable
516
+ }
517
+ ```
518
+ To fix this error, ensure that you don't have any other references to the
519
+ variable before trying to access it mutably:
520
+ ```
521
+ fn bar(x: &mut i32) {}
522
+ fn foo(a: &mut i32) {
523
+ bar(a);
524
+ let ref y = a; // ok!
525
+ }
526
+ ```
527
+ For more information on the rust ownership system, take a look at
528
+ https://doc.rust-lang.org/stable/book/references-and-borrowing.html.
529
+ "## ,
530
+
504
531
E0504 : r##"
505
532
This error occurs when an attempt is made to move a borrowed variable into a
506
533
closure.
@@ -983,7 +1010,6 @@ fn main() {
983
1010
register_diagnostics ! {
984
1011
E0385 , // {} in an aliasable location
985
1012
E0388 , // {} in a static location
986
- E0502 , // cannot borrow `..`.. as .. because .. is also borrowed as ...
987
1013
E0503 , // cannot use `..` because it was mutably borrowed
988
1014
E0508 , // cannot move out of type `..`, a non-copy fixed-size array
989
1015
E0524 , // two closures require unique access to `..` at the same time
You can’t perform that action at this time.
0 commit comments