Open
Description
The implementation of HashSet::get_or_insert_with
is not good. This method make it quite easy to break the invariant of set that all elements are repeated in set only once. Let's say this test passes:
#[test]
fn some_invalid_insert() {
let mut set = HashSet::new();
set.insert(1);
set.get_or_insert_with(&2, |_| 1);
set.get_or_insert_with(&3, |_| 1);
assert_eq!(vec![&1, &1, &1], set.iter().collect::<Vec<_>>());
}
May be we need document it?
Metadata
Metadata
Assignees
Labels
No labels