@@ -83,8 +83,9 @@ pub struct Definitions {
8383
8484 // FIXME(eddyb) don't go through `ast::NodeId` to convert between `HirId`
8585 // and `LocalDefId` - ideally all `LocalDefId`s would be HIR owners.
86+ def_id_to_hir_id : IndexVec < LocalDefId , Option < hir:: HirId > > ,
87+
8688 node_id_to_def_id : FxHashMap < ast:: NodeId , LocalDefId > ,
87- def_id_to_node_id : IndexVec < LocalDefId , ast:: NodeId > ,
8889
8990 pub ( super ) node_id_to_hir_id : IndexVec < ast:: NodeId , Option < hir:: HirId > > ,
9091 /// The reverse mapping of `node_id_to_hir_id`.
@@ -354,14 +355,12 @@ impl Definitions {
354355
355356 #[ inline]
356357 pub fn local_def_id_to_hir_id ( & self , id : LocalDefId ) -> hir:: HirId {
357- let node_id = self . def_id_to_node_id [ id] ;
358- self . node_id_to_hir_id [ node_id] . unwrap ( )
358+ self . def_id_to_hir_id [ id] . unwrap ( )
359359 }
360360
361361 #[ inline]
362362 pub fn opt_local_def_id_to_hir_id ( & self , id : LocalDefId ) -> Option < hir:: HirId > {
363- let node_id = self . def_id_to_node_id [ id] ;
364- self . node_id_to_hir_id [ node_id]
363+ self . def_id_to_hir_id [ id]
365364 }
366365
367366 #[ inline]
@@ -397,7 +396,7 @@ impl Definitions {
397396 let root = LocalDefId { local_def_index : self . table . allocate ( key, def_path_hash) } ;
398397 assert_eq ! ( root. local_def_index, CRATE_DEF_INDEX ) ;
399398
400- assert_eq ! ( self . def_id_to_node_id . push( ast :: CRATE_NODE_ID ) , root) ;
399+ assert_eq ! ( self . def_id_to_hir_id . push( None ) , root) ;
401400 assert_eq ! ( self . def_id_to_span. push( rustc_span:: DUMMY_SP ) , root) ;
402401
403402 self . node_id_to_def_id . insert ( ast:: CRATE_NODE_ID , root) ;
@@ -452,7 +451,7 @@ impl Definitions {
452451 // Create the definition.
453452 let def_id = LocalDefId { local_def_index : self . table . allocate ( key, def_path_hash) } ;
454453
455- assert_eq ! ( self . def_id_to_node_id . push( node_id ) , def_id) ;
454+ assert_eq ! ( self . def_id_to_hir_id . push( None ) , def_id) ;
456455 assert_eq ! ( self . def_id_to_span. push( span) , def_id) ;
457456
458457 // Some things for which we allocate `LocalDefId`s don't correspond to
@@ -482,6 +481,11 @@ impl Definitions {
482481 ) ;
483482 self . node_id_to_hir_id = mapping;
484483
484+ for ( & node_id, & def_id) in self . node_id_to_def_id . iter ( ) {
485+ self . def_id_to_hir_id [ def_id] =
486+ self . node_id_to_hir_id . get ( node_id) . copied ( ) . unwrap_or ( None ) ;
487+ }
488+
485489 // Build the reverse mapping of `node_id_to_hir_id`.
486490 self . hir_id_to_node_id = self
487491 . node_id_to_hir_id
0 commit comments