You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let x: &mut [int] = &mut [1, 2, 3, 4, 5];
let y = x[1..2];
Currently, it does not find the Slice trait for &mut [T]. That is because both the Slice and SliceMut traits are implemented for [T]. SliceMut methods take self as &mut self whereas Slice methods are & self. We do no coercions when looking up methods for overloaded operators, so we don't do the &mut [T] -> &[T] coercion we would do when doing a normal trait method search.
We have three options:
1 leave as is, this seems surprising and unergonomic;
2 do a special &mut -> & coercion when searching for slice methods. I suspect we want something similar for Index etc. when we implement those in a DST-ish way;
3 allow proper coercions when desugaring Index, Slice, etc. - this is potentially complicated.
I prefer option 3, but I have not thought through the repercussions.
The text was updated successfully, but these errors were encountered:
e.g., this should work:
Currently, it does not find the
Slice
trait for&mut [T]
. That is because both theSlice
andSliceMut
traits are implemented for[T]
.SliceMut
methods take self as&mut self
whereasSlice
methods are& self
. We do no coercions when looking up methods for overloaded operators, so we don't do the&mut [T]
->&[T]
coercion we would do when doing a normal trait method search.We have three options:
1 leave as is, this seems surprising and unergonomic;
2 do a special
&mut
->&
coercion when searching for slice methods. I suspect we want something similar for Index etc. when we implement those in a DST-ish way;3 allow proper coercions when desugaring Index, Slice, etc. - this is potentially complicated.
I prefer option 3, but I have not thought through the repercussions.
The text was updated successfully, but these errors were encountered: