# Package for Rust-like borrow checker in Julia?

**URL:** <https://discourse.julialang.org/t/package-for-rust-like-borrow-checker-in-julia/124442>\
**Category:** General Usage\
**Tags:** question\
**Created:** [January 5, 2025, 11:17am UTC](https://discourse.julialang.org/t/package-for-rust-like-borrow-checker-in-julia/124442 "2025-01-05T11:17:12Z")\
**Posts on this page:** 1\
**Showing post:** 70

<div class="post-metadata">

**Author:** ![MilesCranmer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milescranmer/32/21070_2.png) [@MilesCranmer](https://discourse.julialang.org/u/MilesCranmer)\
**Post date:** [January 7, 2025, 6:37pm UTC](https://discourse.julialang.org/t/package-for-rust-like-borrow-checker-in-julia/124442/70 "2025-01-07T18:37:14Z")

</div>

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](https://discourse.julialang.org/t/whats-the-aliasing-story-in-julia/102564).

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 –

```julia
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.

---

_[View the full topic](https://discourse.julialang.org/t/package-for-rust-like-borrow-checker-in-julia/124442)._
