File tree 1 file changed +27
-0
lines changed 1 file changed +27
-0
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.
You can’t perform that action at this time.
0 commit comments