Auto reference in Rust


Is there any outlook or discussion about including auto referencing the language? I found several discussion on the net on the topic, but I did not find any reason as to why not to do it, except that potentially it might be “misleading” for the user, and potential clashes of traits with both signatures. However, I think there might be work around both of those issues, however for some cases, especially operators, this leads to some significantly bad looking code with readability 0. This is true when operators return by value, but you want to take by reference, for instance:

// 5a^2b^2c^2 + floor(ab^2, 2) + min(a^2, b^2) + 3
let poly = &(&(&(&(&a * &a) * &(&b * &b)) * &(&c * &c)) * 5) + &(&floor(&(&(&a * &b) * &b), &2.into()) + &(&min(&(&a * &a), &(&b * &b)) + 3));

In this case all operators are defined for a reference, but return a value. An alternative would be to wrap a reference/Rc/Arc with a struct and pass that by value, however this just brings me back to c++ idioms and also beats the point of having a reference at all.

I’m wondering for other drawbacks of this and well, I’m not an expert on Rust so maybe I’m significantly overlooking things obvious.


Basically, we’ve chosen the most conservative option; you can always add in more automatic dereferencing later, but once it’s in, you can’t remove it. People generally prefer the explicitness; I’ve never seen code like yours in the wild. Which doesn’t mean that it never exists, of course, but I’m not sure it happens often enough in practice to be an issue. Floor and min would usually take things by value, not by reference, for example.


Is there anyway, maybe with a trait or smth that this could be made possible at the moment. The main case for my code is when these are custom large types, rather than primitive values, thus you almost never want to move an object inside an operator.

Otherwise, I think I understand from that point of view why for now it is the good choice. However, have you guys discovered /discussed more situation where it could be harmful?