After reading the Borrowed Pointer Tutorial, I started wondering: why
should the programmer have to specify whether to pass function parameters
by-copy of by-reference?   Couldn't Rust just drop the '&' sigil and let
the compiler decide on parameter passing mode?

If functions parameters are immutable by default, there is no semantic
difference in usage of the parameter no matter which mode was chosen.  And
if the intention is to modify caller's variable, that is already conveyed
by the 'mut' keyword, so, again, the compiler can choose appropriately.

There's already plenty of precedent for letting compiler decide on such
things: even in c++, what looks like a by-reference parameter may end up
being by-value if the function gets inlined (and vice-versa).  Not to
mention the whole inlining decision itself...  Same for c++ return value
optimization (which is even observable by the program!).

Vadim
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to