@@ -811,7 +811,7 @@ fn analyze_attr(attr: &Attribute, state: &mut AnalyzeAttrState) -> bool {
811811 should_encode
812812}
813813
814- fn should_encode_visibility ( def_kind : DefKind ) -> bool {
814+ fn should_encode_span ( def_kind : DefKind ) -> bool {
815815 match def_kind {
816816 DefKind :: Mod
817817 | DefKind :: Struct
@@ -823,25 +823,136 @@ fn should_encode_visibility(def_kind: DefKind) -> bool {
823823 | DefKind :: ForeignTy
824824 | DefKind :: TraitAlias
825825 | DefKind :: AssocTy
826+ | DefKind :: TyParam
826827 | DefKind :: Fn
827828 | DefKind :: Const
828- | DefKind :: Static ( .. )
829+ | DefKind :: Static ( _ )
829830 | DefKind :: Ctor ( ..)
830831 | DefKind :: AssocFn
831832 | DefKind :: AssocConst
832- | DefKind :: Macro ( ..)
833+ | DefKind :: Macro ( _)
834+ | DefKind :: AnonConst
835+ | DefKind :: InlineConst
836+ | DefKind :: OpaqueTy
837+ | DefKind :: Field
838+ | DefKind :: Impl { .. }
839+ | DefKind :: Closure
840+ | DefKind :: Generator => true ,
841+ DefKind :: ConstParam
842+ | DefKind :: ExternCrate
843+ | DefKind :: Use
844+ | DefKind :: ForeignMod
845+ | DefKind :: ImplTraitPlaceholder
846+ | DefKind :: LifetimeParam
847+ | DefKind :: GlobalAsm => false ,
848+ }
849+ }
850+
851+ fn should_encode_attrs ( def_kind : DefKind ) -> bool {
852+ match def_kind {
853+ DefKind :: Mod
854+ | DefKind :: Struct
855+ | DefKind :: Union
856+ | DefKind :: Enum
857+ | DefKind :: Variant
858+ | DefKind :: Trait
859+ | DefKind :: TyAlias
860+ | DefKind :: ForeignTy
861+ | DefKind :: TraitAlias
862+ | DefKind :: AssocTy
863+ | DefKind :: Fn
864+ | DefKind :: Const
865+ | DefKind :: Static ( _)
866+ | DefKind :: AssocFn
867+ | DefKind :: AssocConst
868+ | DefKind :: Macro ( _)
869+ | DefKind :: Field
870+ | DefKind :: Impl { .. } => true ,
871+ DefKind :: TyParam
872+ | DefKind :: ConstParam
873+ | DefKind :: Ctor ( ..)
874+ | DefKind :: ExternCrate
833875 | DefKind :: Use
834876 | DefKind :: ForeignMod
877+ | DefKind :: AnonConst
878+ | DefKind :: InlineConst
835879 | DefKind :: OpaqueTy
836880 | DefKind :: ImplTraitPlaceholder
837- | DefKind :: Impl { .. }
881+ | DefKind :: LifetimeParam
882+ | DefKind :: GlobalAsm
883+ | DefKind :: Closure
884+ | DefKind :: Generator => false ,
885+ }
886+ }
887+
888+ fn should_encode_expn_that_defined ( def_kind : DefKind ) -> bool {
889+ match def_kind {
890+ DefKind :: Mod
891+ | DefKind :: Struct
892+ | DefKind :: Union
893+ | DefKind :: Enum
894+ | DefKind :: Variant
895+ | DefKind :: Trait
896+ | DefKind :: Impl { .. } => true ,
897+ DefKind :: TyAlias
898+ | DefKind :: ForeignTy
899+ | DefKind :: TraitAlias
900+ | DefKind :: AssocTy
901+ | DefKind :: TyParam
902+ | DefKind :: Fn
903+ | DefKind :: Const
904+ | DefKind :: ConstParam
905+ | DefKind :: Static ( _)
906+ | DefKind :: Ctor ( ..)
907+ | DefKind :: AssocFn
908+ | DefKind :: AssocConst
909+ | DefKind :: Macro ( _)
910+ | DefKind :: ExternCrate
911+ | DefKind :: Use
912+ | DefKind :: ForeignMod
913+ | DefKind :: AnonConst
914+ | DefKind :: InlineConst
915+ | DefKind :: OpaqueTy
916+ | DefKind :: ImplTraitPlaceholder
917+ | DefKind :: Field
918+ | DefKind :: LifetimeParam
919+ | DefKind :: GlobalAsm
920+ | DefKind :: Closure
921+ | DefKind :: Generator => false ,
922+ }
923+ }
924+
925+ fn should_encode_visibility ( def_kind : DefKind ) -> bool {
926+ match def_kind {
927+ DefKind :: Mod
928+ | DefKind :: Struct
929+ | DefKind :: Union
930+ | DefKind :: Enum
931+ | DefKind :: Variant
932+ | DefKind :: Trait
933+ | DefKind :: TyAlias
934+ | DefKind :: ForeignTy
935+ | DefKind :: TraitAlias
936+ | DefKind :: AssocTy
937+ | DefKind :: Fn
938+ | DefKind :: Const
939+ | DefKind :: Static ( ..)
940+ | DefKind :: Ctor ( ..)
941+ | DefKind :: AssocFn
942+ | DefKind :: AssocConst
943+ | DefKind :: Macro ( ..)
838944 | DefKind :: Field => true ,
839- DefKind :: TyParam
945+ DefKind :: Use
946+ | DefKind :: ForeignMod
947+ | DefKind :: TyParam
840948 | DefKind :: ConstParam
841949 | DefKind :: LifetimeParam
842950 | DefKind :: AnonConst
843951 | DefKind :: InlineConst
952+ | DefKind :: OpaqueTy
953+ | DefKind :: ImplTraitPlaceholder
844954 | DefKind :: GlobalAsm
955+ | DefKind :: Impl { .. }
845956 | DefKind :: Closure
846957 | DefKind :: Generator
847958 | DefKind :: ExternCrate => false ,
@@ -1160,11 +1271,17 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
11601271 let def_kind = tcx. opt_def_kind ( local_id) ;
11611272 let Some ( def_kind) = def_kind else { continue } ;
11621273 self . tables . opt_def_kind . set_some ( def_id. index , def_kind) ;
1163- let def_span = tcx. def_span ( local_id) ;
1164- record ! ( self . tables. def_span[ def_id] <- def_span) ;
1165- self . encode_attrs ( local_id) ;
1166- record ! ( self . tables. expn_that_defined[ def_id] <- self . tcx. expn_that_defined( def_id) ) ;
1167- if let Some ( ident_span) = tcx. def_ident_span ( def_id) {
1274+ if should_encode_span ( def_kind) {
1275+ let def_span = tcx. def_span ( local_id) ;
1276+ record ! ( self . tables. def_span[ def_id] <- def_span) ;
1277+ }
1278+ if should_encode_attrs ( def_kind) {
1279+ self . encode_attrs ( local_id) ;
1280+ }
1281+ if should_encode_expn_that_defined ( def_kind) {
1282+ record ! ( self . tables. expn_that_defined[ def_id] <- self . tcx. expn_that_defined( def_id) ) ;
1283+ }
1284+ if should_encode_span ( def_kind) && let Some ( ident_span) = tcx. def_ident_span ( def_id) {
11681285 record ! ( self . tables. def_ident_span[ def_id] <- ident_span) ;
11691286 }
11701287 if def_kind. has_codegen_attrs ( ) {
@@ -1523,23 +1640,32 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
15231640 } )
15241641 }
15251642
1526- fn encode_info_for_item ( & mut self , def_id : DefId , item : & ' tcx hir:: Item < ' tcx > ) {
1643+ fn encode_info_for_item ( & mut self , item : & ' tcx hir:: Item < ' tcx > ) {
15271644 let tcx = self . tcx ;
1528-
1645+ let def_id = item . owner_id . to_def_id ( ) ;
15291646 debug ! ( "EncodeContext::encode_info_for_item({:?})" , def_id) ;
15301647
1648+ let record_associated_item_def_ids = |this : & mut Self , def_ids : & [ DefId ] | {
1649+ record_array ! ( this. tables. children[ def_id] <- def_ids. iter( ) . map( |& def_id| {
1650+ assert!( def_id. is_local( ) ) ;
1651+ def_id. index
1652+ } ) )
1653+ } ;
1654+
15311655 match item. kind {
15321656 hir:: ItemKind :: Fn ( ref sig, .., body) => {
15331657 self . tables . asyncness . set_some ( def_id. index , sig. header . asyncness ) ;
15341658 record_array ! ( self . tables. fn_arg_names[ def_id] <- self . tcx. hir( ) . body_param_names( body) ) ;
15351659 self . tables . constness . set_some ( def_id. index , sig. header . constness ) ;
1660+ record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1661+ self . tables . is_intrinsic . set ( def_id. index , tcx. is_intrinsic ( def_id) ) ;
15361662 }
15371663 hir:: ItemKind :: Macro ( ref macro_def, _) => {
15381664 self . tables . is_macro_rules . set ( def_id. index , macro_def. macro_rules ) ;
15391665 record ! ( self . tables. macro_definition[ def_id] <- & * macro_def. body) ;
15401666 }
15411667 hir:: ItemKind :: Mod ( ref m) => {
1542- return self . encode_info_for_mod ( item. owner_id . def_id , m) ;
1668+ self . encode_info_for_mod ( item. owner_id . def_id , m) ;
15431669 }
15441670 hir:: ItemKind :: OpaqueTy ( ref opaque) => {
15451671 self . encode_explicit_item_bounds ( def_id) ;
@@ -1550,9 +1676,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
15501676 hir:: ItemKind :: Impl ( hir:: Impl { defaultness, constness, .. } ) => {
15511677 self . tables . impl_defaultness . set_some ( def_id. index , * defaultness) ;
15521678 self . tables . constness . set_some ( def_id. index , * constness) ;
1679+ self . tables . impl_polarity . set_some ( def_id. index , self . tcx . impl_polarity ( def_id) ) ;
1680+
1681+ if let Some ( trait_ref) = self . tcx . impl_trait_ref ( def_id) {
1682+ record ! ( self . tables. impl_trait_ref[ def_id] <- trait_ref) ;
15531683
1554- let trait_ref = self . tcx . impl_trait_ref ( def_id) ;
1555- if let Some ( trait_ref) = trait_ref {
15561684 let trait_ref = trait_ref. skip_binder ( ) ;
15571685 let trait_def = self . tcx . trait_def ( trait_ref. def_id ) ;
15581686 if let Ok ( mut an) = trait_def. ancestors ( self . tcx , def_id) {
@@ -1570,71 +1698,34 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
15701698 }
15711699 }
15721700
1573- let polarity = self . tcx . impl_polarity ( def_id) ;
1574- self . tables . impl_polarity . set_some ( def_id. index , polarity) ;
1701+ let associated_item_def_ids = self . tcx . associated_item_def_ids ( def_id) ;
1702+ record_associated_item_def_ids ( self , associated_item_def_ids) ;
1703+ for & trait_item_def_id in associated_item_def_ids {
1704+ self . encode_info_for_impl_item ( trait_item_def_id) ;
1705+ }
15751706 }
15761707 hir:: ItemKind :: Trait ( ..) => {
1577- let trait_def = self . tcx . trait_def ( def_id) ;
1578- record ! ( self . tables. trait_def[ def_id] <- trait_def) ;
1708+ record ! ( self . tables. trait_def[ def_id] <- self . tcx. trait_def( def_id) ) ;
1709+
1710+ let associated_item_def_ids = self . tcx . associated_item_def_ids ( def_id) ;
1711+ record_associated_item_def_ids ( self , associated_item_def_ids) ;
1712+ for & item_def_id in associated_item_def_ids {
1713+ self . encode_info_for_trait_item ( item_def_id) ;
1714+ }
15791715 }
15801716 hir:: ItemKind :: TraitAlias ( ..) => {
1581- let trait_def = self . tcx . trait_def ( def_id) ;
1582- record ! ( self . tables. trait_def[ def_id] <- trait_def) ;
1583- }
1584- hir:: ItemKind :: ExternCrate ( _) | hir:: ItemKind :: Use ( ..) => {
1585- bug ! ( "cannot encode info for item {:?}" , item)
1717+ record ! ( self . tables. trait_def[ def_id] <- self . tcx. trait_def( def_id) ) ;
15861718 }
1587- hir:: ItemKind :: Static ( ..)
1719+ hir:: ItemKind :: ExternCrate ( _)
1720+ | hir:: ItemKind :: Use ( ..)
1721+ | hir:: ItemKind :: Static ( ..)
15881722 | hir:: ItemKind :: Const ( ..)
15891723 | hir:: ItemKind :: Enum ( ..)
15901724 | hir:: ItemKind :: Struct ( ..)
15911725 | hir:: ItemKind :: Union ( ..)
15921726 | hir:: ItemKind :: ForeignMod { .. }
15931727 | hir:: ItemKind :: GlobalAsm ( ..)
15941728 | hir:: ItemKind :: TyAlias ( ..) => { }
1595- } ;
1596- // FIXME(eddyb) there should be a nicer way to do this.
1597- match item. kind {
1598- hir:: ItemKind :: Impl { .. } | hir:: ItemKind :: Trait ( ..) => {
1599- let associated_item_def_ids = self . tcx . associated_item_def_ids ( def_id) ;
1600- record_array ! ( self . tables. children[ def_id] <-
1601- associated_item_def_ids. iter( ) . map( |& def_id| {
1602- assert!( def_id. is_local( ) ) ;
1603- def_id. index
1604- } )
1605- ) ;
1606- }
1607- _ => { }
1608- }
1609- if let hir:: ItemKind :: Fn ( ..) = item. kind {
1610- record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1611- self . tables . is_intrinsic . set ( def_id. index , tcx. is_intrinsic ( def_id) ) ;
1612- }
1613- if let hir:: ItemKind :: Impl { .. } = item. kind {
1614- if let Some ( trait_ref) = self . tcx . impl_trait_ref ( def_id) {
1615- record ! ( self . tables. impl_trait_ref[ def_id] <- trait_ref) ;
1616- }
1617- }
1618- // In some cases, along with the item itself, we also
1619- // encode some sub-items. Usually we want some info from the item
1620- // so it's easier to do that here then to wait until we would encounter
1621- // normally in the visitor walk.
1622- match item. kind {
1623- hir:: ItemKind :: Impl { .. } => {
1624- for & trait_item_def_id in
1625- self . tcx . associated_item_def_ids ( item. owner_id . to_def_id ( ) ) . iter ( )
1626- {
1627- self . encode_info_for_impl_item ( trait_item_def_id) ;
1628- }
1629- }
1630- hir:: ItemKind :: Trait ( ..) => {
1631- for & item_def_id in
1632- self . tcx . associated_item_def_ids ( item. owner_id . to_def_id ( ) ) . iter ( )
1633- {
1634- self . encode_info_for_trait_item ( item_def_id) ;
1635- }
1636- }
1637- _ => { }
16381729 }
16391730 }
16401731
@@ -2020,10 +2111,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EncodeContext<'a, 'tcx> {
20202111 }
20212112 fn visit_item ( & mut self , item : & ' tcx hir:: Item < ' tcx > ) {
20222113 intravisit:: walk_item ( self , item) ;
2023- match item. kind {
2024- hir:: ItemKind :: ExternCrate ( _) | hir:: ItemKind :: Use ( ..) => { } // ignore these
2025- _ => self . encode_info_for_item ( item. owner_id . to_def_id ( ) , item) ,
2026- }
2114+ self . encode_info_for_item ( item) ;
20272115 }
20282116 fn visit_foreign_item ( & mut self , ni : & ' tcx hir:: ForeignItem < ' tcx > ) {
20292117 intravisit:: walk_foreign_item ( self , ni) ;
0 commit comments