-
Notifications
You must be signed in to change notification settings - Fork 136
Description
As described in this issue, if the Clone implementation of a HashMap's key produces a key with a different hash, or if key.clone() == key does not hold, then this can result in a broken HashMap after map.clone(). These assumptions are not documented anywhere, which is why I made a pull request to update the Clone trait documentation.
In Verus, the requirement of key.clone() == key for the keys of a HashMap/HashSet is (as far as I can tell) also not documented anywhere. HashMap::clone is specified to return a map equal to the original one, which is not true if key.clone() != key. Due to this, it is possible to prove false facts about a cloned HashMap, as shown here in the playground.
To my understanding, simply updating the HashMap::clone specification would not be enough to fix this issue: A Clone implementation that does not respect key.clone() == key can break very basic invariants of a HashMap, like every key occurring at most once in the map, so that afterwards, the specification of, e.g., HashMap::remove does not hold anymore. So maybe the requirement that key.clone() == key should be part of obeys_key_model<Key>, or be modelled similarly?