File tree Expand file tree Collapse file tree 2 files changed +16
-6
lines changed
compiler/rustc_metadata/src Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change 1+ use rustc_data_structures:: fx:: FxHashMap ;
12use rustc_hir as hir;
23use rustc_hir:: def:: DefKind ;
4+ use rustc_hir:: def_id:: DefId ;
5+ use rustc_middle:: query:: LocalCrate ;
36use rustc_middle:: ty:: TyCtxt ;
47use rustc_session:: cstore:: ForeignModule ;
58
6- pub ( crate ) fn collect ( tcx : TyCtxt < ' _ > ) -> Vec < ForeignModule > {
7- let mut modules = Vec :: new ( ) ;
9+ pub ( crate ) fn collect (
10+ tcx : TyCtxt < ' _ > ,
11+ LocalCrate : LocalCrate ,
12+ ) -> FxHashMap < DefId , ForeignModule > {
13+ let mut modules = FxHashMap :: default ( ) ;
14+
15+ // We need to collect all the `ForeignMod`, even if they are empty.
816 for id in tcx. hir ( ) . items ( ) {
917 if !matches ! ( tcx. def_kind( id. owner_id) , DefKind :: ForeignMod ) {
1018 continue ;
1119 }
20+
21+ let def_id = id. owner_id . to_def_id ( ) ;
1222 let item = tcx. hir ( ) . item ( id) ;
23+
1324 if let hir:: ItemKind :: ForeignMod { items, .. } = item. kind {
1425 let foreign_items = items. iter ( ) . map ( |it| it. id . owner_id . to_def_id ( ) ) . collect ( ) ;
15- modules. push ( ForeignModule { foreign_items, def_id : id . owner_id . to_def_id ( ) } ) ;
26+ modules. insert ( def_id , ForeignModule { foreign_items, def_id } ) ;
1627 }
1728 }
29+
1830 modules
1931}
Original file line number Diff line number Diff line change @@ -404,9 +404,7 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
404404 } )
405405 } ,
406406 native_libraries : |tcx, LocalCrate | native_libs:: collect ( tcx) ,
407- foreign_modules : |tcx, LocalCrate | {
408- foreign_modules:: collect ( tcx) . into_iter ( ) . map ( |m| ( m. def_id , m) ) . collect ( )
409- } ,
407+ foreign_modules : foreign_modules:: collect,
410408
411409 // Returns a map from a sufficiently visible external item (i.e., an
412410 // external item that is visible from at least one local module) to a
You can’t perform that action at this time.
0 commit comments