@@ -53,7 +53,7 @@ pub struct Definitions {
5353 // We do only store the local hash, as all the definitions are from the current crate.
5454 def_path_hashes : IndexVec < LocalDefId , Hash64 > ,
5555 def_path_hash_to_index : DefPathHashMap ,
56- allow_overwrite : IndexSet < DefIndex > ,
56+ allow_overwrite : IndexSet < LocalDefId > ,
5757}
5858
5959/// A unique identifier that we can use to lookup a definition
@@ -304,27 +304,36 @@ impl Definitions {
304304 } ;
305305
306306 // Create the root definition.
307- let root = defs. allocate ( key, def_path_hash) ;
307+ let root = defs. allocate ( key, def_path_hash, false ) ;
308308 assert_eq ! ( root. local_def_index, CRATE_DEF_INDEX ) ;
309309
310310 defs
311311 }
312312
313- fn allocate ( & mut self , key : DefKey , def_path_hash : DefPathHash ) -> LocalDefId {
313+ fn allocate (
314+ & mut self ,
315+ key : DefKey ,
316+ def_path_hash : DefPathHash ,
317+ in_sandbox : bool ,
318+ ) -> LocalDefId {
314319 // Assert that all DefPathHashes correctly contain the local crate's StableCrateId.
315320 debug_assert_eq ! ( self . stable_crate_id, def_path_hash. stable_crate_id( ) ) ;
316321 let local_hash = def_path_hash. local_hash ( ) ;
317- let index = self . index_to_key . next_index ( ) ;
322+ let def_id = self . def_id_to_key . next_index ( ) ;
318323
319324 // Check for hash collisions of DefPathHashes. These should be
320325 // exceedingly rare.
321- if let Some ( existing) = self . def_path_hash_to_index . insert ( & local_hash, & index) {
326+ if let Some ( existing) =
327+ self . def_path_hash_to_index . insert ( & local_hash, & def_id. local_def_index )
328+ {
329+ let existing = LocalDefId { local_def_index : existing } ;
330+
322331 if !in_sandbox && self . allow_overwrite . swap_remove ( & existing) {
323- self . def_path_hash_to_index . insert ( & local_hash, & existing) ;
332+ self . def_path_hash_to_index . insert ( & local_hash, & existing. local_def_index ) ;
324333 return existing;
325334 } else {
326- let def_path1 = DefPath :: make ( LOCAL_CRATE , existing , |idx| self . def_key ( idx ) ) ;
327- let def_path2 = DefPath :: make ( LOCAL_CRATE , index , |idx| self . def_key ( idx ) ) ;
335+ let def_path1 = self . def_path ( existing ) ;
336+ let def_path2 = self . def_path ( def_id ) ;
328337
329338 // Continuing with colliding DefPathHashes can lead to correctness
330339 // issues. We must abort compilation.
@@ -340,14 +349,14 @@ impl Definitions {
340349 ) ;
341350 }
342351 } else {
343- self . index_to_key . push ( key) ;
344- debug ! ( "DefPathTable::insert () - {key:?} <-> {index :?}" ) ;
352+ self . def_id_to_key . push ( key) ;
353+ debug ! ( "def_id_to_key.push () - {key:?} <-> {:?}" , def_id . local_def_index ) ;
345354
346355 self . def_path_hashes . push ( local_hash) ;
347- debug_assert ! ( self . def_path_hashes. len( ) == self . index_to_key . len( ) ) ;
356+ debug_assert ! ( self . def_path_hashes. len( ) == self . def_id_to_key . len( ) ) ;
348357 }
349358
350- index
359+ def_id
351360 }
352361
353362 pub fn enumerated_keys_and_path_hashes (
@@ -404,14 +413,12 @@ impl Definitions {
404413
405414 debug ! ( "create_def: after disambiguation, key = {:?}" , key) ;
406415
407- let local_def_index = self . table . allocate ( key, def_path_hash, in_sandbox) ;
408-
416+ let def_id = self . allocate ( key, def_path_hash, in_sandbox) ;
409417 if in_sandbox {
410- assert_eq ! ( self . table . allow_overwrite. insert( local_def_index ) , true ) ;
418+ assert_eq ! ( self . allow_overwrite. insert( def_id ) , true ) ;
411419 }
412420
413- // Create the definition.
414- LocalDefId { local_def_index }
421+ def_id
415422 }
416423
417424 #[ inline( always) ]
0 commit comments