@@ -836,6 +836,41 @@ fn should_encode_mir(tcx: TyCtxt<'_>, def_id: LocalDefId) -> (bool, bool) {
836836 }
837837}
838838
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+
839874impl EncodeContext < ' a , ' tcx > {
840875 fn encode_def_ids ( & mut self ) {
841876 if self . is_proc_macro {
@@ -864,6 +899,10 @@ impl EncodeContext<'a, 'tcx> {
864899 self . encode_const_stability ( def_id) ;
865900 self . encode_deprecation ( def_id) ;
866901 }
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+ }
867906 }
868907 let inherent_impls = tcx. crate_inherent_impls ( LOCAL_CRATE ) ;
869908 for ( def_id, implementations) in inherent_impls. inherent_impls . iter ( ) {
@@ -878,11 +917,6 @@ impl EncodeContext<'a, 'tcx> {
878917 }
879918 }
880919
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-
886920 fn encode_item_type ( & mut self , def_id : DefId ) {
887921 debug ! ( "EncodeContext::encode_item_type({:?})" , def_id) ;
888922 record ! ( self . tables. ty[ def_id] <- self . tcx. type_of( def_id) ) ;
@@ -913,8 +947,6 @@ impl EncodeContext<'a, 'tcx> {
913947 if let Some ( ctor_def_id) = variant. ctor_def_id {
914948 record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( ctor_def_id) ) ;
915949 }
916- // FIXME(eddyb) is this ever used?
917- self . encode_variances_of ( def_id) ;
918950 }
919951 self . encode_generics ( def_id) ;
920952 self . encode_explicit_predicates ( def_id) ;
@@ -939,7 +971,6 @@ impl EncodeContext<'a, 'tcx> {
939971 self . encode_item_type ( def_id) ;
940972 if variant. ctor_kind == CtorKind :: Fn {
941973 record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
942- self . encode_variances_of ( def_id) ;
943974 }
944975 self . encode_generics ( def_id) ;
945976 self . encode_explicit_predicates ( def_id) ;
@@ -1023,7 +1054,6 @@ impl EncodeContext<'a, 'tcx> {
10231054 self . encode_item_type ( def_id) ;
10241055 if variant. ctor_kind == CtorKind :: Fn {
10251056 record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1026- self . encode_variances_of ( def_id) ;
10271057 }
10281058 self . encode_generics ( def_id) ;
10291059 self . encode_explicit_predicates ( def_id) ;
@@ -1128,7 +1158,6 @@ impl EncodeContext<'a, 'tcx> {
11281158 }
11291159 if trait_item. kind == ty:: AssocKind :: Fn {
11301160 record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1131- self . encode_variances_of ( def_id) ;
11321161 }
11331162 self . encode_generics ( def_id) ;
11341163 self . encode_explicit_predicates ( def_id) ;
@@ -1189,7 +1218,6 @@ impl EncodeContext<'a, 'tcx> {
11891218 self . encode_item_type ( def_id) ;
11901219 if impl_item. kind == ty:: AssocKind :: Fn {
11911220 record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1192- self . encode_variances_of ( def_id) ;
11931221 }
11941222 self . encode_generics ( def_id) ;
11951223 self . encode_explicit_predicates ( def_id) ;
@@ -1458,13 +1486,6 @@ impl EncodeContext<'a, 'tcx> {
14581486 record ! ( self . tables. impl_trait_ref[ def_id] <- trait_ref) ;
14591487 }
14601488 }
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- }
14681489 match item. kind {
14691490 hir:: ItemKind :: Static ( ..)
14701491 | hir:: ItemKind :: Const ( ..)
@@ -1822,7 +1843,6 @@ impl EncodeContext<'a, 'tcx> {
18221843 self . encode_item_type ( def_id) ;
18231844 if let hir:: ForeignItemKind :: Fn ( ..) = nitem. kind {
18241845 record ! ( self . tables. fn_sig[ def_id] <- tcx. fn_sig( def_id) ) ;
1825- self . encode_variances_of ( def_id) ;
18261846 }
18271847 self . encode_generics ( def_id) ;
18281848 self . encode_explicit_predicates ( def_id) ;
0 commit comments