diff options
| author | Timothy McRoy <timothy-mcroy@uiowa.edu> | 2016-05-15 15:30:59 -0500 |
|---|---|---|
| committer | Timothy McRoy <timothy-mcroy@uiowa.edu> | 2016-05-17 21:13:02 -0500 |
| commit | acfe199c02a3cbc0d500678ea30426daf392f0d3 (patch) | |
| tree | d50e073e127a70ba9552453b992591f411ba461e /src | |
| parent | 9f58fb776a74a44f4fcc2cb57084d33c55530aa4 (diff) | |
Add descriptive error explanation for E0502
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_borrowck/diagnostics.rs | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/librustc_borrowck/diagnostics.rs b/src/librustc_borrowck/diagnostics.rs index cdbad685008..59484254909 100644 --- a/src/librustc_borrowck/diagnostics.rs +++ b/src/librustc_borrowck/diagnostics.rs @@ -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. @@ -983,7 +1010,6 @@ fn main() { register_diagnostics! { E0385, // {} in an aliasable location E0388, // {} in a static location - E0502, // cannot borrow `..`.. as .. because .. is also borrowed as ... E0503, // cannot use `..` because it was mutably borrowed E0508, // cannot move out of type `..`, a non-copy fixed-size array E0524, // two closures require unique access to `..` at the same time |
