@@ -14,7 +14,7 @@ use rustc_middle::mir;
1414use rustc_middle:: mir:: interpret:: AllocId ;
1515use rustc_middle:: ty:: data_structures:: HashSet ;
1616use rustc_middle:: ty:: { self , Instance , Ty , TyCtxt } ;
17- use rustc_span:: def_id:: { CRATE_DEF_INDEX , CrateNum , DefId , LOCAL_CRATE } ;
17+ use rustc_span:: def_id:: { CrateNum , DefId , LOCAL_CRATE } ;
1818use stable_mir:: abi:: Layout ;
1919use stable_mir:: mir:: mono:: { InstanceDef , StaticDef } ;
2020use stable_mir:: ty:: { FnDef , MirConstId , Span , TyConstId } ;
@@ -97,34 +97,25 @@ impl<'tcx> Tables<'tcx> {
9797 where
9898 F : Fn ( & mut Tables < ' tcx > , TyCtxt < ' tcx > , DefId ) -> Option < T > ,
9999 {
100- let crate_def = rustc_span :: def_id :: DefId { index : CRATE_DEF_INDEX , krate } ;
100+ let crate_def = krate. as_def_id ( ) ;
101101 let mut queue = vec ! [ crate_def] ;
102+ queue. extend_from_slice ( tcx. trait_impls_in_crate ( krate) ) ;
102103 let mut visited = HashSet :: default ( ) ;
103104 let mut result = vec ! [ ] ;
104- while let Some ( next) = queue. pop ( ) {
105- for def_id in tcx. module_children ( next) . iter ( ) . filter_map ( |item| item. res . opt_def_id ( ) )
106- {
107- if !visited. contains ( & def_id) {
108- visited. insert ( def_id) ;
109- result. extend ( func ( self , tcx, def_id) ) ;
110- match tcx. def_kind ( def_id) {
111- DefKind :: Mod | DefKind :: ForeignMod => queue. push ( def_id) ,
112- DefKind :: Struct | DefKind :: Enum | DefKind :: Union => {
113- for associated_item in tcx
114- . inherent_impls ( def_id)
115- . iter ( )
116- . flat_map ( |impl_id| tcx. associated_item_def_ids ( impl_id) )
117- {
118- result. extend ( func ( self , tcx, * associated_item) ) ;
119- }
120- }
121- DefKind :: Trait => {
122- for associated_item in tcx. associated_item_def_ids ( def_id) {
123- result. extend ( func ( self , tcx, * associated_item) ) ;
124- }
125- }
126- _ => { }
105+ while let Some ( def_id) = queue. pop ( ) {
106+ if visited. insert ( def_id) {
107+ result. extend ( func ( self , tcx, def_id) ) ;
108+ match tcx. def_kind ( def_id) {
109+ DefKind :: Mod | DefKind :: ForeignMod | DefKind :: Trait => queue. extend (
110+ tcx. module_children ( def_id) . iter ( ) . filter_map ( |item| item. res . opt_def_id ( ) ) ,
111+ ) ,
112+ DefKind :: Impl { .. } => queue. extend (
113+ tcx. associated_items ( def_id) . in_definition_order ( ) . map ( |item| item. def_id ) ,
114+ ) ,
115+ DefKind :: Struct | DefKind :: Enum | DefKind :: Union => {
116+ queue. extend ( tcx. inherent_impls ( def_id) ) ;
127117 }
118+ _ => { }
128119 }
129120 }
130121 }
0 commit comments