Skip to content

Commit 9c0d2b2

Browse files
committed
Add detailed diagnostics for E0383.
This adds detailed diagnostics for E0383, 'partial reinitialization of uninitialized structure'. This is part of #24407.
1 parent 8b5948d commit 9c0d2b2

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/librustc_borrowck/diagnostics.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,30 @@ Book:
138138
https://doc.rust-lang.org/book/ownership.html
139139
"##,
140140

141+
E0383: r##"
142+
This error occurs when an attempt is made to partially reinitialize a
143+
structure that is currently uninitialized.
144+
145+
For example, this can happen when a transfer of ownership has taken place:
146+
147+
```
148+
let mut t = Test { a: 1, b: None};
149+
let mut u = Test { a: 2, b: Some(Box::new(t))}; // `t` is now uninitialized
150+
// because ownership has been
151+
// transferred
152+
t.b = Some(Box::new(u)); // error, partial reinitialization of uninitialized
153+
// structure `t`
154+
```
155+
156+
This error can be fixed by fully reinitializing the structure in question:
157+
158+
```
159+
let mut t = Test { a: 1, b: None};
160+
let mut u = Test { a: 2, b: Some(Box::new(t))};
161+
t = Test { a: 1, b: Some(Box::new(u))};
162+
```
163+
"##,
164+
141165
E0384: r##"
142166
This error occurs when an attempt is made to reassign an immutable variable.
143167
For example:
@@ -217,7 +241,6 @@ https://doc.rust-lang.org/std/cell/
217241
}
218242

219243
register_diagnostics! {
220-
E0383, // partial reinitialization of uninitialized structure
221244
E0385, // {} in an aliasable location
222245
E0386, // {} in an immutable container
223246
E0388, // {} in a static location

0 commit comments

Comments
 (0)