@@ -1068,6 +1068,41 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) ->
1068
1068
}
1069
1069
}
1070
1070
1071
+ fn should_encode_const ( def_kind : DefKind ) -> bool {
1072
+ match def_kind {
1073
+ DefKind :: Const | DefKind :: AssocConst | DefKind :: AnonConst => true ,
1074
+
1075
+ DefKind :: Struct
1076
+ | DefKind :: Union
1077
+ | DefKind :: Enum
1078
+ | DefKind :: Variant
1079
+ | DefKind :: Ctor ( ..)
1080
+ | DefKind :: Field
1081
+ | DefKind :: Fn
1082
+ | DefKind :: Static ( ..)
1083
+ | DefKind :: TyAlias
1084
+ | DefKind :: OpaqueTy
1085
+ | DefKind :: ForeignTy
1086
+ | DefKind :: Impl
1087
+ | DefKind :: AssocFn
1088
+ | DefKind :: Closure
1089
+ | DefKind :: Generator
1090
+ | DefKind :: ConstParam
1091
+ | DefKind :: InlineConst
1092
+ | DefKind :: AssocTy
1093
+ | DefKind :: TyParam
1094
+ | DefKind :: Trait
1095
+ | DefKind :: TraitAlias
1096
+ | DefKind :: Mod
1097
+ | DefKind :: ForeignMod
1098
+ | DefKind :: Macro ( ..)
1099
+ | DefKind :: Use
1100
+ | DefKind :: LifetimeParam
1101
+ | DefKind :: GlobalAsm
1102
+ | DefKind :: ExternCrate => false ,
1103
+ }
1104
+ }
1105
+
1071
1106
impl < ' a , ' tcx > EncodeContext < ' a , ' tcx > {
1072
1107
fn encode_attrs ( & mut self , def_id : LocalDefId ) {
1073
1108
let mut attrs = self
@@ -1093,7 +1128,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1093
1128
let def_kind = tcx. opt_def_kind ( local_id) ;
1094
1129
let Some ( def_kind) = def_kind else { continue } ;
1095
1130
self . tables . opt_def_kind . set ( def_id. index , def_kind) ;
1096
- record ! ( self . tables. def_span[ def_id] <- tcx. def_span( def_id) ) ;
1131
+ let def_span = tcx. def_span ( local_id) ;
1132
+ record ! ( self . tables. def_span[ def_id] <- def_span) ;
1097
1133
self . encode_attrs ( local_id) ;
1098
1134
record ! ( self . tables. expn_that_defined[ def_id] <- self . tcx. expn_that_defined( def_id) ) ;
1099
1135
if let Some ( ident_span) = tcx. def_ident_span ( def_id) {
@@ -1127,6 +1163,15 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1127
1163
if should_encode_type ( tcx, local_id, def_kind) {
1128
1164
record ! ( self . tables. type_of[ def_id] <- self . tcx. type_of( def_id) ) ;
1129
1165
}
1166
+ if should_encode_const ( def_kind) && tcx. is_mir_available ( def_id) {
1167
+ let qualifs = tcx. at ( def_span) . mir_const_qualif ( def_id) ;
1168
+ record ! ( self . tables. mir_const_qualif[ def_id] <- qualifs) ;
1169
+ let body_id = tcx. hir ( ) . maybe_body_owned_by ( local_id) ;
1170
+ if let Some ( body_id) = body_id {
1171
+ let const_data = self . encode_rendered_const_for_body ( body_id) ;
1172
+ record ! ( self . tables. rendered_const[ def_id] <- const_data) ;
1173
+ }
1174
+ }
1130
1175
if let DefKind :: TyParam | DefKind :: ConstParam = def_kind {
1131
1176
if let Some ( default) = self . tcx . object_lifetime_default ( def_id) {
1132
1177
record ! ( self . tables. object_lifetime_default[ def_id] <- default ) ;
@@ -1296,14 +1341,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1296
1341
1297
1342
match trait_item. kind {
1298
1343
ty:: AssocKind :: Const => {
1299
- let rendered = rustc_hir_pretty:: to_string (
1300
- & ( & self . tcx . hir ( ) as & dyn intravisit:: Map < ' _ > ) ,
1301
- |s| s. print_trait_item ( ast_item) ,
1302
- ) ;
1303
-
1304
- record ! ( self . tables. kind[ def_id] <- EntryKind :: AssocConst ( ty:: AssocItemContainer :: TraitContainer ) ) ;
1305
- record ! ( self . tables. mir_const_qualif[ def_id] <- mir:: ConstQualifs :: default ( ) ) ;
1306
- record ! ( self . tables. rendered_const[ def_id] <- rendered) ;
1344
+ let container = trait_item. container ;
1345
+ record ! ( self . tables. kind[ def_id] <- EntryKind :: AssocConst ( container) ) ;
1307
1346
}
1308
1347
ty:: AssocKind :: Fn => {
1309
1348
let hir:: TraitItemKind :: Fn ( m_sig, m) = & ast_item. kind else { bug ! ( ) } ;
@@ -1342,16 +1381,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1342
1381
1343
1382
match impl_item. kind {
1344
1383
ty:: AssocKind :: Const => {
1345
- if let hir:: ImplItemKind :: Const ( _, body_id) = ast_item. kind {
1346
- let qualifs = self . tcx . at ( ast_item. span ) . mir_const_qualif ( def_id) ;
1347
- let const_data = self . encode_rendered_const_for_body ( body_id) ;
1348
-
1349
- record ! ( self . tables. kind[ def_id] <- EntryKind :: AssocConst ( ty:: AssocItemContainer :: ImplContainer ) ) ;
1350
- record ! ( self . tables. mir_const_qualif[ def_id] <- qualifs) ;
1351
- record ! ( self . tables. rendered_const[ def_id] <- const_data) ;
1352
- } else {
1353
- bug ! ( )
1354
- }
1384
+ let container = impl_item. container ;
1385
+ record ! ( self . tables. kind[ def_id] <- EntryKind :: AssocConst ( container) ) ;
1355
1386
}
1356
1387
ty:: AssocKind :: Fn => {
1357
1388
let hir:: ImplItemKind :: Fn ( ref sig, body) = ast_item. kind else { bug ! ( ) } ;
@@ -1487,13 +1518,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1487
1518
1488
1519
let entry_kind = match item. kind {
1489
1520
hir:: ItemKind :: Static ( ..) => EntryKind :: Static ,
1490
- hir:: ItemKind :: Const ( _, body_id) => {
1491
- let qualifs = self . tcx . at ( item. span ) . mir_const_qualif ( def_id) ;
1492
- let const_data = self . encode_rendered_const_for_body ( body_id) ;
1493
- record ! ( self . tables. mir_const_qualif[ def_id] <- qualifs) ;
1494
- record ! ( self . tables. rendered_const[ def_id] <- const_data) ;
1495
- EntryKind :: Const
1496
- }
1521
+ hir:: ItemKind :: Const ( ..) => EntryKind :: Const ,
1497
1522
hir:: ItemKind :: Fn ( ref sig, .., body) => {
1498
1523
self . tables . asyncness . set ( def_id. index , sig. header . asyncness ) ;
1499
1524
record_array ! ( self . tables. fn_arg_names[ def_id] <- self . tcx. hir( ) . body_param_names( body) ) ;
@@ -1662,13 +1687,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1662
1687
fn encode_info_for_anon_const ( & mut self , id : hir:: HirId ) {
1663
1688
let def_id = self . tcx . hir ( ) . local_def_id ( id) ;
1664
1689
debug ! ( "EncodeContext::encode_info_for_anon_const({:?})" , def_id) ;
1665
- let body_id = self . tcx . hir ( ) . body_owned_by ( def_id) ;
1666
- let const_data = self . encode_rendered_const_for_body ( body_id) ;
1667
- let qualifs = self . tcx . mir_const_qualif ( def_id) ;
1668
-
1669
1690
record ! ( self . tables. kind[ def_id. to_def_id( ) ] <- EntryKind :: AnonConst ) ;
1670
- record ! ( self . tables. mir_const_qualif[ def_id. to_def_id( ) ] <- qualifs) ;
1671
- record ! ( self . tables. rendered_const[ def_id. to_def_id( ) ] <- const_data) ;
1672
1691
}
1673
1692
1674
1693
fn encode_native_libraries ( & mut self ) -> LazyArray < NativeLib > {
0 commit comments