@@ -4,6 +4,7 @@ use crate::hir::{Owner, OwnerNodes};
4
4
use crate :: ty:: query:: Providers ;
5
5
use crate :: ty:: TyCtxt ;
6
6
use rustc_ast as ast;
7
+ use rustc_data_structures:: fx:: FxHashMap ;
7
8
use rustc_data_structures:: svh:: Svh ;
8
9
use rustc_hir:: def:: { DefKind , Res } ;
9
10
use 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 {
89
90
pub ( super ) struct HirOwnerData < ' hir > {
90
91
pub ( super ) signature : Option < & ' hir Owner < ' hir > > ,
91
92
pub ( super ) with_bodies : Option < & ' hir mut OwnerNodes < ' hir > > ,
93
+ pub ( super ) defs : Option < & ' hir mut FxHashMap < ItemLocalId , LocalDefId > > ,
92
94
}
93
95
94
96
pub struct IndexedHir < ' hir > {
@@ -170,17 +172,22 @@ impl<'hir> Map<'hir> {
170
172
171
173
#[ inline]
172
174
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
+ }
174
181
}
175
182
176
183
#[ inline]
177
184
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 ( )
179
186
}
180
187
181
188
#[ inline]
182
189
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)
184
191
}
185
192
186
193
pub fn def_kind ( & self , local_def_id : LocalDefId ) -> DefKind {
0 commit comments