@@ -1383,6 +1383,21 @@ fn should_encode_const(def_kind: DefKind) -> bool {
13831383 }
13841384}
13851385
1386+ fn should_encode_const_of_item < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : DefId , def_kind : DefKind ) -> bool {
1387+ matches ! ( def_kind, DefKind :: Const | DefKind :: AssocConst )
1388+ && find_attr ! ( tcx. get_all_attrs( def_id) , AttributeKind :: TypeConst ( _) )
1389+ // AssocConst ==> assoc item has value
1390+ && ( !matches ! ( def_kind, DefKind :: AssocConst ) || assoc_item_has_value ( tcx, def_id) )
1391+ }
1392+
1393+ fn assoc_item_has_value < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : DefId ) -> bool {
1394+ let assoc_item = tcx. associated_item ( def_id) ;
1395+ match assoc_item. container {
1396+ ty:: AssocContainer :: InherentImpl | ty:: AssocContainer :: TraitImpl ( _) => true ,
1397+ ty:: AssocContainer :: Trait => assoc_item. defaultness ( tcx) . has_value ( ) ,
1398+ }
1399+ }
1400+
13861401impl < ' a , ' tcx > EncodeContext < ' a , ' tcx > {
13871402 fn encode_attrs ( & mut self , def_id : LocalDefId ) {
13881403 let tcx = self . tcx ;
@@ -1604,23 +1619,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16041619 if let DefKind :: AnonConst = def_kind {
16051620 record ! ( self . tables. anon_const_kind[ def_id] <- self . tcx. anon_const_kind( def_id) ) ;
16061621 }
1607- if let DefKind :: Const = def_kind
1608- && find_attr ! ( tcx. get_all_attrs( def_id) , AttributeKind :: TypeConst ( _) )
1609- {
1622+ if should_encode_const_of_item ( self . tcx , def_id, def_kind) {
16101623 record ! ( self . tables. const_of_item[ def_id] <- self . tcx. const_of_item( def_id) ) ;
16111624 }
1612- if let DefKind :: AssocConst = def_kind
1613- && find_attr ! ( tcx. get_all_attrs( def_id) , AttributeKind :: TypeConst ( _) )
1614- {
1615- let assoc_item = tcx. associated_item ( def_id) ;
1616- let should_encode = match assoc_item. container {
1617- ty:: AssocContainer :: InherentImpl | ty:: AssocContainer :: TraitImpl ( _) => true ,
1618- ty:: AssocContainer :: Trait => assoc_item. defaultness ( tcx) . has_value ( ) ,
1619- } ;
1620- if should_encode {
1621- record ! ( self . tables. const_of_item[ def_id] <- self . tcx. const_of_item( def_id) ) ;
1622- }
1623- }
16241625 if tcx. impl_method_has_trait_impl_trait_tys ( def_id)
16251626 && let Ok ( table) = self . tcx . collect_return_position_impl_trait_in_trait_tys ( def_id)
16261627 {
0 commit comments