Skip to content

Commit

Permalink
Merge pull request #59 from RalfJung/interior-mutability
Browse files Browse the repository at this point in the history
extend def.n of interior mutability
  • Loading branch information
RalfJung committed Jan 24, 2019
2 parents 9c98402 + 754de4e commit 50c65d0
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions reference/src/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

#### Interior mutability

*Interior Mutability* means mutating memory where there also exists a live shared reference immediately (i.e., non-transitively) pointing to the same memory.
This propagates recursively through references, but not through raw pointers.
*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.
"live" here means a value that will be "used again" later.
"derived from" means that the pointer was obtained by casting a shared reference and potentially adding an offset.
This is not yet precisely defined, which will be fixed as part of developing a precise aliasing model.

Finding live shared references propagates recursively through references, but not through raw pointers.
So, for example, if data immediately pointed to by a `&T` or `& &mut T` is mutated, that's interior mutability.
If data immediately pointed to by a `*const T` or `&*const T` is mutated, that's *not* interior mutability.

"live" here means a value that will be "used again" later.
This is not yet precisely defined, this will be fixed as part of developing a precise aliasing model.

Interior mutability is only allowed inside [`UnsafeCell`](https://doc.rust-lang.org/core/cell/struct.UnsafeCell.html).
*Interior mutability* refers to the ability to perform interior mutation without causing UB.
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.

#### Validity and safety invariant

Expand Down

0 comments on commit 50c65d0

Please sign in to comment.