//! Local loans end at branch and loop scope boundaries. /// Release each branch borrow before accessing the source. fn branches(flag: bool) { let mut n: u32 = 0; if flag { let p = &mut n; set *p = 1; } else { let q = &mut n; set *q = 2; } set n = 3; } /// Release the body borrow before the next condition check. fn whileLoop() { let mut n: u32 = 0; while n < 4 { let p = &mut n; set *p += 1; } set n = 5; } /// Release the body borrow when the loop exits. fn breakLoop() { let mut n: u32 = 0; loop { let p = &mut n; set *p = 1; break; } set n = 2; } /// Two scalar fields. record Pair: Copy { /// First scalar. a: u32, /// Second scalar. b: u32, } /// Nested and independent scalar storage. record Nested: Copy { /// Nested record. r: Pair, /// Independent scalar. n: u32, } /// Borrow nested siblings while mutating a separate outer field. fn nestedFields(s: &mut Nested) { let r = &mut s.r; let a = &mut r.a; let b = &mut r.b; set *a = 1; set *b = 2; set s.n = 3; }