Skip to content

Commit ab3271f

Browse files
committed
Simplify the creation of synthetic HIR.
1 parent 54f67d2 commit ab3271f

2 files changed

Lines changed: 16 additions & 17 deletions

File tree

compiler/rustc_hir/src/hir.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,20 @@ impl<'tcx> OwnerNodes<'tcx> {
15951595
// Indexing must ensure it is an OwnerNode.
15961596
self.nodes[ItemLocalId::ZERO].node.as_owner().unwrap()
15971597
}
1598+
1599+
/// Return an instance of `OwnerNodes` suitable for definitions that have no corresponding AST.
1600+
pub fn synthetic() -> OwnerNodes<'tcx> {
1601+
OwnerNodes {
1602+
// There is no reason to bother computing a hash for a synthetic body.
1603+
// Just use a constant value.
1604+
opt_hash_including_bodies: Some(Fingerprint::ZERO),
1605+
nodes: IndexVec::from_elem_n(
1606+
ParentedNode { parent: ItemLocalId::INVALID, node: OwnerNode::Synthetic.into() },
1607+
1,
1608+
),
1609+
bodies: SortedMap::new(),
1610+
}
1611+
}
15981612
}
15991613

16001614
impl fmt::Debug for OwnerNodes<'_> {

compiler/rustc_middle/src/ty/context.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -623,23 +623,8 @@ impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> {
623623
// Fills in all the important parts needed by HIR queries
624624
pub fn feed_hir(&self) {
625625
self.local_def_id_to_hir_id(HirId::make_owner(self.def_id()));
626-
627-
let node = hir::OwnerNode::Synthetic;
628-
let bodies = Default::default();
629-
let attrs = hir::AttributeMap::EMPTY;
630-
631-
let rustc_middle::hir::Hashes { opt_hash_including_bodies, .. } =
632-
self.tcx.hash_owner_nodes(node, &bodies, &attrs.map, attrs.define_opaque);
633-
let node = node.into();
634-
self.opt_hir_owner_nodes(Some(self.tcx.arena.alloc(hir::OwnerNodes {
635-
opt_hash_including_bodies,
636-
nodes: IndexVec::from_elem_n(
637-
hir::ParentedNode { parent: hir::ItemLocalId::INVALID, node },
638-
1,
639-
),
640-
bodies,
641-
})));
642-
self.feed_owner_id().hir_attr_map(attrs);
626+
self.opt_hir_owner_nodes(Some(self.tcx.arena.alloc(hir::OwnerNodes::synthetic())));
627+
self.feed_owner_id().hir_attr_map(hir::AttributeMap::EMPTY);
643628
}
644629
}
645630

0 commit comments

Comments
 (0)