@@ -836,6 +836,41 @@ fn should_encode_mir(tcx: TyCtxt<'_>, def_id: LocalDefId) -> (bool, bool) {
836
836
}
837
837
}
838
838
839
+ fn should_encode_variances ( def_kind : DefKind ) -> bool {
840
+ match def_kind {
841
+ DefKind :: Struct
842
+ | DefKind :: Union
843
+ | DefKind :: Enum
844
+ | DefKind :: Variant
845
+ | DefKind :: Fn
846
+ | DefKind :: Ctor ( ..)
847
+ | DefKind :: AssocFn => true ,
848
+ DefKind :: Mod
849
+ | DefKind :: Field
850
+ | DefKind :: AssocTy
851
+ | DefKind :: AssocConst
852
+ | DefKind :: TyParam
853
+ | DefKind :: ConstParam
854
+ | DefKind :: Static
855
+ | DefKind :: Const
856
+ | DefKind :: ForeignMod
857
+ | DefKind :: TyAlias
858
+ | DefKind :: OpaqueTy
859
+ | DefKind :: Impl
860
+ | DefKind :: Trait
861
+ | DefKind :: TraitAlias
862
+ | DefKind :: Macro ( ..)
863
+ | DefKind :: ForeignTy
864
+ | DefKind :: Use
865
+ | DefKind :: LifetimeParam
866
+ | DefKind :: AnonConst
867
+ | DefKind :: GlobalAsm
868
+ | DefKind :: Closure
869
+ | DefKind :: Generator
870
+ | DefKind :: ExternCrate => false ,
871
+ }
872
+ }
873
+
839
874
impl EncodeContext < ' a , ' tcx > {
840
875
fn encode_def_ids ( & mut self ) {
841
876
if self . is_proc_macro {
@@ -864,6 +899,10 @@ impl EncodeContext<'a, 'tcx> {
864
899
self . encode_const_stability ( def_id) ;
865
900
self . encode_deprecation ( def_id) ;
866
901
}
902
+ if should_encode_variances ( def_kind) {
903
+ let v = self . tcx . variances_of ( def_id) ;
904
+ record ! ( self . tables. variances[ def_id] <- v) ;
905
+ }
867
906
}
868
907
let inherent_impls = tcx. crate_inherent_impls ( LOCAL_CRATE ) ;
869
908
for ( def_id, implementations) in inherent_impls. inherent_impls . iter ( ) {
@@ -878,11 +917,6 @@ impl EncodeContext<'a, 'tcx> {
878
917
}
879
918
}
880
919
881
- fn encode_variances_of ( & mut self , def_id : DefId ) {
882
- debug ! ( "EncodeContext::encode_variances_of({:?})" , def_id) ;
883
- record ! ( self . tables. variances[ def_id] <- self . tcx. variances_of( def_id) ) ;
884
- }
885
-
886
920
fn encode_item_type ( & mut self , def_id : DefId ) {
887
921
debug ! ( "EncodeContext::encode_item_type({:?})" , def_id) ;
888
922
record ! ( self . tables. ty[ def_id] <- self . tcx. type_of( def_id) ) ;
@@ -913,8 +947,6 @@ impl EncodeContext<'a, 'tcx> {
913
947
if let Some ( ctor_def_id) = variant. ctor_def_id {
914
948
record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( ctor_def_id) ) ;
915
949
}
916
- // FIXME(eddyb) is this ever used?
917
- self . encode_variances_of ( def_id) ;
918
950
}
919
951
self . encode_generics ( def_id) ;
920
952
self . encode_explicit_predicates ( def_id) ;
@@ -939,7 +971,6 @@ impl EncodeContext<'a, 'tcx> {
939
971
self . encode_item_type ( def_id) ;
940
972
if variant. ctor_kind == CtorKind :: Fn {
941
973
record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
942
- self . encode_variances_of ( def_id) ;
943
974
}
944
975
self . encode_generics ( def_id) ;
945
976
self . encode_explicit_predicates ( def_id) ;
@@ -1023,7 +1054,6 @@ impl EncodeContext<'a, 'tcx> {
1023
1054
self . encode_item_type ( def_id) ;
1024
1055
if variant. ctor_kind == CtorKind :: Fn {
1025
1056
record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1026
- self . encode_variances_of ( def_id) ;
1027
1057
}
1028
1058
self . encode_generics ( def_id) ;
1029
1059
self . encode_explicit_predicates ( def_id) ;
@@ -1128,7 +1158,6 @@ impl EncodeContext<'a, 'tcx> {
1128
1158
}
1129
1159
if trait_item. kind == ty:: AssocKind :: Fn {
1130
1160
record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1131
- self . encode_variances_of ( def_id) ;
1132
1161
}
1133
1162
self . encode_generics ( def_id) ;
1134
1163
self . encode_explicit_predicates ( def_id) ;
@@ -1189,7 +1218,6 @@ impl EncodeContext<'a, 'tcx> {
1189
1218
self . encode_item_type ( def_id) ;
1190
1219
if impl_item. kind == ty:: AssocKind :: Fn {
1191
1220
record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1192
- self . encode_variances_of ( def_id) ;
1193
1221
}
1194
1222
self . encode_generics ( def_id) ;
1195
1223
self . encode_explicit_predicates ( def_id) ;
@@ -1458,13 +1486,6 @@ impl EncodeContext<'a, 'tcx> {
1458
1486
record ! ( self . tables. impl_trait_ref[ def_id] <- trait_ref) ;
1459
1487
}
1460
1488
}
1461
- match item. kind {
1462
- hir:: ItemKind :: Enum ( ..)
1463
- | hir:: ItemKind :: Struct ( ..)
1464
- | hir:: ItemKind :: Union ( ..)
1465
- | hir:: ItemKind :: Fn ( ..) => self . encode_variances_of ( def_id) ,
1466
- _ => { }
1467
- }
1468
1489
match item. kind {
1469
1490
hir:: ItemKind :: Static ( ..)
1470
1491
| hir:: ItemKind :: Const ( ..)
@@ -1822,7 +1843,6 @@ impl EncodeContext<'a, 'tcx> {
1822
1843
self . encode_item_type ( def_id) ;
1823
1844
if let hir:: ForeignItemKind :: Fn ( ..) = nitem. kind {
1824
1845
record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1825
- self . encode_variances_of ( def_id) ;
1826
1846
}
1827
1847
self . encode_generics ( def_id) ;
1828
1848
self . encode_explicit_predicates ( def_id) ;
0 commit comments