about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNathan Kleyn <nathan@nathankleyn.com>2015-08-13 09:25:56 +0100
committerNathan Kleyn <nathan@nathankleyn.com>2015-08-13 10:17:56 +0100
commit75c6428e1bf2f5564392276642d962163d8a9809 (patch)
tree2b340db80077db9e5f5f0a6d6b06b6b773509c6a
parent55752a4bdeae5dad77875b7702a14882fd12725b (diff)
downloadrust-75c6428e1bf2f5564392276642d962163d8a9809.tar.gz
rust-75c6428e1bf2f5564392276642d962163d8a9809.zip
Add details about types with interior mutability to E0386.
Types with interior mutability like `Cell` and `RefCell` can be used to
skirt the restriction on mutating mutable values inside an immutable
container.
-rw-r--r--src/librustc_borrowck/diagnostics.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/librustc_borrowck/diagnostics.rs b/src/librustc_borrowck/diagnostics.rs
index 1aa735f8c63..0d0456cfb42 100644
--- a/src/librustc_borrowck/diagnostics.rs
+++ b/src/librustc_borrowck/diagnostics.rs
@@ -179,6 +179,14 @@ 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`:
+
+```
+let y: Cell<_> = Cell::new(1);
+y.set(2);
+```
 "##,
 
 E0387: r##"