Skip to content

Commit

Permalink
Add descriptive error explanation for E0502
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy McRoy committed May 15, 2016
1 parent 9f58fb7 commit bbb7844
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/librustc_borrowck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,33 @@ fn foo(a: &mut i32) {
```
"##,

E0502: r##"
This error indicates that you are trying to borrow a variable as mutable when it
has already been borrowed as immutable.
Example of erroneous code:
```compile_fail
fn bar(x: &mut i32) {}
fn foo(a: &mut i32) {
let ref y = a; // a is borrowed as immutable.
bar(a); // error: cannot borrow `*a` as mutable because `a` is also borrowed
// as immutable
}
```
To fix this error, ensure that you don't have any other references to the
variable before trying to access it mutably:
```
fn bar(x: &mut i32) {}
fn foo(a: &mut i32) {
bar(a);
let ref y = a; // ok!
}
```
For more information on the rust ownership system, take a look at
https://doc.rust-lang.org/stable/book/references-and-borrowing.html.
"##,

E0504: r##"
This error occurs when an attempt is made to move a borrowed variable into a
closure.
Expand Down

0 comments on commit bbb7844

Please sign in to comment.