//# publish module 0x1.Tester { struct X { f: u64 } bump_and_give(x_ref: &mut Self.X): &u64 { label b0: *(&mut copy(x_ref).X::f) = *&mut copy(x_ref).X::f + 1; return &move(x_ref).X::f; } contrived_example_no(x_ref: &mut Self.X): &u64 { let returned_ref: &u64; label b0: returned_ref = Self.bump_and_give(copy(x_ref)); // ERROR Cannot mutably borrow from `x_ref` it is being borrowed by `returned_ref` assert(*copy(returned_ref) == *freeze(&mut move(x_ref).X::f) + 1, 42); return move(returned_ref); } contrived_example_valid(x_ref: &mut Self.X): &u64 { let returned_ref: &u64; label b0: returned_ref = Self.bump_and_give(copy(x_ref)); // This is still valid, but might not be in other cases. See other Imm Borrow tests // i.e. you might hit FreezeRefExistsMutableBorrowError assert(*copy(returned_ref) == *(&freeze(move(x_ref)).X::f) + 1, 42); return move(returned_ref); } }