Split get_opt_name hashing use into hashed_symbol

This commit is contained in:
John Kåre Alsaker
2025-05-02 13:40:49 +02:00
parent d16daf5cba
commit 4869e20e26
2 changed files with 21 additions and 5 deletions

View File

@@ -145,7 +145,7 @@ impl DefKey {
let DisambiguatedDefPathData { ref data, disambiguator } = self.disambiguated_data;
std::mem::discriminant(data).hash(&mut hasher);
if let Some(name) = data.get_opt_name() {
if let Some(name) = data.hashed_symbol() {
// Get a stable hash by considering the symbol chars rather than
// the symbol index.
name.as_str().hash(&mut hasher);
@@ -443,6 +443,26 @@ pub enum DefPathDataName {
impl DefPathData {
pub fn get_opt_name(&self) -> Option<Symbol> {
use self::DefPathData::*;
match *self {
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),
Impl
| ForeignMod
| CrateRoot
| Use
| GlobalAsm
| Closure
| Ctor
| AnonConst
| OpaqueTy
| AnonAssocTy(..)
| SyntheticCoroutineBody
| NestedStatic => None,
}
}
fn hashed_symbol(&self) -> Option<Symbol> {
use self::DefPathData::*;
match *self {
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) | AnonAssocTy(name) => {