Skip to content

make IndexMut a super trait over Index #21949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 7, 2015
Merged

Conversation

japaric
Copy link
Member

@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
Member 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
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