Why nested mut method calls aren't allowed

A possible solution is to only allow changing the order in which function arguments are borrowed if it has no visible side effects. In the case of foo(&mut a, bar(&mut a)), changing the evaluation order does have visible side effects: The bar function may mutate a, which affects the first argument if it is evaluated after the second one. However, it would work here:

foo(&mut a, bar(&a))

Here the evaluation order of the arguments does not matter (unless Deref coercion occurs). If this is a common pain point, and the compiler can prove that changing the evaluation order here does not affect the program's behavior, then this is a reasonable request. It is actually very similar to NLL: It makes the compiler smarter in order to accept more valid programs that would otherwise require more boilerplate, and it only works in situations where it can't affect program behavior (for instance, NLL doesn't work on types that implement Drop).

/r/rust Thread Parent