Skip to content

Borrow Rules

Current compiler checks include:

  • mutable borrow exclusivity
  • immutable/mutable overlap rejection
  • no reference escape to forbidden storage/returns

Example:

fn main() {
let mut x = 10
let y = &mut x
*y = 12
println(*y)
}

When borrows overlap illegally, the compiler emits diagnostics at check time.