@@ -4,6 +4,7 @@ use crate::hir::{Owner, OwnerNodes};
44use crate :: ty:: query:: Providers ;
55use crate :: ty:: TyCtxt ;
66use rustc_ast as ast;
7+ use rustc_data_structures:: fx:: FxHashMap ;
78use rustc_data_structures:: svh:: Svh ;
89use rustc_hir:: def:: { DefKind , Res } ;
910use rustc_hir:: def_id:: { CrateNum , DefId , LocalDefId , CRATE_DEF_INDEX , LOCAL_CRATE } ;
@@ -89,6 +90,7 @@ fn is_body_owner<'hir>(node: Node<'hir>, hir_id: HirId) -> bool {
8990pub ( super ) struct HirOwnerData < ' hir > {
9091 pub ( super ) signature : Option < & ' hir Owner < ' hir > > ,
9192 pub ( super ) with_bodies : Option < & ' hir mut OwnerNodes < ' hir > > ,
93+ pub ( super ) defs : Option < & ' hir mut FxHashMap < ItemLocalId , LocalDefId > > ,
9294}
9395
9496pub struct IndexedHir < ' hir > {
@@ -170,17 +172,22 @@ impl<'hir> Map<'hir> {
170172
171173 #[ inline]
172174 pub fn opt_local_def_id ( & self , hir_id : HirId ) -> Option < LocalDefId > {
173- self . tcx . definitions . opt_hir_id_to_local_def_id ( hir_id)
175+ if hir_id. local_id == ItemLocalId :: from_u32 ( 0 ) {
176+ // Every HirId owner has a DefId, so we can just return it directly here
177+ Some ( hir_id. owner )
178+ } else {
179+ self . tcx . hir_owner_defs ( hir_id. owner ) . and_then ( |map| map. get ( & hir_id. local_id ) . copied ( ) )
180+ }
174181 }
175182
176183 #[ inline]
177184 pub fn local_def_id_to_hir_id ( & self , def_id : LocalDefId ) -> HirId {
178- self . tcx . definitions . local_def_id_to_hir_id ( def_id)
185+ self . tcx . local_def_id_to_hir_id ( def_id) . unwrap ( )
179186 }
180187
181188 #[ inline]
182189 pub fn opt_local_def_id_to_hir_id ( & self , def_id : LocalDefId ) -> Option < HirId > {
183- self . tcx . definitions . opt_local_def_id_to_hir_id ( def_id)
190+ self . tcx . local_def_id_to_hir_id ( def_id)
184191 }
185192
186193 pub fn def_kind ( & self , local_def_id : LocalDefId ) -> DefKind {
0 commit comments