@@ -811,7 +811,7 @@ fn analyze_attr(attr: &Attribute, state: &mut AnalyzeAttrState) -> bool {
811
811
should_encode
812
812
}
813
813
814
- fn should_encode_visibility ( def_kind : DefKind ) -> bool {
814
+ fn should_encode_span ( def_kind : DefKind ) -> bool {
815
815
match def_kind {
816
816
DefKind :: Mod
817
817
| DefKind :: Struct
@@ -823,25 +823,136 @@ fn should_encode_visibility(def_kind: DefKind) -> bool {
823
823
| DefKind :: ForeignTy
824
824
| DefKind :: TraitAlias
825
825
| DefKind :: AssocTy
826
+ | DefKind :: TyParam
826
827
| DefKind :: Fn
827
828
| DefKind :: Const
828
- | DefKind :: Static ( .. )
829
+ | DefKind :: Static ( _ )
829
830
| DefKind :: Ctor ( ..)
830
831
| DefKind :: AssocFn
831
832
| 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
833
875
| DefKind :: Use
834
876
| DefKind :: ForeignMod
877
+ | DefKind :: AnonConst
878
+ | DefKind :: InlineConst
835
879
| DefKind :: OpaqueTy
836
880
| 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 ( ..)
838
944
| DefKind :: Field => true ,
839
- DefKind :: TyParam
945
+ DefKind :: Use
946
+ | DefKind :: ForeignMod
947
+ | DefKind :: TyParam
840
948
| DefKind :: ConstParam
841
949
| DefKind :: LifetimeParam
842
950
| DefKind :: AnonConst
843
951
| DefKind :: InlineConst
952
+ | DefKind :: OpaqueTy
953
+ | DefKind :: ImplTraitPlaceholder
844
954
| DefKind :: GlobalAsm
955
+ | DefKind :: Impl { .. }
845
956
| DefKind :: Closure
846
957
| DefKind :: Generator
847
958
| DefKind :: ExternCrate => false ,
@@ -1160,11 +1271,17 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1160
1271
let def_kind = tcx. opt_def_kind ( local_id) ;
1161
1272
let Some ( def_kind) = def_kind else { continue } ;
1162
1273
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) {
1168
1285
record ! ( self . tables. def_ident_span[ def_id] <- ident_span) ;
1169
1286
}
1170
1287
if def_kind. has_codegen_attrs ( ) {
@@ -1523,23 +1640,32 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1523
1640
} )
1524
1641
}
1525
1642
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 > ) {
1527
1644
let tcx = self . tcx ;
1528
-
1645
+ let def_id = item . owner_id . to_def_id ( ) ;
1529
1646
debug ! ( "EncodeContext::encode_info_for_item({:?})" , def_id) ;
1530
1647
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
+
1531
1655
match item. kind {
1532
1656
hir:: ItemKind :: Fn ( ref sig, .., body) => {
1533
1657
self . tables . asyncness . set_some ( def_id. index , sig. header . asyncness ) ;
1534
1658
record_array ! ( self . tables. fn_arg_names[ def_id] <- self . tcx. hir( ) . body_param_names( body) ) ;
1535
1659
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) ) ;
1536
1662
}
1537
1663
hir:: ItemKind :: Macro ( ref macro_def, _) => {
1538
1664
self . tables . is_macro_rules . set ( def_id. index , macro_def. macro_rules ) ;
1539
1665
record ! ( self . tables. macro_definition[ def_id] <- & * macro_def. body) ;
1540
1666
}
1541
1667
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) ;
1543
1669
}
1544
1670
hir:: ItemKind :: OpaqueTy ( ref opaque) => {
1545
1671
self . encode_explicit_item_bounds ( def_id) ;
@@ -1550,9 +1676,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1550
1676
hir:: ItemKind :: Impl ( hir:: Impl { defaultness, constness, .. } ) => {
1551
1677
self . tables . impl_defaultness . set_some ( def_id. index , * defaultness) ;
1552
1678
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) ;
1553
1683
1554
- let trait_ref = self . tcx . impl_trait_ref ( def_id) ;
1555
- if let Some ( trait_ref) = trait_ref {
1556
1684
let trait_ref = trait_ref. skip_binder ( ) ;
1557
1685
let trait_def = self . tcx . trait_def ( trait_ref. def_id ) ;
1558
1686
if let Ok ( mut an) = trait_def. ancestors ( self . tcx , def_id) {
@@ -1570,71 +1698,34 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1570
1698
}
1571
1699
}
1572
1700
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
+ }
1575
1706
}
1576
1707
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
+ }
1579
1715
}
1580
1716
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) ) ;
1586
1718
}
1587
- hir:: ItemKind :: Static ( ..)
1719
+ hir:: ItemKind :: ExternCrate ( _)
1720
+ | hir:: ItemKind :: Use ( ..)
1721
+ | hir:: ItemKind :: Static ( ..)
1588
1722
| hir:: ItemKind :: Const ( ..)
1589
1723
| hir:: ItemKind :: Enum ( ..)
1590
1724
| hir:: ItemKind :: Struct ( ..)
1591
1725
| hir:: ItemKind :: Union ( ..)
1592
1726
| hir:: ItemKind :: ForeignMod { .. }
1593
1727
| hir:: ItemKind :: GlobalAsm ( ..)
1594
1728
| 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
- _ => { }
1638
1729
}
1639
1730
}
1640
1731
@@ -2020,10 +2111,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EncodeContext<'a, 'tcx> {
2020
2111
}
2021
2112
fn visit_item ( & mut self , item : & ' tcx hir:: Item < ' tcx > ) {
2022
2113
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) ;
2027
2115
}
2028
2116
fn visit_foreign_item ( & mut self , ni : & ' tcx hir:: ForeignItem < ' tcx > ) {
2029
2117
intravisit:: walk_foreign_item ( self , ni) ;
0 commit comments