2020-01-05 02:37:57 +01:00
|
|
|
use rustc_hir as hir;
|
2022-04-07 12:29:57 -04:00
|
|
|
use rustc_hir::def::DefKind;
|
2020-03-29 17:19:48 +02:00
|
|
|
use rustc_middle::ty::TyCtxt;
|
2020-11-14 03:02:03 +01:00
|
|
|
use rustc_session::cstore::ForeignModule;
|
2018-02-10 14:28:17 -08:00
|
|
|
|
2022-05-20 19:51:09 -04:00
|
|
|
pub(crate) fn collect(tcx: TyCtxt<'_>) -> Vec<ForeignModule> {
|
2022-04-06 19:04:15 -04:00
|
|
|
let mut modules = Vec::new();
|
|
|
|
for id in tcx.hir().items() {
|
2022-10-27 14:02:18 +11:00
|
|
|
if !matches!(tcx.def_kind(id.owner_id), DefKind::ForeignMod) {
|
2022-04-06 19:04:15 -04:00
|
|
|
continue;
|
2022-04-07 12:29:57 -04:00
|
|
|
}
|
|
|
|
let item = tcx.hir().item(id);
|
|
|
|
if let hir::ItemKind::ForeignMod { items, .. } = item.kind {
|
2022-10-27 14:02:18 +11:00
|
|
|
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() });
|
2022-04-07 12:29:57 -04:00
|
|
|
}
|
2022-04-06 19:04:15 -04:00
|
|
|
}
|
|
|
|
modules
|
2018-02-10 14:28:17 -08:00
|
|
|
}
|