# Smarter borrow checking for function calls

**URL:** <https://internals.rust-lang.org/t/smarter-borrow-checking-for-function-calls/7509>\
**Category:** compiler\
**Created:** [May 11, 2018, 12:13pm UTC](https://internals.rust-lang.org/t/smarter-borrow-checking-for-function-calls/7509 "2018-05-11T12:13:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josef-Vonasek](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@Josef-Vonasek](https://internals.rust-lang.org/u/Josef-Vonasek)\
**Post date:** [May 11, 2018, 12:14pm UTC](https://internals.rust-lang.org/t/smarter-borrow-checking-for-function-calls/7509/1 "2018-05-11T12:14:00Z")

</div>

The issue:

This compiles fine

```rust
array[10] = array[11]

```

This raises borrow checker error

```rust
set(array, 10, get(array, 11))
// or
array.set(10, array.get(11))

```

The reason for this behavior is the immutable borrow in `get` interferes with mutable borrow in `set`, because rust evaluates from left to right.

For example this compiles without a problem.

```rust
set(10, get(11, array), array)

```

I think the obvious way to solve it, is to make the compiler understand, that the values are borrowed **after** the function body is entered (arguments are already evaluated and put on stack by that time).

---

<div class="post-metadata">

**Author:** ![Ixrec](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/ixrec/32/6754_2.png) [@Ixrec](https://internals.rust-lang.org/u/Ixrec)\
**Post date:** [May 11, 2018, 12:17pm UTC](https://internals.rust-lang.org/t/smarter-borrow-checking-for-function-calls/7509/2 "2018-05-11T12:17:44Z")

</div>

I believe this is already implemented on nightly: [https://github.com/rust-lang/rust/issues/46037](https://github.com/rust-lang/rust/issues/46037)

[[blog post] Nested method calls via two-phase borrowing](https://internals.rust-lang.org/t/blog-post-nested-method-calls-via-two-phase-borrowing/4886) contains a proper explanation and discussion of the proposed solution that I believe got implemented.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 25, 2019, 8:30am UTC](https://internals.rust-lang.org/t/smarter-borrow-checking-for-function-calls/7509/3 "2019-03-25T08:30:12Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
