@@ -87,8 +87,8 @@ pub struct Definitions {
87
87
def_id_to_node_id : IndexVec < LocalDefId , ast:: NodeId > ,
88
88
89
89
pub ( super ) node_id_to_hir_id : IndexVec < ast:: NodeId , Option < hir:: HirId > > ,
90
- /// The pre-computed mapping of `hir_id_to_node_id` -> `node_id_to_def_id `.
91
- pub ( super ) hir_id_to_def_id : FxHashMap < hir:: HirId , LocalDefId > ,
90
+ /// The reverse mapping of `node_id_to_hir_id `.
91
+ pub ( super ) hir_id_to_node_id : FxHashMap < hir:: HirId , ast :: NodeId > ,
92
92
93
93
/// If `ExpnId` is an ID of some macro expansion,
94
94
/// then `DefId` is the normal module (`mod`) in which the expanded macro was defined.
@@ -351,7 +351,8 @@ impl Definitions {
351
351
352
352
#[ inline]
353
353
pub fn opt_hir_id_to_local_def_id ( & self , hir_id : hir:: HirId ) -> Option < LocalDefId > {
354
- self . hir_id_to_def_id . get ( & hir_id) . copied ( )
354
+ let node_id = self . hir_id_to_node_id [ & hir_id] ;
355
+ self . opt_local_def_id ( node_id)
355
356
}
356
357
357
358
/// Retrieves the span of the given `DefId` if `DefId` is in the local crate.
@@ -466,15 +467,11 @@ impl Definitions {
466
467
) ;
467
468
self . node_id_to_hir_id = mapping;
468
469
469
- // Build the pre-computed mapping of `hir_id_to_node_id` -> `node_id_to_def_id `.
470
- self . hir_id_to_def_id = self
470
+ // Build the reverse mapping of `node_id_to_hir_id `.
471
+ self . hir_id_to_node_id = self
471
472
. node_id_to_hir_id
472
473
. iter_enumerated ( )
473
- . filter_map ( |( node_id, & hir_id) | {
474
- hir_id. and_then ( |hir_id| {
475
- self . node_id_to_def_id . get ( & node_id) . map ( |& def_id| ( hir_id, def_id) )
476
- } )
477
- } )
474
+ . filter_map ( |( node_id, & hir_id) | hir_id. map ( |hir_id| ( hir_id, node_id) ) )
478
475
. collect ( ) ;
479
476
}
480
477
0 commit comments