-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Document replacement behavior of map and set insertion methods #26888
Comments
This is... unexpected. |
/cc @rust-lang/libs @gankro is this behavior intentional and should it be documented? |
It's intentional. The justification being "our API says you're not allowed to care about keys, and swapping keys is more expensive, so do the less expensive thing". It's not necessarily the right choice, but at very least it's not an accident. It's unclear if anyone is relying on this (we settled on a uniform behaviour in case anyone did). |
I think we should document that they don't replace the key. rust-lang/rfcs#1194 provides an additional |
{BTree,Hash}{Map,Set} will not update their key if it already exists, which can matter with more complex keys. This behavior is now documented. Fixes rust-lang#26888
{BTree,Hash}{Map,Set} will not update their key if it already exists, which can matter with more complex keys. This behavior is now documented. Fixes rust-lang#26888
{BTree,Hash}{Map,Set} will not update their key if it already exists, which can matter with more complex keys. This behavior is now documented. Fixes #26888
The behavior of the following methods is undocumented when the key/item being inserted is equivalent to one already in the collection:
BTreeMap::insert
BTreeSet::insert
HashMap::insert
HashSet::insert
The following program demonstrates that the maps and sets do not replace their keys/items in this scenario:
Output:
The text was updated successfully, but these errors were encountered: