Skip to content

libsyntax: Implementation of PartialEq on Ident is not well behaved #28658

Closed
@petrochenkov

Description

@petrochenkov

Spawned from #28642

There's no one true way to compare Idents. They can be compared non-hygienically (id1.name == id2.name), hygienically (mtwt::resolve(id1) == mtwt::resolve(id2)), or even member-wise (id1.name == id2.name && id1.ctxt== id2.ctxt) depending on the situation.
Currently PartialEq for Idents compares only names (non-hygienic comparison), but panics if the contexts are different. Hash for idents is not consistent with PartialEq and hashes both name and context of an Ident leading, it can lead to rare random panics if Idents are used as keys in HashMaps.
One solution is to remove implementations of PartialEq and Hash from Ident and use necessary versions of comparisons explicitly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-parserArea: The lexing & parsing of Rust source code to an AST

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions