Change:
I believe we intend to eventually extend the index traits with the ability to override the syntax specifically using a trait like . This would allow hashmaps to be used like and have that insert the key, unlike today where will panic if is not already present. To pave the way, the simplest thing is to remove the operator from those collections where we would anticipate growing on demand. I believe that would be , , and possible and . Thoughts? cc
triage: P-backcompat-libs I-needs-decision (1.0 beta)
triage: P-backcompat-libs (1.0 beta)
I was just starting to prep a PR to resolve this by removing the impl, as you suggested. :)
Don't we want to keep the implementation on for example to do something like ?
Depending on the exact way that is done, it may not be possible to provide both modes of use. That is, we want to be able to write -- which we cannot today -- but it's not clear that you can do that and also support examples like the one you gave. In particular, that involves adjusting inference to determine whether or not a deref is in play. For now, removing these impls will give us the most freedom when we do incorporate .
It seems weird to have this and insert -- insert has a return value, though. This would be a super-annoying ergonomic regression in the interim. What's the expected timeline for something like IndexSet? 1.1?
Oh actually upon reflection most usages I know are Index, not IndexMut. Not as awful a regression.
It should be possible to move in, out, and take references with the operator. If that's not possible with the current design then the current design has to be changed instead of committing to yet another subpar design until 2.0.
sounds powerful and interesting, is there any RFC for it now?
It feels odd that does not support . I don't buy the argument that would be confused with - no other container supports insertion via the syntax. Now if you would add some hypothetical and support insertion into a via , then someone would just get confused that they can't use to insert into a .. (doesn't really makes sense, but what if entries are default constructible!) Not even talking about the pandora box of accidentally inserting elements into the container. Imho we should keep consistent as an accessor to get references to data already existing in the container.

Discussion:
use core::fmt::Debug; use core::hash::{Hash, Hasher}; use core::iter::{Map, FromIterator, IntoIterator}; <del> use core::ops::{Index, IndexMut}; </del> <ins> use core::ops::{Index}; </ins> use core::{iter, fmt, mem, usize}; use Bound::{self, Included, Excluded, Unbounded};

} } <del> #[stable(feature = "rust1", since = "1.0.0")] impl<K: Ord, Q: ?Sized, V> IndexMut<Q> for BTreeMap<K, V> where K: Borrow<Q>, Q: Ord { fn index_mut(&mut self, key: &Q) -> &mut V { self.get_mut(key).expect("no entry found for key") } } </del> /// Genericises over how to get the correct type of iterator from the correct type /// of Node ownership. trait Traverse<N> {

return; } if self.glob_map.contains_key(&import_id) { <del> self.glob_map[import_id].insert(name); </del> <ins> self.glob_map.get_mut(&import_id).unwrap().insert(name); </ins> return; }

// We've successfully resolved the import. Write the results in. let mut import_resolutions = module_.import_resolutions.borrow_mut(); <del> let import_resolution = &mut (*import_resolutions)[target]; </del> <ins> let import_resolution = import_resolutions.get_mut(&target).unwrap(); </ins> { let mut check_and_write_import = |namespace, result: &_, used_public: &mut bool| {

// borrow_kind of the upvar to make sure it // is inferred to mutable if necessary let mut upvar_capture_map = self.fcx.inh.upvar_capture_map.borrow_mut(); <del> let ub = &mut upvar_capture_map[upvar_id]; </del> <ins> let ub = upvar_capture_map.get_mut(&upvar_id).unwrap(); </ins> self.adjust_upvar_borrow_kind(upvar_id, ub, borrow_kind); // also need to be in an FnMut closure since this is not an ImmBorrow

use iter::{self, Iterator, ExactSizeIterator, IntoIterator, IteratorExt, FromIterator, Extend, Map}; use marker::Sized; use mem::{self, replace}; <del> use ops::{Deref, FnMut, Index, IndexMut}; </del> <ins> use ops::{Deref, FnMut, Index}; </ins> use option::Option::{self, Some, None}; use rand::{self, Rng}; use result::Result::{self, Ok, Err};

} } <del> #[stable(feature = "rust1", since = "1.0.0")] impl<K, V, S, Q: ?Sized> IndexMut<Q> for HashMap<K, V, S> where K: Eq + Hash + Borrow<Q>, Q: Eq + Hash, S: HashState, { #[inline] fn index_mut<'a>(&'a mut self, index: &Q) -> &'a mut V { self.get_mut(index).expect("no entry found for key") } } </del> /// HashMap iterator. #[stable(feature = "rust1", since = "1.0.0")] pub struct Iter<'a, K: 'a, V: 'a> {