Closed
Description
The function get_index_mut
gives a mutable reference to the of an entry, but does not update the corresponding hash. This means you can write buggy code like this:
use indexmap::IndexMap;
fn main() {
let mut map = IndexMap::new();
map.insert("foo", 0);
*map.get_index_mut(0).unwrap().0 = "bar";
assert!(!map.contains_key("foo"));
assert!(!map.contains_key("bar"));
assert!(map.keys().collect::<Vec<_>>() == [&"bar"]);
}
This does not seem like it is the intended behavior, since e.g. first_mut
only gives a non-mutable reference to the key.
If this is the intended behavior, then there should probably be a warning in the documentation that you should not changing the key in ways which alter the Hash
or Eq
behavior.
Metadata
Metadata
Assignees
Labels
No labels