diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2023-12-24 01:04:16 +0000 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2025-06-22 20:25:55 +0000 |
| commit | 89e5db8fea71e1055437454285d1c128576ec9b9 (patch) | |
| tree | eecd5df462a0bb0460e41ce60c8b64c76d942b2a /compiler/rustc_hir/src/definitions.rs | |
| parent | 8051f012658fde822bfc661b52e90950b411e5c9 (diff) | |
| download | rust-89e5db8fea71e1055437454285d1c128576ec9b9.tar.gz rust-89e5db8fea71e1055437454285d1c128576ec9b9.zip | |
Only inherit local hash for paths.
Diffstat (limited to 'compiler/rustc_hir/src/definitions.rs')
| -rw-r--r-- | compiler/rustc_hir/src/definitions.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/compiler/rustc_hir/src/definitions.rs b/compiler/rustc_hir/src/definitions.rs index f93b9e5af53..d9fea542100 100644 --- a/compiler/rustc_hir/src/definitions.rs +++ b/compiler/rustc_hir/src/definitions.rs @@ -140,7 +140,9 @@ impl DefKey { pub(crate) fn compute_stable_hash(&self, parent: DefPathHash) -> DefPathHash { let mut hasher = StableHasher::new(); - parent.hash(&mut hasher); + // The new path is in the same crate as `parent`, and will contain the stable_crate_id. + // Therefore, we only need to include information of the parent's local hash. + parent.local_hash().hash(&mut hasher); let DisambiguatedDefPathData { ref data, disambiguator } = self.disambiguated_data; @@ -361,8 +363,16 @@ impl Definitions { }, }; - let parent_hash = DefPathHash::new(stable_crate_id, Hash64::ZERO); - let def_path_hash = key.compute_stable_hash(parent_hash); + // We want *both* halves of a DefPathHash to depend on the crate-id of the defining crate. + // The crate-id can be more easily changed than the DefPath of an item, so, in the case of + // a crate-local DefPathHash collision, the user can simply "roll the dice again" for all + // DefPathHashes in the crate by changing the crate disambiguator (e.g. via bumping the + // crate's version number). + // + // Children paths will only hash the local portion, and still inherit the change to the + // root hash. + let def_path_hash = + DefPathHash::new(stable_crate_id, Hash64::new(stable_crate_id.as_u64())); // Create the root definition. let mut table = DefPathTable::new(stable_crate_id); |
