Rollup merge of #106403 - compiler-errors:rename-hir-methods, r=cjgillot
Rename `hir::Map::{get_,find_}parent_node` to `hir::Map::{,opt_}parent_id`, and add `hir::Map::{get,find}_parent` The `hir::Map::get_parent_node` function doesn't return a `Node`, and I think that's quite confusing. Let's rename it to something that sounds more like something that gets the parent hir id => `hir::Map::parent_id`. Same with `find_parent_node` => `opt_parent_id`. Also, combine `hir.get(hir.parent_id(hir_id))` and similar `hir.find(hir.parent_id(hir_id))` function into new functions that actually retrieve the parent node in one call. This last commit is the only one that might need to be looked at closely.
This commit is contained in:
commit
5ce6311f34
54 changed files with 170 additions and 179 deletions
|
@ -117,7 +117,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
Some(if movability.is_some() { "an async closure" } else { "a closure" })
|
||||
}),
|
||||
hir::Node::Expr(hir::Expr { .. }) => {
|
||||
let parent_hid = hir.get_parent_node(hir_id);
|
||||
let parent_hid = hir.parent_id(hir_id);
|
||||
if parent_hid != hir_id { self.describe_enclosure(parent_hid) } else { None }
|
||||
}
|
||||
_ => None,
|
||||
|
|
|
@ -838,8 +838,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
|
||||
let hir = self.tcx.hir();
|
||||
let hir_id = hir.local_def_id_to_hir_id(def_id.as_local()?);
|
||||
let parent_node = hir.get_parent_node(hir_id);
|
||||
match hir.find(parent_node) {
|
||||
match hir.find_parent(hir_id) {
|
||||
Some(hir::Node::Stmt(hir::Stmt { kind: hir::StmtKind::Local(local), .. })) => {
|
||||
get_name(err, &local.pat.kind)
|
||||
}
|
||||
|
@ -1421,7 +1420,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||
) -> bool {
|
||||
let hir = self.tcx.hir();
|
||||
let parent_node = hir.get_parent_node(obligation.cause.body_id);
|
||||
let parent_node = hir.parent_id(obligation.cause.body_id);
|
||||
let node = hir.find(parent_node);
|
||||
if let Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, _, body_id), .. })) = node
|
||||
&& let hir::ExprKind::Block(blk, _) = &hir.body(*body_id).value.kind
|
||||
|
@ -1458,7 +1457,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
|
||||
fn return_type_span(&self, obligation: &PredicateObligation<'tcx>) -> Option<Span> {
|
||||
let hir = self.tcx.hir();
|
||||
let parent_node = hir.get_parent_node(obligation.cause.body_id);
|
||||
let parent_node = hir.parent_id(obligation.cause.body_id);
|
||||
let Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, ..), .. })) = hir.find(parent_node) else {
|
||||
return None;
|
||||
};
|
||||
|
@ -1483,7 +1482,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
}
|
||||
|
||||
let hir = self.tcx.hir();
|
||||
let fn_hir_id = hir.get_parent_node(obligation.cause.body_id);
|
||||
let fn_hir_id = hir.parent_id(obligation.cause.body_id);
|
||||
let node = hir.find(fn_hir_id);
|
||||
let Some(hir::Node::Item(hir::Item {
|
||||
kind: hir::ItemKind::Fn(sig, _, body_id),
|
||||
|
@ -1695,7 +1694,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
}
|
||||
|
||||
let hir = self.tcx.hir();
|
||||
let parent_node = hir.get_parent_node(obligation.cause.body_id);
|
||||
let parent_node = hir.parent_id(obligation.cause.body_id);
|
||||
let node = hir.find(parent_node);
|
||||
if let Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, _, body_id), .. })) =
|
||||
node
|
||||
|
@ -2291,7 +2290,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
let expr = hir.expect_expr(expr_id);
|
||||
debug!("target_ty evaluated from {:?}", expr);
|
||||
|
||||
let parent = hir.get_parent_node(expr_id);
|
||||
let parent = hir.parent_id(expr_id);
|
||||
if let Some(hir::Node::Expr(e)) = hir.find(parent) {
|
||||
let parent_span = hir.span(parent);
|
||||
let parent_did = parent.owner.to_def_id();
|
||||
|
@ -2512,7 +2511,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
ObligationCauseCode::VariableType(hir_id) => {
|
||||
let parent_node = self.tcx.hir().get_parent_node(hir_id);
|
||||
let parent_node = self.tcx.hir().parent_id(hir_id);
|
||||
match self.tcx.hir().find(parent_node) {
|
||||
Some(Node::Local(hir::Local { ty: Some(ty), .. })) => {
|
||||
err.span_suggestion_verbose(
|
||||
|
@ -2992,7 +2991,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
span: Span,
|
||||
) {
|
||||
let body_hir_id = obligation.cause.body_id;
|
||||
let item_id = self.tcx.hir().get_parent_node(body_hir_id);
|
||||
let item_id = self.tcx.hir().parent_id(body_hir_id);
|
||||
|
||||
if let Some(body_id) =
|
||||
self.tcx.hir().maybe_body_owned_by(self.tcx.hir().local_def_id(item_id))
|
||||
|
@ -3219,7 +3218,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind
|
||||
&& let hir::Path { res: hir::def::Res::Local(hir_id), .. } = path
|
||||
&& let Some(hir::Node::Pat(binding)) = self.tcx.hir().find(*hir_id)
|
||||
&& let parent_hir_id = self.tcx.hir().get_parent_node(binding.hir_id)
|
||||
&& let parent_hir_id = self.tcx.hir().parent_id(binding.hir_id)
|
||||
&& let Some(hir::Node::Local(local)) = self.tcx.hir().find(parent_hir_id)
|
||||
&& let Some(binding_expr) = local.init
|
||||
{
|
||||
|
@ -3287,8 +3286,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind
|
||||
&& let hir::Path { res: hir::def::Res::Local(hir_id), .. } = path
|
||||
&& let Some(hir::Node::Pat(binding)) = self.tcx.hir().find(*hir_id)
|
||||
&& let parent_hir_id = self.tcx.hir().get_parent_node(binding.hir_id)
|
||||
&& let Some(parent) = self.tcx.hir().find(parent_hir_id)
|
||||
&& let Some(parent) = self.tcx.hir().find_parent(binding.hir_id)
|
||||
{
|
||||
// We've reached the root of the method call chain...
|
||||
if let hir::Node::Local(local) = parent
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue