Skip to content

Should the std library implement Equiv for Str? #16738

Closed
@glennw

Description

@glennw

Anything that implements Str trait gets an implicit implementation of Equiv (see http://doc.rust-lang.org/std/cmp/trait.Equiv.html#tymethod.equiv).

In Servo, we have an Atom type that represents an interned string. For efficiency reasons, the hash value of the Atom is != the hash value of the string it represents.

If you then have a HashMap and call find_equiv(&str) it fails silently due to the hash mismatches.

Ideally we want this to be a compile error (you should always construct an Atom rather than use find_equiv).

However, due to the implicit trait implementation mentioned above, any type that implements Str also implements Equiv.

We have a workaround - we currently don't implement Str for Atom, and instead just implement as_slice() as a method on the Atom type.

Should we consider removing the implicit implementation of Equiv for anything that implements Str?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions