Skip to content

Commit 55752a4

Browse files
committed
Add detailed diagnostics for E0386.
This adds detailed diagnostics for E0386, 'cannot assign to data in an immutable container'.
1 parent ea3cd02 commit 55752a4

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/librustc_borrowck/diagnostics.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,27 @@ fn main(){
160160
```
161161
"##,
162162

163+
E0386: r##"
164+
This error occurs when an attempt is made to mutate the target of a mutable
165+
reference stored inside an immutable container.
166+
167+
For example, this can happen when storing a `&mut` inside an immutable `Box`:
168+
169+
```
170+
let mut x: i64 = 1;
171+
let y: Box<_> = Box::new(&mut x);
172+
**y = 2; // error, cannot assign to data in an immutable container
173+
```
174+
175+
This error can be fixed by making the container mutable:
176+
177+
```
178+
let mut x: i64 = 1;
179+
let mut y: Box<_> = Box::new(&mut x);
180+
**y = 2;
181+
```
182+
"##,
183+
163184
E0387: r##"
164185
This error occurs when an attempt is made to mutate or mutably reference data
165186
that a closure has captured immutably. Examples of this error are shown below:
@@ -219,7 +240,6 @@ https://doc.rust-lang.org/std/cell/
219240
register_diagnostics! {
220241
E0383, // partial reinitialization of uninitialized structure
221242
E0385, // {} in an aliasable location
222-
E0386, // {} in an immutable container
223243
E0388, // {} in a static location
224244
E0389 // {} in a `&` reference
225245
}

0 commit comments

Comments
 (0)