Get rid of the hir_owner query.
This commit is contained in:
parent
92f2e0aa62
commit
b99c3ae6d6
7 changed files with 42 additions and 77 deletions
|
@ -1,4 +1,4 @@
|
|||
use crate::hir::{ModuleItems, Owner};
|
||||
use crate::hir::ModuleItems;
|
||||
use crate::middle::debugger_visualizer::DebuggerVisualizerFile;
|
||||
use crate::query::LocalCrate;
|
||||
use crate::ty::TyCtxt;
|
||||
|
@ -108,7 +108,7 @@ impl<'hir> Iterator for ParentOwnerIterator<'hir> {
|
|||
if self.current_id.local_id.index() != 0 {
|
||||
self.current_id.local_id = ItemLocalId::new(0);
|
||||
if let Some(node) = self.map.tcx.hir_owner(self.current_id.owner) {
|
||||
return Some((self.current_id.owner, node.node));
|
||||
return Some((self.current_id.owner, node));
|
||||
}
|
||||
}
|
||||
if self.current_id == CRATE_HIR_ID {
|
||||
|
@ -126,23 +126,23 @@ impl<'hir> Iterator for ParentOwnerIterator<'hir> {
|
|||
|
||||
// If this `HirId` doesn't have an entry, skip it and look for its `parent_id`.
|
||||
if let Some(node) = self.map.tcx.hir_owner(self.current_id.owner) {
|
||||
return Some((self.current_id.owner, node.node));
|
||||
return Some((self.current_id.owner, node));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TyCtxt<'tcx> {
|
||||
#[inline]
|
||||
fn hir_owner(self, owner: OwnerId) -> Option<OwnerNode<'tcx>> {
|
||||
Some(self.hir_owner_nodes(owner).as_owner()?.node())
|
||||
}
|
||||
|
||||
/// Retrieves the `hir::Node` corresponding to `id`, returning `None` if cannot be found.
|
||||
pub fn opt_hir_node(self, id: HirId) -> Option<Node<'tcx>> {
|
||||
if id.local_id == ItemLocalId::from_u32(0) {
|
||||
let owner = self.hir_owner(id.owner)?;
|
||||
Some(owner.node.into())
|
||||
} else {
|
||||
let owner = self.hir_owner_nodes(id.owner).as_owner()?;
|
||||
let node = owner.nodes[id.local_id].as_ref()?;
|
||||
Some(node.node)
|
||||
}
|
||||
let owner = self.hir_owner_nodes(id.owner).as_owner()?;
|
||||
let node = owner.nodes[id.local_id].as_ref()?;
|
||||
Some(node.node)
|
||||
}
|
||||
|
||||
/// Retrieves the `hir::Node` corresponding to `id`, returning `None` if cannot be found.
|
||||
|
@ -174,7 +174,7 @@ impl<'hir> Map<'hir> {
|
|||
|
||||
#[inline]
|
||||
pub fn root_module(self) -> &'hir Mod<'hir> {
|
||||
match self.tcx.hir_owner(CRATE_OWNER_ID).map(|o| o.node) {
|
||||
match self.tcx.hir_owner(CRATE_OWNER_ID) {
|
||||
Some(OwnerNode::Crate(item)) => item,
|
||||
_ => bug!(),
|
||||
}
|
||||
|
@ -242,27 +242,27 @@ impl<'hir> Map<'hir> {
|
|||
|
||||
pub fn get_generics(self, id: LocalDefId) -> Option<&'hir Generics<'hir>> {
|
||||
let node = self.tcx.hir_owner(OwnerId { def_id: id })?;
|
||||
node.node.generics()
|
||||
node.generics()
|
||||
}
|
||||
|
||||
pub fn owner(self, id: OwnerId) -> OwnerNode<'hir> {
|
||||
self.tcx.hir_owner(id).unwrap_or_else(|| bug!("expected owner for {:?}", id)).node
|
||||
self.tcx.hir_owner(id).unwrap_or_else(|| bug!("expected owner for {:?}", id))
|
||||
}
|
||||
|
||||
pub fn item(self, id: ItemId) -> &'hir Item<'hir> {
|
||||
self.tcx.hir_owner(id.owner_id).unwrap().node.expect_item()
|
||||
self.tcx.hir_owner(id.owner_id).unwrap().expect_item()
|
||||
}
|
||||
|
||||
pub fn trait_item(self, id: TraitItemId) -> &'hir TraitItem<'hir> {
|
||||
self.tcx.hir_owner(id.owner_id).unwrap().node.expect_trait_item()
|
||||
self.tcx.hir_owner(id.owner_id).unwrap().expect_trait_item()
|
||||
}
|
||||
|
||||
pub fn impl_item(self, id: ImplItemId) -> &'hir ImplItem<'hir> {
|
||||
self.tcx.hir_owner(id.owner_id).unwrap().node.expect_impl_item()
|
||||
self.tcx.hir_owner(id.owner_id).unwrap().expect_impl_item()
|
||||
}
|
||||
|
||||
pub fn foreign_item(self, id: ForeignItemId) -> &'hir ForeignItem<'hir> {
|
||||
self.tcx.hir_owner(id.owner_id).unwrap().node.expect_foreign_item()
|
||||
self.tcx.hir_owner(id.owner_id).unwrap().expect_foreign_item()
|
||||
}
|
||||
|
||||
pub fn body(self, id: BodyId) -> &'hir Body<'hir> {
|
||||
|
@ -436,7 +436,7 @@ impl<'hir> Map<'hir> {
|
|||
|
||||
pub fn get_module(self, module: LocalModDefId) -> (&'hir Mod<'hir>, Span, HirId) {
|
||||
let hir_id = HirId::make_owner(module.to_local_def_id());
|
||||
match self.tcx.hir_owner(hir_id.owner).map(|o| o.node) {
|
||||
match self.tcx.hir_owner(hir_id.owner) {
|
||||
Some(OwnerNode::Item(&Item { span, kind: ItemKind::Mod(m), .. })) => (m, span, hir_id),
|
||||
Some(OwnerNode::Crate(item)) => (item, item.spans.inner_span, hir_id),
|
||||
node => panic!("not a module: {node:?}"),
|
||||
|
@ -726,11 +726,10 @@ impl<'hir> Map<'hir> {
|
|||
|
||||
pub fn get_foreign_abi(self, hir_id: HirId) -> Abi {
|
||||
let parent = self.get_parent_item(hir_id);
|
||||
if let Some(node) = self.tcx.hir_owner(parent) {
|
||||
if let OwnerNode::Item(Item { kind: ItemKind::ForeignMod { abi, .. }, .. }) = node.node
|
||||
{
|
||||
return *abi;
|
||||
}
|
||||
if let Some(node) = self.tcx.hir_owner(parent)
|
||||
&& let OwnerNode::Item(Item { kind: ItemKind::ForeignMod { abi, .. }, .. }) = node
|
||||
{
|
||||
return *abi;
|
||||
}
|
||||
bug!(
|
||||
"expected foreign mod or inlined parent, found {}",
|
||||
|
@ -742,33 +741,32 @@ impl<'hir> Map<'hir> {
|
|||
self.tcx
|
||||
.hir_owner(OwnerId { def_id })
|
||||
.unwrap_or_else(|| bug!("expected owner for {:?}", def_id))
|
||||
.node
|
||||
}
|
||||
|
||||
pub fn expect_item(self, id: LocalDefId) -> &'hir Item<'hir> {
|
||||
match self.tcx.hir_owner(OwnerId { def_id: id }) {
|
||||
Some(Owner { node: OwnerNode::Item(item), .. }) => item,
|
||||
Some(OwnerNode::Item(item)) => item,
|
||||
_ => bug!("expected item, found {}", self.node_to_string(HirId::make_owner(id))),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_impl_item(self, id: LocalDefId) -> &'hir ImplItem<'hir> {
|
||||
match self.tcx.hir_owner(OwnerId { def_id: id }) {
|
||||
Some(Owner { node: OwnerNode::ImplItem(item), .. }) => item,
|
||||
Some(OwnerNode::ImplItem(item)) => item,
|
||||
_ => bug!("expected impl item, found {}", self.node_to_string(HirId::make_owner(id))),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_trait_item(self, id: LocalDefId) -> &'hir TraitItem<'hir> {
|
||||
match self.tcx.hir_owner(OwnerId { def_id: id }) {
|
||||
Some(Owner { node: OwnerNode::TraitItem(item), .. }) => item,
|
||||
Some(OwnerNode::TraitItem(item)) => item,
|
||||
_ => bug!("expected trait item, found {}", self.node_to_string(HirId::make_owner(id))),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_fn_output(self, def_id: LocalDefId) -> Option<&'hir FnRetTy<'hir>> {
|
||||
match self.tcx.hir_owner(OwnerId { def_id }) {
|
||||
Some(Owner { node, .. }) => node.fn_decl().map(|fn_decl| &fn_decl.output),
|
||||
Some(node) => node.fn_decl().map(|fn_decl| &fn_decl.output),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -782,7 +780,7 @@ impl<'hir> Map<'hir> {
|
|||
|
||||
pub fn expect_foreign_item(self, id: OwnerId) -> &'hir ForeignItem<'hir> {
|
||||
match self.tcx.hir_owner(id) {
|
||||
Some(Owner { node: OwnerNode::ForeignItem(item), .. }) => item,
|
||||
Some(OwnerNode::ForeignItem(item)) => item,
|
||||
_ => {
|
||||
bug!(
|
||||
"expected foreign item, found {}",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue