This is to some extent in flux (see bug #10337). But the branch I am
working on actually reports *both* usages as errors. The correct code
would be:

   *p + n
   n + *p

Basically, a binary operator like `l + r` is translated to something
similar to the following (which assumes universal function notation,
not yet implemented):

   Add::add(&l, &r)

In other words, no autoderef or other transformation takes place.  We
just look for a matching trait. Instead we just pass the values in by
reference. The reason for passing by reference is so that you can
compare linear types more naturally (i.e., `~[1, 2, 3]`).

I still consider the precise behavior of overloaded operators somewhat
experimental, but I know that I am not happy with the current one,
which is quite ad hoc.


Niko

 On Thu, Nov 14, 2013 at 05:50:05AM +0200, Tommi wrote:
> let mut n = 11;
> let p: &int = &123;
> 
> p + n; // OK
> n + p; // error: mismatched types: expected `int` but found `&int`
> 
> Shouldn't this error be considered a compiler-bug? The Add trait says '&' for 
> rhs after all:
> fn add(&self, rhs: &RHS) -> Result;
> 
> -Tommi
> 
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to