The issue:
This compiles fine
array[10] = array[11]
This raises borrow checker error
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.
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).