Skip to content

Commit 75c6428

Browse files
committed
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.
1 parent 55752a4 commit 75c6428

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/librustc_borrowck/diagnostics.rs

+8
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ let mut x: i64 = 1;
179179
let mut y: Box<_> = Box::new(&mut x);
180180
**y = 2;
181181
```
182+
183+
It can also be fixed by using a type with interior mutability, such as `Cell` or
184+
`RefCell`:
185+
186+
```
187+
let y: Cell<_> = Cell::new(1);
188+
y.set(2);
189+
```
182190
"##,
183191

184192
E0387: r##"

0 commit comments

Comments
 (0)