@@ -1068,6 +1068,41 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) ->
10681068 }
10691069}
10701070
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+
10711106impl < ' a , ' tcx > EncodeContext < ' a , ' tcx > {
10721107 fn encode_attrs ( & mut self , def_id : LocalDefId ) {
10731108 let mut attrs = self
@@ -1093,7 +1128,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
10931128 let def_kind = tcx. opt_def_kind ( local_id) ;
10941129 let Some ( def_kind) = def_kind else { continue } ;
10951130 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) ;
10971133 self . encode_attrs ( local_id) ;
10981134 record ! ( self . tables. expn_that_defined[ def_id] <- self . tcx. expn_that_defined( def_id) ) ;
10991135 if let Some ( ident_span) = tcx. def_ident_span ( def_id) {
@@ -1127,6 +1163,15 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
11271163 if should_encode_type ( tcx, local_id, def_kind) {
11281164 record ! ( self . tables. type_of[ def_id] <- self . tcx. type_of( def_id) ) ;
11291165 }
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+ }
11301175 if let DefKind :: TyParam | DefKind :: ConstParam = def_kind {
11311176 if let Some ( default) = self . tcx . object_lifetime_default ( def_id) {
11321177 record ! ( self . tables. object_lifetime_default[ def_id] <- default ) ;
@@ -1296,14 +1341,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
12961341
12971342 match trait_item. kind {
12981343 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) ) ;
13071346 }
13081347 ty:: AssocKind :: Fn => {
13091348 let hir:: TraitItemKind :: Fn ( m_sig, m) = & ast_item. kind else { bug ! ( ) } ;
@@ -1342,16 +1381,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13421381
13431382 match impl_item. kind {
13441383 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) ) ;
13551386 }
13561387 ty:: AssocKind :: Fn => {
13571388 let hir:: ImplItemKind :: Fn ( ref sig, body) = ast_item. kind else { bug ! ( ) } ;
@@ -1487,13 +1518,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14871518
14881519 let entry_kind = match item. kind {
14891520 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 ,
14971522 hir:: ItemKind :: Fn ( ref sig, .., body) => {
14981523 self . tables . asyncness . set ( def_id. index , sig. header . asyncness ) ;
14991524 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> {
16621687 fn encode_info_for_anon_const ( & mut self , id : hir:: HirId ) {
16631688 let def_id = self . tcx . hir ( ) . local_def_id ( id) ;
16641689 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-
16691690 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) ;
16721691 }
16731692
16741693 fn encode_native_libraries ( & mut self ) -> LazyArray < NativeLib > {
0 commit comments