@@ -103,12 +103,16 @@ It also means that the compiler does not have to introduce a silent
103103using these operators is much more clear.
104104
105105Fortunately, there is no loss in expressiveness, since you can always
106- implement the trait on reference types.
106+ implement the trait on reference types. However, for types that * do*
107+ need to be taken by reference, there is a slight loss in ergonomics
108+ since you may need to explicitly borrow the operands with ` & ` . The
109+ upside is that the ownership semantics become clearer: they more
110+ closely resemble normal function arguments.
107111
108- By keeping Rhs as an input trait on the trait, you can overload on the
112+ By keeping ` Rhs ` as an input trait on the trait, you can overload on the
109113types of both operands via
110114[ multidispatch] ( https://github.com/rust-lang/rfcs/pull/195 ) . By
111- defaulting Rhs to ` Self ` , in
115+ defaulting ` Rhs ` to ` Self ` , in
112116[ the future] ( https://github.com/rust-lang/rfcs/pull/213 ) it will be
113117possible to simply say ` T: Add ` as shorthand for ` T: Add<T> ` , which is
114118the common case.
@@ -134,7 +138,7 @@ impl Add<Complex> for Complex {
134138}
135139
136140// Recovering by-ref semantics:
137- impl <'a , 'b > Add <& 'a str > for & 'b String {
141+ impl <'a , 'b > Add <& 'a str > for & 'b str {
138142 type Result = String ;
139143 fn add (self , rhs : & 'a str ) -> String { ... }
140144}
@@ -293,12 +297,12 @@ will still be possible to write `v[3]` for vectors. In addition, the
293297outlined above:
294298
295299``` rust
296- pub trait Index <Idx > {
300+ pub trait Index <Idx > for Sized ? {
297301 type Sized ? Result ;
298302 fn index <'a >(& 'a self , index : Idx ) -> & 'a Result ;
299303}
300304
301- pub trait IndexMut <Idx > {
305+ pub trait IndexMut <Idx > for Sized ? {
302306 type Sized ? Result ;
303307 fn index_mut <'a >(& 'a mut self , index : Idx ) -> & 'a mut Result ;
304308}
@@ -439,6 +443,8 @@ to be done for 1.0.
439443
440444# Alternatives
441445
446+ ## Comparison traits
447+
442448We could pursue a more aggressive change to the comparison traits by
443449not having ` PartialOrd ` be a super trait of ` Ord ` , but instead
444450providing a blanket ` impl ` for ` PartialOrd ` for any `T:
@@ -453,6 +459,22 @@ true).
453459Since it's unlikely that these other changes can happen in time for
4544601.0, this RFC takes a more conservative approach.
455461
462+ ## Slicing
463+
464+ We may want to drop the ` [] ` notation. This notation was introduced to
465+ improve ergonomics (from ` foo(v.as_slice()) ` to ` foo(v[] ` ), but now
466+ that [ collections reform] ( https://github.com/rust-lang/rfcs/pull/235 )
467+ is starting to land we can instead write ` foo(&*v) ` . If we also had
468+ [ deref coercions] ( https://github.com/rust-lang/rfcs/pull/241 ) , that
469+ would be just ` foo(&v) ` .
470+
471+ While ` &*v ` notation is more ergonomic than ` v.as_slice() ` , it is also
472+ somewhat intimidating notation for a situation that newcomers to the
473+ language are likely to face quickly.
474+
475+ In the opinion of this RFC author, we should either keep ` [] `
476+ notation, or provide deref coercions so that you can just say ` &v ` .
477+
456478# Unresolved questions
457479
458480In the long run, we should support overloading of operators like ` += `
0 commit comments