r/ProgrammingLanguages • u/jamiiecb • Apr 10 '26
Borrow-checking surprises
https://www.scattered-thoughts.net/writing/borrow-checking-surprises
52
Upvotes
r/ProgrammingLanguages • u/jamiiecb • Apr 10 '26
View all comments
Show parent comment
12
u/matthieum Apr 10 '26
Honestly, I think it was a mistake in Rust to rule that a statement should be evaluated left to right, and therefore the left-hand side of an assignment should be valuated prior to the right-hand side... then having to carve out exceptions for borrow-checking ergonomics.
Instead, you could make the clear exception to the general left-to-right rule that in assignments the right-hand side is evaluated first, and you'd have a simpler set of rules, requiring no borrow-checking exception.
I'd personally want to push it even further, and argue that in general the receiver of a function call should be evaluated after the arguments of the call. That is, allowing
vec.push(vec.len())... and simply see assignment as an.=function call. One reason not to, though, is that it breaks the idea thatvec.push(x)is sugar forVec::push(&mut vec, x).Did we need right-to-left evaluation all along? Was GCC right?