Skip to content

Clarify behavior of HashSet::insert when there's existing key #107581

Closed
@stepancheg

Description

@stepancheg

Location

https://doc.rust-lang.org/std/collections/struct.HashSet.html#method.insert

Summary

HashSet::insert is underspecified.

It says:

If the set already contained this value, false is returned.

But when the set already contains a value, is existing value replaced with new, or new value just discarded?

It does not make difference for primitive types, but can have significant effect when inserting Arc for example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions