@@ -1354,9 +1354,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1354
1354
1355
1355
for local_id in tcx. iter_local_def_id ( ) {
1356
1356
let def_id = local_id. to_def_id ( ) ;
1357
- let def_kind = tcx. opt_def_kind ( local_id) ;
1358
- let Some ( def_kind) = def_kind else { continue } ;
1359
- self . tables . opt_def_kind . set_some ( def_id. index , def_kind) ;
1357
+ let def_kind = tcx. def_kind ( local_id) ;
1358
+ self . tables . def_kind . set_some ( def_id. index , def_kind) ;
1360
1359
if should_encode_span ( def_kind) {
1361
1360
let def_span = tcx. def_span ( local_id) ;
1362
1361
record ! ( self . tables. def_span[ def_id] <- def_span) ;
@@ -1393,7 +1392,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1393
1392
if should_encode_fn_sig ( def_kind) {
1394
1393
record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1395
1394
}
1396
- if should_encode_generics ( def_kind) {
1395
+ // FIXME: Some anonymous constants produced by `#[rustc_legacy_const_generics]`
1396
+ // do not have corresponding HIR nodes, so some queries usually making sense for
1397
+ // anonymous constants will not work on them and panic. It's not clear whether it
1398
+ // can cause any observable issues or not.
1399
+ let anon_const_without_hir = def_kind == DefKind :: AnonConst
1400
+ && tcx. hir ( ) . find ( tcx. local_def_id_to_hir_id ( local_id) ) . is_none ( ) ;
1401
+ if should_encode_generics ( def_kind) && !anon_const_without_hir {
1397
1402
let g = tcx. generics_of ( def_id) ;
1398
1403
record ! ( self . tables. generics_of[ def_id] <- g) ;
1399
1404
record ! ( self . tables. explicit_predicates_of[ def_id] <- self . tcx. explicit_predicates_of( def_id) ) ;
@@ -1407,7 +1412,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1407
1412
}
1408
1413
}
1409
1414
}
1410
- if should_encode_type ( tcx, local_id, def_kind) {
1415
+ if should_encode_type ( tcx, local_id, def_kind) && !anon_const_without_hir {
1411
1416
record ! ( self . tables. type_of[ def_id] <- self . tcx. type_of( def_id) ) ;
1412
1417
}
1413
1418
if should_encode_constness ( def_kind) {
@@ -1785,7 +1790,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1785
1790
self . tables . proc_macro_quoted_spans . set_some ( i, span) ;
1786
1791
}
1787
1792
1788
- self . tables . opt_def_kind . set_some ( LOCAL_CRATE . as_def_id ( ) . index , DefKind :: Mod ) ;
1793
+ self . tables . def_kind . set_some ( LOCAL_CRATE . as_def_id ( ) . index , DefKind :: Mod ) ;
1789
1794
record ! ( self . tables. def_span[ LOCAL_CRATE . as_def_id( ) ] <- tcx. def_span( LOCAL_CRATE . as_def_id( ) ) ) ;
1790
1795
self . encode_attrs ( LOCAL_CRATE . as_def_id ( ) . expect_local ( ) ) ;
1791
1796
let vis = tcx. local_visibility ( CRATE_DEF_ID ) . map_id ( |def_id| def_id. local_def_index ) ;
@@ -1833,7 +1838,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1833
1838
def_key. disambiguated_data . data = DefPathData :: MacroNs ( name) ;
1834
1839
1835
1840
let def_id = id. to_def_id ( ) ;
1836
- self . tables . opt_def_kind . set_some ( def_id. index , DefKind :: Macro ( macro_kind) ) ;
1841
+ self . tables . def_kind . set_some ( def_id. index , DefKind :: Macro ( macro_kind) ) ;
1837
1842
self . tables . proc_macro . set_some ( def_id. index , macro_kind) ;
1838
1843
self . encode_attrs ( id) ;
1839
1844
record ! ( self . tables. def_keys[ def_id] <- def_key) ;
0 commit comments