@@ -80,23 +80,34 @@ impl<'tcx> Tables<'tcx> {
8080 !must_override && self . tcx . is_mir_available ( def_id)
8181 }
8282
83- fn to_fn_def ( & mut self , tcx : TyCtxt < ' tcx > , def_id : DefId ) -> Option < FnDef > {
84- if matches ! ( tcx. def_kind( def_id) , DefKind :: Fn | DefKind :: AssocFn ) {
83+ fn to_fn_def ( & mut self , def_id : DefId ) -> Option < FnDef > {
84+ if matches ! ( self . tcx. def_kind( def_id) , DefKind :: Fn | DefKind :: AssocFn ) {
8585 Some ( self . fn_def ( def_id) )
8686 } else {
8787 None
8888 }
8989 }
9090
91- fn to_static ( & mut self , tcx : TyCtxt < ' tcx > , def_id : DefId ) -> Option < StaticDef > {
92- matches ! ( tcx. def_kind( def_id) , DefKind :: Static { .. } ) . then ( || self . static_def ( def_id) )
91+ fn to_static ( & mut self , def_id : DefId ) -> Option < StaticDef > {
92+ matches ! ( self . tcx. def_kind( def_id) , DefKind :: Static { .. } ) . then ( || self . static_def ( def_id) )
9393 }
94+ }
9495
95- /// Iterate over the definitions of the given crate.
96- pub fn iter_def_ids ( & self , tcx : TyCtxt < ' tcx > , krate : CrateNum ) -> impl Iterator < Item = DefId > {
97- let num_definitions = tcx. num_def_ids ( krate) ;
96+ /// Iterate over the definitions of the given crate.
97+ pub ( crate ) fn filter_def_ids < F , T > ( tcx : TyCtxt < ' _ > , krate : CrateNum , mut func : F ) -> Vec < T >
98+ where
99+ F : FnMut ( DefId ) -> Option < T > ,
100+ {
101+ if krate == LOCAL_CRATE {
102+ tcx. iter_local_def_id ( ) . filter_map ( |did| func ( did. to_def_id ( ) ) ) . collect ( )
103+ } else {
104+ let num_definitions = tcx. num_extern_def_ids ( krate) ;
98105 ( 0 ..num_definitions)
99- . map ( move |i| DefId { krate, index : rustc_span:: def_id:: DefIndex :: from_usize ( i) } )
106+ . filter_map ( move |i| {
107+ let def_id = DefId { krate, index : rustc_span:: def_id:: DefIndex :: from_usize ( i) } ;
108+ func ( def_id)
109+ } )
110+ . collect ( )
100111 }
101112}
102113
0 commit comments