Function eval order: inside-out, left-right?

  1. Is function arg evaluation order guaranteed in Rust?///
z(  f(a(), b()), c(d()), e() )

We are guaranteed that the eval order is: a, b, f, d, c, e, z ?

Can someone more familiar with Rust please verify if the following is correct?

Due to borrowing rules, the answer once again is "it's complicated" and we can NOT assume that order of evaluation is left -> right, inside -> out.

As with the conclusion of that discussion, the evaluation order is essentially fixed. Changes won't be made to it, and it'll behave it does today in the future.

Due to borrowing rules, the answer once again is “it’s complicated” and we can NOT assume that order of evaluation is left -> right, inside -> out.

Borrowing rules have not and will never influence order of evaluation (besides just making language designers make different decisions, which the phase for has already passed). I believe the post was saying that, in the rust compiler as of 2015, the borrower checker checked according to rules slightly different from how the compiler compiled. If I understand the post correctly, this was fixed with MIR and there are no longer such inconsistencies. At no point did borrow rules change the order of evaluation, though.

I don't know when the order will be properly documented, or if it has already been, but it has been fixed, and any documentation will follow what can be observed in today's rust compiler.

3 Likes