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

@ -115,7 +115,7 @@ fn is_parent_const_stable_trait(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
let local_def_id = def_id.expect_local(); let local_def_id = def_id.expect_local();
let hir_id = tcx.local_def_id_to_hir_id(local_def_id); let hir_id = tcx.local_def_id_to_hir_id(local_def_id);
let Some(parent) = tcx.hir().find_parent_node(hir_id) else { return false }; let Some(parent) = tcx.hir().opt_parent_id(hir_id) else { return false };
let parent_def = tcx.hir().get(parent); let parent_def = tcx.hir().get(parent);
if !matches!( if !matches!(

View file

@ -716,7 +716,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
num = num_trait_generics_except_self, num = num_trait_generics_except_self,
); );
if let Some(parent_node) = self.tcx.hir().find_parent_node(self.path_segment.hir_id) if let Some(parent_node) = self.tcx.hir().opt_parent_id(self.path_segment.hir_id)
&& let Some(parent_node) = self.tcx.hir().find(parent_node) && let Some(parent_node) = self.tcx.hir().find(parent_node)
&& let hir::Node::Expr(expr) = parent_node { && let hir::Node::Expr(expr) = parent_node {
match expr.kind { match expr.kind {

View file

@ -943,7 +943,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}) => { }) => {
// Check if our original expression is a child of the condition of a while loop // Check if our original expression is a child of the condition of a while loop
let expr_is_ancestor = std::iter::successors(Some(original_expr_id), |id| { let expr_is_ancestor = std::iter::successors(Some(original_expr_id), |id| {
self.tcx.hir().find_parent_node(*id) self.tcx.hir().opt_parent_id(*id)
}) })
.take_while(|id| *id != parent) .take_while(|id| *id != parent)
.any(|id| id == expr.hir_id); .any(|id| id == expr.hir_id);

View file

@ -140,7 +140,7 @@ impl<'tcx> expr_use_visitor::Delegate<'tcx> for ExprUseDelegate<'tcx> {
diag_expr_id: HirId, diag_expr_id: HirId,
) { ) {
let hir = self.tcx.hir(); let hir = self.tcx.hir();
let parent = match hir.find_parent_node(place_with_id.hir_id) { let parent = match hir.opt_parent_id(place_with_id.hir_id) {
Some(parent) => parent, Some(parent) => parent,
None => place_with_id.hir_id, None => place_with_id.hir_id,
}; };

View file

@ -298,7 +298,7 @@ impl<'hir> Map<'hir> {
/// Finds the id of the parent node to this one. /// Finds the id of the parent node to this one.
/// ///
/// If calling repeatedly and iterating over parents, prefer [`Map::parent_iter`]. /// 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) { if id.local_id == ItemLocalId::from_u32(0) {
Some(self.tcx.hir_owner_parent(id.owner)) Some(self.tcx.hir_owner_parent(id.owner))
} else { } else {
@ -313,7 +313,7 @@ impl<'hir> Map<'hir> {
#[track_caller] #[track_caller]
pub fn parent_id(self, hir_id: HirId) -> HirId { 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))) .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 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) { if let Some(parent_did) = tcx.hir().opt_local_def_id(parent_hir_id) {
InternalSubsts::identity_for_item(tcx, parent_did.to_def_id()) InternalSubsts::identity_for_item(tcx, parent_did.to_def_id())
} else { } else {

View file

@ -82,7 +82,7 @@ pub(crate) fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(item.item_id.expect_def_id().expect_local()); let hir_id = cx.tcx.hir().local_def_id_to_hir_id(item.item_id.expect_def_id().expect_local());
// check if parent is trait impl // check if parent is trait impl
if let Some(parent_hir_id) = cx.tcx.hir().find_parent_node(hir_id) { if let Some(parent_hir_id) = cx.tcx.hir().opt_parent_id(hir_id) {
if let Some(parent_node) = cx.tcx.hir().find(parent_hir_id) { if let Some(parent_node) = cx.tcx.hir().find(parent_hir_id) {
if matches!( if matches!(
parent_node, parent_node,

View file

@ -68,7 +68,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: &Msrv
fn is_child_of_cast(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { fn is_child_of_cast(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
let map = cx.tcx.hir(); let map = cx.tcx.hir();
if_chain! { if_chain! {
if let Some(parent_id) = map.find_parent_node(expr.hir_id); if let Some(parent_id) = map.opt_parent_id(expr.hir_id);
if let Some(parent) = map.find(parent_id); if let Some(parent) = map.find(parent_id);
then { then {
let expr = match parent { let expr = match parent {