forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#113754 - cjgillot:simplify-foreign, r=petro…
…chenkov Simplify native_libs query Drive-by cleanup I saw while implementing rust-lang#113734
- Loading branch information
Showing
7 changed files
with
54 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,28 @@ | ||
use rustc_data_structures::fx::FxIndexMap; | ||
use rustc_hir as hir; | ||
use rustc_hir::def::DefKind; | ||
use rustc_hir::def_id::DefId; | ||
use rustc_middle::query::LocalCrate; | ||
use rustc_middle::ty::TyCtxt; | ||
use rustc_session::cstore::ForeignModule; | ||
|
||
pub(crate) fn collect(tcx: TyCtxt<'_>) -> Vec<ForeignModule> { | ||
let mut modules = Vec::new(); | ||
pub(crate) fn collect(tcx: TyCtxt<'_>, LocalCrate: LocalCrate) -> FxIndexMap<DefId, ForeignModule> { | ||
let mut modules = FxIndexMap::default(); | ||
|
||
// We need to collect all the `ForeignMod`, even if they are empty. | ||
for id in tcx.hir().items() { | ||
if !matches!(tcx.def_kind(id.owner_id), DefKind::ForeignMod) { | ||
continue; | ||
} | ||
|
||
let def_id = id.owner_id.to_def_id(); | ||
let item = tcx.hir().item(id); | ||
if let hir::ItemKind::ForeignMod { items, .. } = item.kind { | ||
|
||
if let hir::ItemKind::ForeignMod { abi, items } = item.kind { | ||
let foreign_items = items.iter().map(|it| it.id.owner_id.to_def_id()).collect(); | ||
modules.push(ForeignModule { foreign_items, def_id: id.owner_id.to_def_id() }); | ||
modules.insert(def_id, ForeignModule { def_id, abi, foreign_items }); | ||
} | ||
} | ||
|
||
modules | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters