@@ -83,8 +83,9 @@ pub struct Definitions {
83
83
84
84
// FIXME(eddyb) don't go through `ast::NodeId` to convert between `HirId`
85
85
// and `LocalDefId` - ideally all `LocalDefId`s would be HIR owners.
86
+ def_id_to_hir_id : IndexVec < LocalDefId , Option < hir:: HirId > > ,
87
+
86
88
node_id_to_def_id : FxHashMap < ast:: NodeId , LocalDefId > ,
87
- def_id_to_node_id : IndexVec < LocalDefId , ast:: NodeId > ,
88
89
89
90
pub ( super ) node_id_to_hir_id : IndexVec < ast:: NodeId , Option < hir:: HirId > > ,
90
91
/// The reverse mapping of `node_id_to_hir_id`.
@@ -354,14 +355,12 @@ impl Definitions {
354
355
355
356
#[ inline]
356
357
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 ( )
359
359
}
360
360
361
361
#[ inline]
362
362
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]
365
364
}
366
365
367
366
#[ inline]
@@ -397,7 +396,7 @@ impl Definitions {
397
396
let root = LocalDefId { local_def_index : self . table . allocate ( key, def_path_hash) } ;
398
397
assert_eq ! ( root. local_def_index, CRATE_DEF_INDEX ) ;
399
398
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) ;
401
400
assert_eq ! ( self . def_id_to_span. push( rustc_span:: DUMMY_SP ) , root) ;
402
401
403
402
self . node_id_to_def_id . insert ( ast:: CRATE_NODE_ID , root) ;
@@ -452,7 +451,7 @@ impl Definitions {
452
451
// Create the definition.
453
452
let def_id = LocalDefId { local_def_index : self . table . allocate ( key, def_path_hash) } ;
454
453
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) ;
456
455
assert_eq ! ( self . def_id_to_span. push( span) , def_id) ;
457
456
458
457
// Some things for which we allocate `LocalDefId`s don't correspond to
@@ -482,6 +481,11 @@ impl Definitions {
482
481
) ;
483
482
self . node_id_to_hir_id = mapping;
484
483
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
+
485
489
// Build the reverse mapping of `node_id_to_hir_id`.
486
490
self . hir_id_to_node_id = self
487
491
. node_id_to_hir_id
0 commit comments