For one, the Index trait is in dire need of an overhaul.

In respect to the operator traits in general, I have actually been thinking of 
submitting an RFC proposing that they take thier parameters by-value instead of 
by-ref. That would remove the auto-ref behaviour of the operators which is more 
consistent with the rest of Rust:


    impl<'a, 'b, T> Mul<&'b Mat<T>, Mat<T>> for &'a Mat<T> {
        fn mul(&'a self, other: &'b Mat<T>) -> T { ... }
    }

    let m2: Mat<_> = &m0 * &m1;


~Brendan

On 16 Apr 2014, at 3:23 pm, Artella Coding <[email protected]> 
wrote:

> Hi Eric, this is an example of code which gives the error : 
> 
> ************************************************************
> struct Cls {
>       vec : ~[~int]
> }
> 
> /*
>     Does not compile, yielding error message : 
> 
>     "method `index` has an incompatible type for trait: 
>     expected concrete lifetime, but found bound lifetime 
>     parameter &"
> */
> impl<'a> Index<uint,&'a ~int> for Cls {
>       fn index(&'a self, i: &uint) -> &'a ~int {
>           let val = &'a self.vec[*i];
>           return val;
>       }
> }
> 
> fn main(){}
> ************************************************************
> 
> It is easy to write a function which does the exact same thing (for the 
> struct above) and has a return type with a bounded lifetime, and therefore it 
> does not make sense to me why operator overloading would be restricted in 
> this fashion (i.e. restricted to return concrete lifetimes). Thanks.
> 
> 
> 
> On Wed, Apr 16, 2014 at 2:48 AM, Eric Reed <[email protected]> wrote:
> Could you provide a code sample that causes this error?
> 
> 
> On Tue, Apr 15, 2014 at 6:28 AM, Artella Coding 
> <[email protected]> wrote:
> 
> Currently if I try to specify lifetimes in the return types of overloaded 
> operators like Index ([]), I get an error message : 
> 
> "method `index` has an incompatible type for trait: expected concrete 
> lifetime, but found bound lifetime parameter &"
> 
> Why has this restriction been placed, given that I can write custom functions 
> which can have bounded lifetimes specifications in the return type?
> 
> Thanks
> 
> _______________________________________________
> 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

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

Reply via email to