Skip to content

Conversation

japaric
Copy link
Contributor

@japaric japaric commented Feb 5, 2015

closes #21630

Overloaded indexing (&[mut] foo[bar]) only works when <Self as Index>::Output is the same as <Self as IndexMut>::Output (see issue above). To restrict implementations of IndexMut that doesn't work, this PR makes IndexMut a supertrait over Index, i.e. trait IndexMut<I>: Index<I>, just like in the trait DerefMut: Deref case.

This breaks all downstream implementations of IndexMut, in most cases this simply means removing the type Output = .. bit, which is now redundant, from IndexMut implementations:

 impl Index<Foo> for Bar {
     type Output = Baz;
     ..
 }

 impl IndexMut<Foo> for Bar {
-    type Output = Baz;
     ..
 }

[breaking-change]


r? @nikomatsakis

@nikomatsakis
Copy link
Contributor

@bors r+ 5270eac

👍

@japaric
Copy link
Contributor Author

japaric commented Feb 7, 2015

@bors: r=nikomatsakis 724bf7b

@bors
Copy link
Collaborator

bors commented Feb 7, 2015

⌛ Testing commit 724bf7b with merge 0b6dbbc...

bors added a commit that referenced this pull request Feb 7, 2015
closes #21630

Overloaded indexing (`&[mut] foo[bar]`) only works when `<Self as Index>::Output` is the same as `<Self as IndexMut>::Output` (see issue above). To restrict implementations of `IndexMut` that doesn't work, this PR makes `IndexMut` a supertrait over `Index`, i.e. `trait IndexMut<I>: Index<I>`, just like in the `trait DerefMut: Deref` case.

This breaks all downstream implementations of `IndexMut`, in most cases this simply means removing the `type Output = ..` bit, which is now redundant, from `IndexMut` implementations:

``` diff
 impl Index<Foo> for Bar {
     type Output = Baz;
     ..
 }

 impl IndexMut<Foo> for Bar {
-    type Output = Baz;
     ..
 }
```

[breaking-change]

---

r? @nikomatsakis
@bors
Copy link
Collaborator

bors commented Feb 7, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

autoderef: (&mut foo[bar]).baz() works, but foo[bar].baz() fails to type check due to wrong deref
3 participants