summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_error_codes/src/error_codes/E0386.md
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_error_codes/src/error_codes/E0386.md')
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0386.md31
1 files changed, 31 insertions, 0 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0386.md b/compiler/rustc_error_codes/src/error_codes/E0386.md
new file mode 100644
index 000000000..de3b468b6
--- /dev/null
+++ b/compiler/rustc_error_codes/src/error_codes/E0386.md
@@ -0,0 +1,31 @@
+#### Note: this error code is no longer emitted by the compiler.
+
+This error occurs when an attempt is made to mutate the target of a mutable
+reference stored inside an immutable container.
+
+For example, this can happen when storing a `&mut` inside an immutable `Box`:
+
+```
+let mut x: i64 = 1;
+let y: Box<_> = Box::new(&mut x);
+**y = 2; // error, cannot assign to data in an immutable container
+```
+
+This error can be fixed by making the container mutable:
+
+```
+let mut x: i64 = 1;
+let mut y: Box<_> = Box::new(&mut x);
+**y = 2;
+```
+
+It can also be fixed by using a type with interior mutability, such as `Cell`
+or `RefCell`:
+
+```
+use std::cell::Cell;
+
+let x: i64 = 1;
+let y: Box<Cell<_>> = Box::new(Cell::new(x));
+y.set(2);
+```