]> git.lizzy.rs Git - rust.git/commitdiff
Add detailed diagnostics for E0383.
authorNathan Kleyn <nathan@nathankleyn.com>
Wed, 12 Aug 2015 17:07:56 +0000 (18:07 +0100)
committerNathan Kleyn <nathan@nathankleyn.com>
Thu, 13 Aug 2015 08:06:29 +0000 (09:06 +0100)
This adds detailed diagnostics for E0383, 'partial reinitialization of
uninitialized structure'.

This is part of rust-lang/rust#24407.

src/librustc_borrowck/diagnostics.rs

index 850701e704613c3ac666d5338c3db85a6903fc97..acd2bf3fba9d6f5a6b1632156b5adbe4c11e8d39 100644 (file)
@@ -138,6 +138,30 @@ fn main() {
 https://doc.rust-lang.org/book/ownership.html
 "##,
 
+E0383: r##"
+This error occurs when an attempt is made to partially reinitialize a
+structure that is currently uninitialized.
+
+For example, this can happen when a transfer of ownership has taken place:
+
+```
+let mut t = Test { a: 1, b: None};
+let mut u = Test { a: 2, b: Some(Box::new(t))}; // `t` is now uninitialized
+                                                // because ownership has been
+                                                // transferred
+t.b = Some(Box::new(u)); // error, partial reinitialization of uninitialized
+                         //        structure `t`
+```
+
+This error can be fixed by fully reinitializing the structure in question:
+
+```
+let mut t = Test { a: 1, b: None};
+let mut u = Test { a: 2, b: Some(Box::new(t))};
+t = Test { a: 1, b: Some(Box::new(u))};
+```
+"##,
+
 E0384: r##"
 This error occurs when an attempt is made to reassign an immutable variable.
 For example:
@@ -217,7 +241,6 @@ fn mutable() {
 }
 
 register_diagnostics! {
-    E0383, // partial reinitialization of uninitialized structure
     E0385, // {} in an aliasable location
     E0386, // {} in an immutable container
     E0388, // {} in a static location