https://gcc.gnu.org/g:a65c3b497fd0ca28f35cb7e63f5a1ce95baff8ad
commit r16-228-ga65c3b497fd0ca28f35cb7e63f5a1ce95baff8ad Author: Pierre-Emmanuel Patry <pierre-emmanuel.pa...@embecosm.com> Date: Sun Apr 6 01:44:18 2025 +0200 gccrs: Add hash function for Identifiers gcc/rust/ChangeLog: * ast/rust-ast.h: Add hash function. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.pa...@embecosm.com> Diff: --- gcc/rust/ast/rust-ast.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 94585dc13442..aa6ad5066aa1 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -2102,6 +2102,19 @@ template <> struct less<Rust::Identifier> return lhs.as_string () < rhs.as_string (); } }; + +template <> struct hash<Rust::Identifier> +{ + std::size_t operator() (const Rust::Identifier &k) const + { + using std::hash; + using std::size_t; + using std::string; + + return hash<string> () (k.as_string ()) ^ (hash<int> () (k.get_locus ())); + } +}; + } // namespace std #endif