On 13-08-23 12:16 PM, Simon Sapin wrote:
> Le 23/08/2013 19:47, Matthieu Monrocq a écrit :
>> The most trivial mistake is to have `+=` and `+` defined so that `a +=
>> 5` has a different result than `a = a + 5`
> 
> Would it work to make `a += b` always expand to `a = a + b`, and have
> that not be overridable? Or am I missing something else?

Generally these operators want to be able to implement optimized
versions that do not produce and destroy temporaries.

This might be a bit less of an issue when you're working with moved
values, but that just (pardon the pun) moves the implementation
challenge elsewhere: making sure that plus(&a,&b) as you'd have on
non-owned values is the same as plus(a,b) on owned-and-moved values.
It's all a bit subtle.

-Graydon

_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to