1
Fork 0

rename find_parent_node to opt_parent_id

This commit is contained in:
Michael Goulet 2023-01-03 07:31:33 +00:00
parent a313ef05a7
commit 6af339dbfa
8 changed files with 9 additions and 9 deletions

View file

@ -298,7 +298,7 @@ impl<'hir> Map<'hir> {
/// Finds the id of the parent node to this one.
///
/// If calling repeatedly and iterating over parents, prefer [`Map::parent_iter`].
pub fn find_parent_node(self, id: HirId) -> Option<HirId> {
pub fn opt_parent_id(self, id: HirId) -> Option<HirId> {
if id.local_id == ItemLocalId::from_u32(0) {
Some(self.tcx.hir_owner_parent(id.owner))
} else {
@ -313,7 +313,7 @@ impl<'hir> Map<'hir> {
#[track_caller]
pub fn parent_id(self, hir_id: HirId) -> HirId {
self.find_parent_node(hir_id)
self.opt_parent_id(hir_id)
.unwrap_or_else(|| bug!("No parent for node {:?}", self.node_to_string(hir_id)))
}

View file

@ -2506,7 +2506,7 @@ impl<'tcx> ConstantKind<'tcx> {
}
let hir_id = tcx.hir().local_def_id_to_hir_id(def.did);
let parent_substs = if let Some(parent_hir_id) = tcx.hir().find_parent_node(hir_id) {
let parent_substs = if let Some(parent_hir_id) = tcx.hir().opt_parent_id(hir_id) {
if let Some(parent_did) = tcx.hir().opt_local_def_id(parent_hir_id) {
InternalSubsts::identity_for_item(tcx, parent_did.to_def_id())
} else {