Auto merge of #79318 - cjgillot:fitem, r=lcnr
Store HIR ForeignItem in a side table In a similar fashion to Item, ImplItem and TraitItem.
This commit is contained in:
commit
c922857066
56 changed files with 400 additions and 226 deletions
|
@ -43,6 +43,7 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
|
|||
items: BTreeSet::new(),
|
||||
trait_items: BTreeSet::new(),
|
||||
impl_items: BTreeSet::new(),
|
||||
foreign_items: BTreeSet::new(),
|
||||
},
|
||||
);
|
||||
|
||||
|
@ -105,6 +106,18 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
|
|||
|
||||
visit::walk_assoc_item(self, item, ctxt);
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, item: &'a ForeignItem) {
|
||||
self.lctx.allocate_hir_id_counter(item.id);
|
||||
self.lctx.with_hir_id_owner(item.id, |lctx| {
|
||||
let hir_item = lctx.lower_foreign_item(item);
|
||||
let id = hir::ForeignItemId { hir_id: hir_item.hir_id };
|
||||
lctx.foreign_items.insert(id, hir_item);
|
||||
lctx.modules.get_mut(&lctx.current_module).unwrap().foreign_items.insert(id);
|
||||
});
|
||||
|
||||
visit::walk_foreign_item(self, item);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'hir> LoweringContext<'_, 'hir> {
|
||||
|
@ -304,7 +317,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
})
|
||||
}
|
||||
ItemKind::Mod(ref m) => hir::ItemKind::Mod(self.lower_mod(m)),
|
||||
ItemKind::ForeignMod(ref nm) => hir::ItemKind::ForeignMod(self.lower_foreign_mod(nm)),
|
||||
ItemKind::ForeignMod(ref fm) => hir::ItemKind::ForeignMod {
|
||||
abi: fm.abi.map_or(abi::Abi::C, |abi| self.lower_abi(abi)),
|
||||
items: self
|
||||
.arena
|
||||
.alloc_from_iter(fm.items.iter().map(|x| self.lower_foreign_item_ref(x))),
|
||||
},
|
||||
ItemKind::GlobalAsm(ref ga) => hir::ItemKind::GlobalAsm(self.lower_global_asm(ga)),
|
||||
ItemKind::TyAlias(_, ref gen, _, Some(ref ty)) => {
|
||||
// We lower
|
||||
|
@ -704,10 +722,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
}
|
||||
}
|
||||
|
||||
fn lower_foreign_mod(&mut self, fm: &ForeignMod) -> hir::ForeignMod<'hir> {
|
||||
hir::ForeignMod {
|
||||
abi: fm.abi.map_or(abi::Abi::C, |abi| self.lower_abi(abi)),
|
||||
items: self.arena.alloc_from_iter(fm.items.iter().map(|x| self.lower_foreign_item(x))),
|
||||
fn lower_foreign_item_ref(&mut self, i: &ForeignItem) -> hir::ForeignItemRef<'hir> {
|
||||
hir::ForeignItemRef {
|
||||
id: hir::ForeignItemId { hir_id: self.lower_node_id(i.id) },
|
||||
ident: i.ident,
|
||||
span: i.span,
|
||||
vis: self.lower_visibility(&i.vis, Some(i.id)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -101,6 +101,7 @@ struct LoweringContext<'a, 'hir: 'a> {
|
|||
|
||||
trait_items: BTreeMap<hir::TraitItemId, hir::TraitItem<'hir>>,
|
||||
impl_items: BTreeMap<hir::ImplItemId, hir::ImplItem<'hir>>,
|
||||
foreign_items: BTreeMap<hir::ForeignItemId, hir::ForeignItem<'hir>>,
|
||||
bodies: BTreeMap<hir::BodyId, hir::Body<'hir>>,
|
||||
exported_macros: Vec<hir::MacroDef<'hir>>,
|
||||
non_exported_macro_attrs: Vec<ast::Attribute>,
|
||||
|
@ -298,6 +299,7 @@ pub fn lower_crate<'a, 'hir>(
|
|||
items: BTreeMap::new(),
|
||||
trait_items: BTreeMap::new(),
|
||||
impl_items: BTreeMap::new(),
|
||||
foreign_items: BTreeMap::new(),
|
||||
bodies: BTreeMap::new(),
|
||||
trait_impls: BTreeMap::new(),
|
||||
modules: BTreeMap::new(),
|
||||
|
@ -485,6 +487,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
visit::walk_assoc_item(self, item, ctxt);
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, item: &'tcx ForeignItem) {
|
||||
self.lctx.allocate_hir_id_counter(item.id);
|
||||
visit::walk_foreign_item(self, item);
|
||||
}
|
||||
|
||||
fn visit_ty(&mut self, t: &'tcx Ty) {
|
||||
match t.kind {
|
||||
// Mirrors the case in visit::walk_ty
|
||||
|
@ -548,6 +555,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
items: self.items,
|
||||
trait_items: self.trait_items,
|
||||
impl_items: self.impl_items,
|
||||
foreign_items: self.foreign_items,
|
||||
bodies: self.bodies,
|
||||
body_ids,
|
||||
trait_impls: self.trait_impls,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue