Skip to content

Commit 50c65d0

Browse files
authored
Merge pull request #59 from RalfJung/interior-mutability
extend def.n of interior mutability
2 parents 9c98402 + 754de4e commit 50c65d0

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

reference/src/glossary.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22

33
#### Interior mutability
44

5-
*Interior Mutability* means mutating memory where there also exists a live shared reference immediately (i.e., non-transitively) pointing to the same memory.
6-
This propagates recursively through references, but not through raw pointers.
5+
*Interior Mutation* means mutating memory where there also exists a live shared reference pointing to the same memory; or mutating memory through a pointer derived from a shared reference.
6+
"live" here means a value that will be "used again" later.
7+
"derived from" means that the pointer was obtained by casting a shared reference and potentially adding an offset.
8+
This is not yet precisely defined, which will be fixed as part of developing a precise aliasing model.
9+
10+
Finding live shared references propagates recursively through references, but not through raw pointers.
711
So, for example, if data immediately pointed to by a `&T` or `& &mut T` is mutated, that's interior mutability.
812
If data immediately pointed to by a `*const T` or `&*const T` is mutated, that's *not* interior mutability.
913

10-
"live" here means a value that will be "used again" later.
11-
This is not yet precisely defined, this will be fixed as part of developing a precise aliasing model.
12-
13-
Interior mutability is only allowed inside [`UnsafeCell`](https://doc.rust-lang.org/core/cell/struct.UnsafeCell.html).
14+
*Interior mutability* refers to the ability to perform interior mutation without causing UB.
15+
All interior mutation in Rust has to happen inside an [`UnsafeCell`](https://doc.rust-lang.org/core/cell/struct.UnsafeCell.html), so all data structures that have interior mutability must (directly or indirectly) use `UnsafeCell` for this purpose.
1416

1517
#### Validity and safety invariant
1618

0 commit comments

Comments
 (0)