hir: Remove opt_local_def_id_to_hir_id and opt_hir_node_by_def_id

Also replace a few `hir_node()` calls with `hir_node_by_def_id()`
This commit is contained in:
Vadim Petrochenkov
2024-03-14 21:05:06 +03:00
parent 30f74ff0dc
commit 89b536dbc8
37 changed files with 135 additions and 199 deletions

View File

@@ -158,12 +158,6 @@ impl<'tcx> TyCtxt<'tcx> {
self.hir_owner_nodes(owner_id).node()
}
/// Retrieves the `hir::Node` corresponding to `id`, returning `None` if cannot be found.
#[inline]
pub fn opt_hir_node_by_def_id(self, id: LocalDefId) -> Option<Node<'tcx>> {
Some(self.hir_node_by_def_id(id))
}
/// Retrieves the `hir::Node` corresponding to `id`.
pub fn hir_node(self, id: HirId) -> Node<'tcx> {
self.hir_owner_nodes(id.owner).nodes[id.local_id].node
@@ -239,8 +233,7 @@ impl<'hir> Map<'hir> {
}
pub fn get_if_local(self, id: DefId) -> Option<Node<'hir>> {
id.as_local()
.and_then(|id| Some(self.tcx.hir_node(self.tcx.opt_local_def_id_to_hir_id(id)?)))
id.as_local().map(|id| self.tcx.hir_node_by_def_id(id))
}
pub fn get_generics(self, id: LocalDefId) -> Option<&'hir Generics<'hir>> {
@@ -304,7 +297,7 @@ impl<'hir> Map<'hir> {
/// Given a `LocalDefId`, returns the `BodyId` associated with it,
/// if the node is a body owner, otherwise returns `None`.
pub fn maybe_body_owned_by(self, id: LocalDefId) -> Option<BodyId> {
let node = self.tcx.opt_hir_node_by_def_id(id)?;
let node = self.tcx.hir_node_by_def_id(id);
let (_, body_id) = associated_body(node)?;
Some(body_id)
}

View File

@@ -1265,11 +1265,9 @@ impl<'tcx> TyCtxt<'tcx> {
break (scope, ty::BrNamed(def_id.into(), self.item_name(def_id.into())));
};
let is_impl_item = match self.opt_hir_node_by_def_id(suitable_region_binding_scope) {
Some(Node::Item(..) | Node::TraitItem(..)) => false,
Some(Node::ImplItem(..)) => {
self.is_bound_region_in_impl_item(suitable_region_binding_scope)
}
let is_impl_item = match self.hir_node_by_def_id(suitable_region_binding_scope) {
Node::Item(..) | Node::TraitItem(..) => false,
Node::ImplItem(..) => self.is_bound_region_in_impl_item(suitable_region_binding_scope),
_ => false,
};
@@ -2355,10 +2353,6 @@ impl<'tcx> TyCtxt<'tcx> {
self.intrinsic_raw(def_id)
}
pub fn opt_local_def_id_to_hir_id(self, local_def_id: LocalDefId) -> Option<HirId> {
Some(self.local_def_id_to_hir_id(local_def_id))
}
pub fn next_trait_solver_globally(self) -> bool {
self.sess.opts.unstable_opts.next_solver.map_or(false, |c| c.globally)
}