@@ -8,7 +8,7 @@ use rustc_data_structures::svh::Svh;
8
8
use rustc_data_structures:: sync:: { par_for_each_in, Send , Sync } ;
9
9
use rustc_hir:: def:: { DefKind , Res } ;
10
10
use rustc_hir:: def_id:: { DefId , LocalDefId , CRATE_DEF_ID , LOCAL_CRATE } ;
11
- use rustc_hir:: definitions:: { DefKey , DefPath , DefPathHash } ;
11
+ use rustc_hir:: definitions:: { DefKey , DefPath , DefPathData , DefPathHash } ;
12
12
use rustc_hir:: intravisit:: { self , Visitor } ;
13
13
use rustc_hir:: * ;
14
14
use rustc_index:: vec:: Idx ;
@@ -180,7 +180,19 @@ impl<'hir> Map<'hir> {
180
180
/// Do not call this function directly. The query should be called.
181
181
pub ( super ) fn opt_def_kind ( self , local_def_id : LocalDefId ) -> Option < DefKind > {
182
182
let hir_id = self . local_def_id_to_hir_id ( local_def_id) ;
183
- let def_kind = match self . find ( hir_id) ? {
183
+ let node = match self . find ( hir_id) {
184
+ Some ( node) => node,
185
+ None => match self . def_key ( local_def_id) . disambiguated_data . data {
186
+ // FIXME: Some anonymous constants do not have corresponding HIR nodes,
187
+ // so many local queries will panic on their def ids. `None` is currently
188
+ // returned here instead of `DefKind::{Anon,Inline}Const` to avoid such panics.
189
+ // Ideally all def ids should have `DefKind`s, we need to create the missing
190
+ // HIR nodes or feed relevant query results to achieve that.
191
+ DefPathData :: AnonConst => return None ,
192
+ _ => bug ! ( "no HIR node for def id {local_def_id:?}" ) ,
193
+ } ,
194
+ } ;
195
+ let def_kind = match node {
184
196
Node :: Item ( item) => match item. kind {
185
197
ItemKind :: Static ( _, mt, _) => DefKind :: Static ( mt) ,
186
198
ItemKind :: Const ( ..) => DefKind :: Const ,
@@ -267,7 +279,10 @@ impl<'hir> Map<'hir> {
267
279
| Node :: Param ( _)
268
280
| Node :: Arm ( _)
269
281
| Node :: Lifetime ( _)
270
- | Node :: Block ( _) => return None ,
282
+ | Node :: Block ( _) => span_bug ! (
283
+ self . span( hir_id) ,
284
+ "unexpected node with def id {local_def_id:?}: {node:?}"
285
+ ) ,
271
286
} ;
272
287
Some ( def_kind)
273
288
}
0 commit comments