2020-01-04 19:37:57 -06:00
|
|
|
use rustc_hir as hir;
|
2022-04-07 11:29:57 -05:00
|
|
|
use rustc_hir::def::DefKind;
|
2020-03-29 10:19:48 -05:00
|
|
|
use rustc_middle::ty::TyCtxt;
|
2020-11-13 20:02:03 -06:00
|
|
|
use rustc_session::cstore::ForeignModule;
|
2018-02-10 16:28:17 -06:00
|
|
|
|
2019-10-06 06:30:46 -05:00
|
|
|
crate fn collect(tcx: TyCtxt<'_>) -> Vec<ForeignModule> {
|
2022-04-06 18:04:15 -05:00
|
|
|
let mut modules = Vec::new();
|
|
|
|
for id in tcx.hir().items() {
|
2022-04-07 11:29:57 -05:00
|
|
|
if !matches!(tcx.hir().def_kind(id.def_id), DefKind::ForeignMod) {
|
2022-04-06 18:04:15 -05:00
|
|
|
continue;
|
2022-04-07 11:29:57 -05:00
|
|
|
}
|
|
|
|
let item = tcx.hir().item(id);
|
|
|
|
if let hir::ItemKind::ForeignMod { items, .. } = item.kind {
|
|
|
|
let foreign_items = items.iter().map(|it| it.id.def_id.to_def_id()).collect();
|
|
|
|
modules.push(ForeignModule { foreign_items, def_id: id.def_id.to_def_id() });
|
|
|
|
}
|
2022-04-06 18:04:15 -05:00
|
|
|
}
|
|
|
|
modules
|
2018-02-10 16:28:17 -06:00
|
|
|
}
|