liveBook · Manning

Aliasing

As explained in Rust in Action: Systems programming concepts and techniques

Aliasing is the condition in which multiple references or access paths designate the same memory location at the same time.

Aliasing occurs when multiple references or access paths designate the same memory location at the same time. In Rust, read-only borrows may alias the same data, while mutable borrows are guaranteed not to alias. section 3.4.1

Read-only versus mutable access

Several read-only references can inspect one variable together. A mutable reference requires exclusive access, preventing another reference from changing or simultaneously accessing that location. This rule lets `let` data appear immutable while types such as `Rc` and `Arc` update internal reference counts. section 3.4.1

Keep these distinctions in mind:

  • `let` concerns aliasing and can contain data that changes internally; `const` represents a different form of fixed data. section 3.4.1
  • Read-write references cannot alias the same data, whereas read-only borrows can. section 3.4.1

How Rust in Action: Systems programming concepts and techniques covers it

How deep it goes
Defines aliasing and contrasts read-only and mutable borrows, while stopping short of detailed compiler implementation.
Examples
Uses shared read-only references and internally changing Rc or Arc values as concrete comparisons.
What it assumes
Assumes basic variables and references while introducing aliasing through Rust's mutability rules.
What you can do after
Evaluate whether references can safely coexist by distinguishing shared borrows from exclusive mutable borrows.
How it connects
Connects aliasing with borrowing, mutability, const, let, interior mutability, Rc, and Arc.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust in Action: Systems programming concepts and techniques. The section links point to the parts of the book it draws on.