@@ -1783,14 +1783,31 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
17831783 debug ! ( "EncodeContext::encode_traits_and_impls()" ) ;
17841784 empty_proc_macro ! ( self ) ;
17851785 let tcx = self . tcx ;
1786- let mut visitor = ImplsVisitor { tcx, impls : FxHashMap :: default ( ) } ;
1786+ let mut fx_hash_map: FxHashMap < DefId , Vec < ( DefIndex , Option < SimplifiedType > ) > > =
1787+ FxHashMap :: default ( ) ;
17871788
17881789 for id in tcx. hir ( ) . items ( ) {
1789- let item = tcx. hir ( ) . item ( id) ;
1790- visitor. visit_item ( item) ;
1790+ match tcx. hir ( ) . def_kind ( id. def_id ) {
1791+ DefKind :: Impl => {
1792+ let item = tcx. hir ( ) . item ( id) ;
1793+ if let Some ( trait_ref) = tcx. impl_trait_ref ( item. def_id . to_def_id ( ) ) {
1794+ let simplified_self_ty = fast_reject:: simplify_type (
1795+ self . tcx ,
1796+ trait_ref. self_ty ( ) ,
1797+ TreatParams :: AsPlaceholders ,
1798+ ) ;
1799+
1800+ fx_hash_map
1801+ . entry ( trait_ref. def_id )
1802+ . or_default ( )
1803+ . push ( ( item. def_id . local_def_index , simplified_self_ty) ) ;
1804+ }
1805+ }
1806+ _ => continue ,
1807+ }
17911808 }
17921809
1793- let mut all_impls: Vec < _ > = visitor . impls . into_iter ( ) . collect ( ) ;
1810+ let mut all_impls: Vec < _ > = fx_hash_map . into_iter ( ) . collect ( ) ;
17941811
17951812 // Bring everything into deterministic order for hashing
17961813 all_impls. sort_by_cached_key ( |& ( trait_def_id, _) | tcx. def_path_hash ( trait_def_id) ) ;
@@ -2053,41 +2070,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
20532070 }
20542071}
20552072
2056- struct ImplsVisitor < ' tcx > {
2057- tcx : TyCtxt < ' tcx > ,
2058- impls : FxHashMap < DefId , Vec < ( DefIndex , Option < SimplifiedType > ) > > ,
2059- }
2060-
2061- impl < ' tcx , ' v > ItemLikeVisitor < ' v > for ImplsVisitor < ' tcx > {
2062- fn visit_item ( & mut self , item : & hir:: Item < ' _ > ) {
2063- match item. kind {
2064- hir:: ItemKind :: Impl ( ..) => {
2065- if let Some ( trait_ref) = self . tcx . impl_trait_ref ( item. def_id . to_def_id ( ) ) {
2066- let simplified_self_ty = fast_reject:: simplify_type (
2067- self . tcx ,
2068- trait_ref. self_ty ( ) ,
2069- TreatParams :: AsPlaceholders ,
2070- ) ;
2071-
2072- self . impls
2073- . entry ( trait_ref. def_id )
2074- . or_default ( )
2075- . push ( ( item. def_id . local_def_index , simplified_self_ty) ) ;
2076- }
2077- }
2078- _ => { }
2079- }
2080- }
2081-
2082- fn visit_trait_item ( & mut self , _trait_item : & ' v hir:: TraitItem < ' v > ) { }
2083-
2084- fn visit_impl_item ( & mut self , _impl_item : & ' v hir:: ImplItem < ' v > ) {
2085- // handled in `visit_item` above
2086- }
2087-
2088- fn visit_foreign_item ( & mut self , _foreign_item : & ' v hir:: ForeignItem < ' v > ) { }
2089- }
2090-
20912073/// Used to prefetch queries which will be needed later by metadata encoding.
20922074/// Only a subset of the queries are actually prefetched to keep this code smaller.
20932075fn prefetch_mir ( tcx : TyCtxt < ' _ > ) {
0 commit comments