Skip to content
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

Future-proof indexing on maps: remove IndexMut #23559

Merged
merged 1 commit into from
Mar 23, 2015

Conversation

aturon
Copy link
Member

@aturon aturon commented Mar 20, 2015

This commit removes the IndexMut impls on HashMap and BTreeMap, in
order to future-proof the API against the eventual inclusion of an
IndexSet trait.

Ideally, we would eventually be able to support:

map[owned_key] = val;
map[borrowed_key].mutating_method(arguments);
&mut map[borrowed_key];

but to keep the design space as unconstrained as possible, we do not
currently want to support IndexMut, in case some other strategy will
eventually be needed.

Code currently using mutating index notation can use get_mut instead.

[breaking-change]

Closes #23448

r? @gankro

This commit removes the `IndexMut` impls on `HashMap` and `BTreeMap`, in
order to future-proof the API against the eventual inclusion of an
`IndexSet` trait.

Ideally, we would eventually be able to support:

```rust
map[owned_key] = val;
map[borrowed_key].mutating_method(arguments);
&mut map[borrowed_key];
```

but to keep the design space as unconstrained as possible, we do not
currently want to support `IndexMut`, in case some other strategy will
eventually be needed.

Code currently using mutating index notation can use `get_mut` instead.

[breaking-change]

Closes rust-lang#23448
@aturon
Copy link
Member Author

aturon commented Mar 20, 2015

Note that I did not remove from VecMap (which is not stable) nor from VecDequeue (where IndexSet would be of limited usefulness).

{
fn index_mut(&mut self, key: &Q) -> &mut V {
self.get_mut(key).expect("no entry found for key")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof, I dunno if we'll be able to accurately reproduce such complex functionality.

@Gankra
Copy link
Contributor

Gankra commented Mar 20, 2015

@bors r+

@bors
Copy link
Contributor

bors commented Mar 20, 2015

📌 Commit 5fe0bb7 has been approved by Gankro

@bors
Copy link
Contributor

bors commented Mar 21, 2015

⌛ Testing commit 5fe0bb7 with merge 7740b61...

@bors
Copy link
Contributor

bors commented Mar 21, 2015

💔 Test failed - auto-win-32-opt

@alexcrichton
Copy link
Member

@bors: retry

On Sat, Mar 21, 2015 at 6:05 AM, bors notifications@github.com wrote:

[image: 💔] Test failed - auto-win-32-opt
http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/3815


Reply to this email directly or view it on GitHub
#23559 (comment).

Manishearth added a commit to Manishearth/rust that referenced this pull request Mar 21, 2015
…nkro

 This commit removes the `IndexMut` impls on `HashMap` and `BTreeMap`, in
order to future-proof the API against the eventual inclusion of an
`IndexSet` trait.

Ideally, we would eventually be able to support:

```rust
map[owned_key] = val;
map[borrowed_key].mutating_method(arguments);
&mut map[borrowed_key];
```

but to keep the design space as unconstrained as possible, we do not
currently want to support `IndexMut`, in case some other strategy will
eventually be needed.

Code currently using mutating index notation can use `get_mut` instead.

[breaking-change]

Closes rust-lang#23448

r? @gankro
@bors
Copy link
Contributor

bors commented Mar 21, 2015

@bors
Copy link
Contributor

bors commented Mar 21, 2015

💔 Test failed - auto-mac-32-opt

@alexcrichton
Copy link
Member

@bors: retry

On Sat, Mar 21, 2015 at 4:10 PM, bors notifications@github.com wrote:

[image: 💔] Test failed - auto-mac-32-opt
http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/4182


Reply to this email directly or view it on GitHub
#23559 (comment).

@bors
Copy link
Contributor

bors commented Mar 22, 2015

⌛ Testing commit 5fe0bb7 with merge c6a0865...

Manishearth added a commit to Manishearth/rust that referenced this pull request Mar 22, 2015
…nkro

 This commit removes the `IndexMut` impls on `HashMap` and `BTreeMap`, in
order to future-proof the API against the eventual inclusion of an
`IndexSet` trait.

Ideally, we would eventually be able to support:

```rust
map[owned_key] = val;
map[borrowed_key].mutating_method(arguments);
&mut map[borrowed_key];
```

but to keep the design space as unconstrained as possible, we do not
currently want to support `IndexMut`, in case some other strategy will
eventually be needed.

Code currently using mutating index notation can use `get_mut` instead.

[breaking-change]

Closes rust-lang#23448

r? @gankro
@bors
Copy link
Contributor

bors commented Mar 23, 2015

💔 Test failed - auto-linux-32-nopt-t

@aturon
Copy link
Member Author

aturon commented Mar 23, 2015

@bors: retry

@bors bors merged commit 5fe0bb7 into rust-lang:master Mar 23, 2015
Ms2ger added a commit to servo/servo that referenced this pull request May 1, 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.

Remove IndexMut impl from various collections to prepare for possible IndexSet in the future
4 participants