Skip to content

Commit 3b9ccbb

Browse files
authored
Rollup merge of #141279 - nnethercote:lower_to_hir, r=compiler-errors
`lower_to_hir` cleanups Some minor cleanups I made when reading this code. r? `@Nadrieril`
2 parents ac500ad + 8a927e6 commit 3b9ccbb

File tree

2 files changed

+26
-38
lines changed

2 files changed

+26
-38
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -70,44 +70,32 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
7070
}
7171
}
7272

73-
pub(super) fn lower_node(&mut self, def_id: LocalDefId) -> hir::MaybeOwner<'hir> {
73+
pub(super) fn lower_node(&mut self, def_id: LocalDefId) {
7474
let owner = self.owners.ensure_contains_elem(def_id, || hir::MaybeOwner::Phantom);
7575
if let hir::MaybeOwner::Phantom = owner {
7676
let node = self.ast_index[def_id];
7777
match node {
7878
AstOwner::NonOwner => {}
79-
AstOwner::Crate(c) => self.lower_crate(c),
80-
AstOwner::Item(item) => self.lower_item(item),
81-
AstOwner::AssocItem(item, ctxt) => self.lower_assoc_item(item, ctxt),
82-
AstOwner::ForeignItem(item) => self.lower_foreign_item(item),
79+
AstOwner::Crate(c) => {
80+
debug_assert_eq!(self.resolver.node_id_to_def_id[&CRATE_NODE_ID], CRATE_DEF_ID);
81+
self.with_lctx(CRATE_NODE_ID, |lctx| {
82+
let module = lctx.lower_mod(&c.items, &c.spans);
83+
// FIXME(jdonszelman): is dummy span ever a problem here?
84+
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs, DUMMY_SP);
85+
hir::OwnerNode::Crate(module)
86+
})
87+
}
88+
AstOwner::Item(item) => {
89+
self.with_lctx(item.id, |lctx| hir::OwnerNode::Item(lctx.lower_item(item)))
90+
}
91+
AstOwner::AssocItem(item, ctxt) => {
92+
self.with_lctx(item.id, |lctx| lctx.lower_assoc_item(item, ctxt))
93+
}
94+
AstOwner::ForeignItem(item) => self.with_lctx(item.id, |lctx| {
95+
hir::OwnerNode::ForeignItem(lctx.lower_foreign_item(item))
96+
}),
8397
}
8498
}
85-
86-
self.owners[def_id]
87-
}
88-
89-
#[instrument(level = "debug", skip(self, c))]
90-
fn lower_crate(&mut self, c: &Crate) {
91-
debug_assert_eq!(self.resolver.node_id_to_def_id[&CRATE_NODE_ID], CRATE_DEF_ID);
92-
self.with_lctx(CRATE_NODE_ID, |lctx| {
93-
let module = lctx.lower_mod(&c.items, &c.spans);
94-
// FIXME(jdonszelman): is dummy span ever a problem here?
95-
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs, DUMMY_SP);
96-
hir::OwnerNode::Crate(module)
97-
})
98-
}
99-
100-
#[instrument(level = "debug", skip(self))]
101-
fn lower_item(&mut self, item: &Item) {
102-
self.with_lctx(item.id, |lctx| hir::OwnerNode::Item(lctx.lower_item(item)))
103-
}
104-
105-
fn lower_assoc_item(&mut self, item: &AssocItem, ctxt: AssocCtxt) {
106-
self.with_lctx(item.id, |lctx| lctx.lower_assoc_item(item, ctxt))
107-
}
108-
109-
fn lower_foreign_item(&mut self, item: &ForeignItem) {
110-
self.with_lctx(item.id, |lctx| hir::OwnerNode::ForeignItem(lctx.lower_foreign_item(item)))
11199
}
112100
}
113101

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -444,14 +444,14 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> hir::Crate<'_> {
444444
tcx.definitions_untracked().def_index_count(),
445445
);
446446

447+
let mut lowerer = item::ItemLowerer {
448+
tcx,
449+
resolver: &mut resolver,
450+
ast_index: &ast_index,
451+
owners: &mut owners,
452+
};
447453
for def_id in ast_index.indices() {
448-
item::ItemLowerer {
449-
tcx,
450-
resolver: &mut resolver,
451-
ast_index: &ast_index,
452-
owners: &mut owners,
453-
}
454-
.lower_node(def_id);
454+
lowerer.lower_node(def_id);
455455
}
456456

457457
drop(ast_index);

0 commit comments

Comments
 (0)