Skip to content

Commit a71746c

Browse files
Rollup merge of #156123 - cjgillot:synthetic-hir, r=JonathanBrouwer
Simplify the creation of synthetic HIR.
2 parents 6133b7e + ab3271f commit a71746c

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
@@ -627,23 +627,8 @@ impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> {
627627
// Fills in all the important parts needed by HIR queries
628628
pub fn feed_hir(&self) {
629629
self.local_def_id_to_hir_id(HirId::make_owner(self.def_id()));
630-
631-
let node = hir::OwnerNode::Synthetic;
632-
let bodies = Default::default();
633-
let attrs = hir::AttributeMap::EMPTY;
634-
635-
let rustc_middle::hir::Hashes { opt_hash_including_bodies, .. } =
636-
self.tcx.hash_owner_nodes(node, &bodies, &attrs.map, attrs.define_opaque);
637-
let node = node.into();
638-
self.opt_hir_owner_nodes(Some(self.tcx.arena.alloc(hir::OwnerNodes {
639-
opt_hash_including_bodies,
640-
nodes: IndexVec::from_elem_n(
641-
hir::ParentedNode { parent: hir::ItemLocalId::INVALID, node },
642-
1,
643-
),
644-
bodies,
645-
})));
646-
self.feed_owner_id().hir_attr_map(attrs);
630+
self.opt_hir_owner_nodes(Some(self.tcx.arena.alloc(hir::OwnerNodes::synthetic())));
631+
self.feed_owner_id().hir_attr_map(hir::AttributeMap::EMPTY);
647632
}
648633
}
649634

0 commit comments

Comments
 (0)