Package for Rust-like borrow checker in Julia?

Btw @mbauman do you know if there are any new features I should be aware of regarding aliasing detection? I took a look at What's the aliasing story in Julia.

The reason I’m interested in it is because Rust has this feature of allowing multiple mutable references to an object if they point at non-overlapping fields. However, this is only safe because the compiler can prove whether fields are aliased or not.

Meaning this would work –

struct Point
    x::Vector{Int}
    y::Vector{Int}
end

# Mutable binding of a Point object
@bind @mut p = Point([1], [2])

@lifetime lt begin
    # Get references to all fields we'll need
    @ref @mut p_x = p.x in lt
    @ref @mut p_y = p.y in lt
end

These are mutable references (like C pointers) to p.x and p.y. In Rust, this is allowed, because the compiler can prove whether x and y are aliased or not (for any type of data structure). But in Julia I’m not sure if this is possible?

If not then I think we should just ban multiple mutable references (= current behavior), even if they refer to distinct fields. I think it just violates some of the borrow checker semantics. So we’ll be a bit stricter than Rust in that sense, only because we can’t prove things about the memory layout.