@@ -1288,21 +1288,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
12881288 }
12891289 }
12901290
1291- fn encode_field (
1292- & mut self ,
1293- adt_def : ty:: AdtDef < ' tcx > ,
1294- variant_index : VariantIdx ,
1295- field_index : usize ,
1296- ) {
1297- let variant = & adt_def. variant ( variant_index) ;
1298- let field = & variant. fields [ field_index] ;
1299-
1300- let def_id = field. did ;
1301- debug ! ( "EncodeContext::encode_field({:?})" , def_id) ;
1302-
1303- record ! ( self . tables. kind[ def_id] <- EntryKind :: Field ) ;
1304- }
1305-
13061291 fn encode_struct_ctor ( & mut self , adt_def : ty:: AdtDef < ' tcx > , def_id : DefId ) {
13071292 debug ! ( "EncodeContext::encode_struct_ctor({:?})" , def_id) ;
13081293 let tcx = self . tcx ;
@@ -1657,6 +1642,52 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16571642 record ! ( self . tables. impl_trait_ref[ def_id] <- trait_ref) ;
16581643 }
16591644 }
1645+ // In some cases, along with the item itself, we also
1646+ // encode some sub-items. Usually we want some info from the item
1647+ // so it's easier to do that here then to wait until we would encounter
1648+ // normally in the visitor walk.
1649+ match item. kind {
1650+ hir:: ItemKind :: Enum ( ..) => {
1651+ let def = self . tcx . adt_def ( item. def_id . to_def_id ( ) ) ;
1652+ self . encode_fields ( def) ;
1653+
1654+ for ( i, variant) in def. variants ( ) . iter_enumerated ( ) {
1655+ self . encode_enum_variant_info ( def, i) ;
1656+
1657+ if let Some ( _ctor_def_id) = variant. ctor_def_id {
1658+ self . encode_enum_variant_ctor ( def, i) ;
1659+ }
1660+ }
1661+ }
1662+ hir:: ItemKind :: Struct ( ref struct_def, _) => {
1663+ let def = self . tcx . adt_def ( item. def_id . to_def_id ( ) ) ;
1664+ self . encode_fields ( def) ;
1665+
1666+ // If the struct has a constructor, encode it.
1667+ if let Some ( ctor_hir_id) = struct_def. ctor_hir_id ( ) {
1668+ let ctor_def_id = self . tcx . hir ( ) . local_def_id ( ctor_hir_id) ;
1669+ self . encode_struct_ctor ( def, ctor_def_id. to_def_id ( ) ) ;
1670+ }
1671+ }
1672+ hir:: ItemKind :: Union ( ..) => {
1673+ let def = self . tcx . adt_def ( item. def_id . to_def_id ( ) ) ;
1674+ self . encode_fields ( def) ;
1675+ }
1676+ hir:: ItemKind :: Impl { .. } => {
1677+ for & trait_item_def_id in
1678+ self . tcx . associated_item_def_ids ( item. def_id . to_def_id ( ) ) . iter ( )
1679+ {
1680+ self . encode_info_for_impl_item ( trait_item_def_id) ;
1681+ }
1682+ }
1683+ hir:: ItemKind :: Trait ( ..) => {
1684+ for & item_def_id in self . tcx . associated_item_def_ids ( item. def_id . to_def_id ( ) ) . iter ( )
1685+ {
1686+ self . encode_info_for_trait_item ( item_def_id) ;
1687+ }
1688+ }
1689+ _ => { }
1690+ }
16601691 }
16611692
16621693 fn encode_info_for_closure ( & mut self , hir_id : hir:: HirId ) {
@@ -2062,7 +2093,6 @@ impl<'a, 'tcx> Visitor<'tcx> for EncodeContext<'a, 'tcx> {
20622093 hir:: ItemKind :: ExternCrate ( _) | hir:: ItemKind :: Use ( ..) => { } // ignore these
20632094 _ => self . encode_info_for_item ( item. def_id . to_def_id ( ) , item) ,
20642095 }
2065- self . encode_addl_info_for_item ( item) ;
20662096 }
20672097 fn visit_foreign_item ( & mut self , ni : & ' tcx hir:: ForeignItem < ' tcx > ) {
20682098 intravisit:: walk_foreign_item ( self , ni) ;
@@ -2078,7 +2108,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
20782108 fn encode_fields ( & mut self , adt_def : ty:: AdtDef < ' tcx > ) {
20792109 for ( variant_index, variant) in adt_def. variants ( ) . iter_enumerated ( ) {
20802110 for ( field_index, _field) in variant. fields . iter ( ) . enumerate ( ) {
2081- self . encode_field ( adt_def, variant_index, field_index) ;
2111+ let variant = & adt_def. variant ( variant_index) ;
2112+ let field = & variant. fields [ field_index] ;
2113+ let def_id = field. did ;
2114+ debug ! ( "EncodeContext::encode_field({:?})" , def_id) ;
2115+ record ! ( self . tables. kind[ def_id] <- EntryKind :: Field ) ;
20822116 }
20832117 }
20842118 }
@@ -2103,68 +2137,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
21032137 self . encode_info_for_closure ( expr. hir_id ) ;
21042138 }
21052139 }
2106-
2107- /// In some cases, along with the item itself, we also
2108- /// encode some sub-items. Usually we want some info from the item
2109- /// so it's easier to do that here then to wait until we would encounter
2110- /// normally in the visitor walk.
2111- fn encode_addl_info_for_item ( & mut self , item : & hir:: Item < ' _ > ) {
2112- match item. kind {
2113- hir:: ItemKind :: Static ( ..)
2114- | hir:: ItemKind :: Const ( ..)
2115- | hir:: ItemKind :: Fn ( ..)
2116- | hir:: ItemKind :: Macro ( ..)
2117- | hir:: ItemKind :: Mod ( ..)
2118- | hir:: ItemKind :: ForeignMod { .. }
2119- | hir:: ItemKind :: GlobalAsm ( ..)
2120- | hir:: ItemKind :: ExternCrate ( ..)
2121- | hir:: ItemKind :: Use ( ..)
2122- | hir:: ItemKind :: TyAlias ( ..)
2123- | hir:: ItemKind :: OpaqueTy ( ..)
2124- | hir:: ItemKind :: TraitAlias ( ..) => {
2125- // no sub-item recording needed in these cases
2126- }
2127- hir:: ItemKind :: Enum ( ..) => {
2128- let def = self . tcx . adt_def ( item. def_id . to_def_id ( ) ) ;
2129- self . encode_fields ( def) ;
2130-
2131- for ( i, variant) in def. variants ( ) . iter_enumerated ( ) {
2132- self . encode_enum_variant_info ( def, i) ;
2133-
2134- if let Some ( _ctor_def_id) = variant. ctor_def_id {
2135- self . encode_enum_variant_ctor ( def, i) ;
2136- }
2137- }
2138- }
2139- hir:: ItemKind :: Struct ( ref struct_def, _) => {
2140- let def = self . tcx . adt_def ( item. def_id . to_def_id ( ) ) ;
2141- self . encode_fields ( def) ;
2142-
2143- // If the struct has a constructor, encode it.
2144- if let Some ( ctor_hir_id) = struct_def. ctor_hir_id ( ) {
2145- let ctor_def_id = self . tcx . hir ( ) . local_def_id ( ctor_hir_id) ;
2146- self . encode_struct_ctor ( def, ctor_def_id. to_def_id ( ) ) ;
2147- }
2148- }
2149- hir:: ItemKind :: Union ( ..) => {
2150- let def = self . tcx . adt_def ( item. def_id . to_def_id ( ) ) ;
2151- self . encode_fields ( def) ;
2152- }
2153- hir:: ItemKind :: Impl { .. } => {
2154- for & trait_item_def_id in
2155- self . tcx . associated_item_def_ids ( item. def_id . to_def_id ( ) ) . iter ( )
2156- {
2157- self . encode_info_for_impl_item ( trait_item_def_id) ;
2158- }
2159- }
2160- hir:: ItemKind :: Trait ( ..) => {
2161- for & item_def_id in self . tcx . associated_item_def_ids ( item. def_id . to_def_id ( ) ) . iter ( )
2162- {
2163- self . encode_info_for_trait_item ( item_def_id) ;
2164- }
2165- }
2166- }
2167- }
21682140}
21692141
21702142/// Used to prefetch queries which will be needed later by metadata encoding.
0 commit comments