HIR: rename get_parent_node_by_hir_id to get_parent_node
diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs
index 8c5fa97..351f581 100644
--- a/src/librustc/hir/map/blocks.rs
+++ b/src/librustc/hir/map/blocks.rs
@@ -87,7 +87,7 @@
match map.get(id) {
map::Node::Block(_) => {
// Use the parent, hopefully an expression node.
- Code::from_node(map, map.get_parent_node_by_hir_id(id))
+ Code::from_node(map, map.get_parent_node(id))
}
map::Node::Expr(expr) => Some(Code::Expr(expr)),
node => FnLikeNode::from_node(node).map(Code::FnLike)
diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs
index b31941f..bb39f85 100644
--- a/src/librustc/hir/map/mod.rs
+++ b/src/librustc/hir/map/mod.rs
@@ -347,7 +347,7 @@
if variant_data.ctor_hir_id().is_none() {
return None;
}
- let ctor_of = match self.find_by_hir_id(self.get_parent_node_by_hir_id(hir_id)) {
+ let ctor_of = match self.find_by_hir_id(self.get_parent_node(hir_id)) {
Some(Node::Item(..)) => def::CtorOf::Struct,
Some(Node::Variant(..)) => def::CtorOf::Variant,
_ => unreachable!(),
@@ -424,7 +424,7 @@
/// which this is the body of, i.e., a `fn`, `const` or `static`
/// item (possibly associated), a closure, or a `hir::AnonConst`.
pub fn body_owner(&self, BodyId { hir_id }: BodyId) -> HirId {
- let parent = self.get_parent_node_by_hir_id(hir_id);
+ let parent = self.get_parent_node(hir_id);
assert!(self.lookup(parent).map_or(false, |e| e.is_body_owner(hir_id)));
parent
}
@@ -485,7 +485,7 @@
match self.get(id) {
Node::Item(&Item { node: ItemKind::Trait(..), .. }) |
Node::Item(&Item { node: ItemKind::TraitAlias(..), .. }) => id,
- Node::GenericParam(_) => self.get_parent_node_by_hir_id(id),
+ Node::GenericParam(_) => self.get_parent_node(id),
_ => bug!("ty_param_owner: {} not a type parameter", self.node_to_string(id))
}
}
@@ -625,7 +625,7 @@
/// never appear as the parent node. Thus, you can always walk the parent nodes
/// from a node to the root of the HIR (unless you get back the same ID here,
/// which can happen if the ID is not in the map itself or is just weird).
- pub fn get_parent_node_by_hir_id(&self, hir_id: HirId) -> HirId {
+ pub fn get_parent_node(&self, hir_id: HirId) -> HirId {
if self.dep_graph.is_fully_enabled() {
let hir_id_owner = hir_id.owner;
let def_path_hash = self.definitions.def_path_hash(hir_id_owner);
@@ -644,7 +644,7 @@
Some(Node::Binding(_)) => (),
_ => return false,
}
- match self.find_by_hir_id(self.get_parent_node_by_hir_id(id)) {
+ match self.find_by_hir_id(self.get_parent_node(id)) {
Some(Node::Item(_)) |
Some(Node::TraitItem(_)) |
Some(Node::ImplItem(_)) => true,
@@ -680,7 +680,7 @@
{
let mut id = start_id;
loop {
- let parent_id = self.get_parent_node_by_hir_id(id);
+ let parent_id = self.get_parent_node(id);
if parent_id == CRATE_HIR_ID {
return Ok(CRATE_HIR_ID);
}
@@ -1022,7 +1022,7 @@
Some(Node::Arm(arm)) => arm.span,
Some(Node::Block(block)) => block.span,
Some(Node::Ctor(..)) => match self.find_by_hir_id(
- self.get_parent_node_by_hir_id(hir_id))
+ self.get_parent_node(hir_id))
{
Some(Node::Item(item)) => item.span,
Some(Node::Variant(variant)) => variant.span,
diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs
index b8e7db9..ac2124f 100644
--- a/src/librustc/middle/resolve_lifetime.rs
+++ b/src/librustc/middle/resolve_lifetime.rs
@@ -662,7 +662,7 @@
if let Some(Region::LateBound(_, def_id, _)) = def {
if let Some(hir_id) = self.tcx.hir().as_local_hir_id(def_id) {
// Ensure that the parent of the def is an item, not HRTB
- let parent_id = self.tcx.hir().get_parent_node_by_hir_id(hir_id);
+ let parent_id = self.tcx.hir().get_parent_node(hir_id);
let parent_impl_id = hir::ImplItemId { hir_id: parent_id };
let parent_trait_id = hir::TraitItemId { hir_id: parent_id };
let krate = self.tcx.hir().forest.krate();
@@ -2051,7 +2051,7 @@
// and whether there's a `self` argument (treated specially).
let mut assoc_item_kind = None;
let mut impl_self = None;
- let parent = self.tcx.hir().get_parent_node_by_hir_id(output.hir_id);
+ let parent = self.tcx.hir().get_parent_node(output.hir_id);
let body = match self.tcx.hir().get(parent) {
// `fn` definitions and methods.
Node::Item(&hir::Item {
diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs
index b433098..f99d684 100644
--- a/src/librustc/traits/error_reporting.rs
+++ b/src/librustc/traits/error_reporting.rs
@@ -938,7 +938,7 @@
err: &mut DiagnosticBuilder<'tcx>,
) {
if let &ObligationCauseCode::VariableType(hir_id) = code {
- let parent_node = self.tcx.hir().get_parent_node_by_hir_id(hir_id);
+ let parent_node = self.tcx.hir().get_parent_node(hir_id);
if let Some(Node::Local(ref local)) = self.tcx.hir().find_by_hir_id(parent_node) {
if let Some(ref expr) = local.init {
if let hir::ExprKind::Index(_, _) = expr.node {
@@ -1013,7 +1013,7 @@
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
) {
let hir = self.tcx.hir();
- let parent_node = hir.get_parent_node_by_hir_id(obligation.cause.body_id);
+ let parent_node = hir.get_parent_node(obligation.cause.body_id);
let node = hir.find_by_hir_id(parent_node);
if let Some(hir::Node::Item(hir::Item {
node: hir::ItemKind::Fn(decl, _, _, body_id),
diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs
index 28399ed..45822fc 100644
--- a/src/librustc/ty/context.rs
+++ b/src/librustc/ty/context.rs
@@ -2880,7 +2880,7 @@
if lint::maybe_lint_level_root(self, id) {
return id;
}
- let next = self.hir().get_parent_node_by_hir_id(id);
+ let next = self.hir().get_parent_node(id);
if next == id {
bug!("lint traversal reached the root of the crate");
}
@@ -2898,7 +2898,7 @@
if let Some(pair) = sets.level_and_source(lint, id, self.sess) {
return pair
}
- let next = self.hir().get_parent_node_by_hir_id(id);
+ let next = self.hir().get_parent_node(id);
if next == id {
bug!("lint traversal reached the root of the crate");
}
diff --git a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs
index fa28663..658e430 100644
--- a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs
+++ b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs
@@ -47,7 +47,7 @@
/// with a reference to the let
fn get_pattern_source<'tcx>(tcx: TyCtxt<'tcx>, pat: &Pat) -> PatternSource<'tcx> {
- let parent = tcx.hir().get_parent_node_by_hir_id(pat.hir_id);
+ let parent = tcx.hir().get_parent_node(pat.hir_id);
match tcx.hir().get(parent) {
Node::Expr(ref e) => {
diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs
index 87c0b85..4ff669d 100644
--- a/src/librustc_borrowck/borrowck/mod.rs
+++ b/src/librustc_borrowck/borrowck/mod.rs
@@ -1189,7 +1189,7 @@
}
fn local_ty(&self, hir_id: hir::HirId) -> (Option<&hir::Ty>, bool) {
- let parent = self.tcx.hir().get_parent_node_by_hir_id(hir_id);
+ let parent = self.tcx.hir().get_parent_node(hir_id);
let parent_node = self.tcx.hir().get(parent);
// The parent node is like a fn
@@ -1287,7 +1287,7 @@
},
)) = ty.map(|t| &t.node)
{
- let borrow_expr_id = self.tcx.hir().get_parent_node_by_hir_id(borrowed_hir_id);
+ let borrow_expr_id = self.tcx.hir().get_parent_node(borrowed_hir_id);
db.span_suggestion(
self.tcx.hir().span(borrow_expr_id),
"consider removing the `&mut`, as it is an \
diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs
index 0301661..1b78f77 100644
--- a/src/librustc_driver/pretty.rs
+++ b/src/librustc_driver/pretty.rs
@@ -631,7 +631,7 @@
if let Some(n) = hir::map::blocks::FnLikeNode::from_node(node) {
break n.body();
}
- let parent = tcx.hir().get_parent_node_by_hir_id(hir_id);
+ let parent = tcx.hir().get_parent_node(hir_id);
assert_ne!(hir_id, parent);
hir_id = parent;
}
diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs
index 2fb534e..d0258ca 100644
--- a/src/librustc_lint/types.rs
+++ b/src/librustc_lint/types.rs
@@ -275,7 +275,7 @@
return;
}
- let par_id = cx.tcx.hir().get_parent_node_by_hir_id(e.hir_id);
+ let par_id = cx.tcx.hir().get_parent_node(e.hir_id);
if let Node::Expr(par_e) = cx.tcx.hir().get(par_id) {
if let hir::ExprKind::Struct(..) = par_e.node {
if is_range_literal(cx.sess(), par_e)
@@ -314,7 +314,7 @@
_ => bug!(),
};
if lit_val < min || lit_val > max {
- let parent_id = cx.tcx.hir().get_parent_node_by_hir_id(e.hir_id);
+ let parent_id = cx.tcx.hir().get_parent_node(e.hir_id);
if let Node::Expr(par_e) = cx.tcx.hir().get(parent_id) {
match par_e.node {
hir::ExprKind::Cast(..) => {
diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs
index 597f172..94b4f6e 100644
--- a/src/librustc_mir/hair/cx/expr.rs
+++ b/src/librustc_mir/hair/cx/expr.rs
@@ -909,7 +909,7 @@
Res::Def(DefKind::ConstParam, def_id) => {
let hir_id = cx.tcx.hir().as_local_hir_id(def_id).unwrap();
- let item_id = cx.tcx.hir().get_parent_node_by_hir_id(hir_id);
+ let item_id = cx.tcx.hir().get_parent_node(hir_id);
let item_def_id = cx.tcx.hir().local_def_id_from_hir_id(item_id);
let generics = cx.tcx.generics_of(item_def_id);
let local_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs
index 9c78d76..545336a 100644
--- a/src/librustc_mir/transform/check_unsafety.rs
+++ b/src/librustc_mir/transform/check_unsafety.rs
@@ -570,7 +570,7 @@
used_unsafe: &FxHashSet<hir::HirId>,
id: hir::HirId,
) -> Option<(String, hir::HirId)> {
- let parent_id = tcx.hir().get_parent_node_by_hir_id(id);
+ let parent_id = tcx.hir().get_parent_node(id);
if parent_id != id {
if used_unsafe.contains(&parent_id) {
Some(("block".to_string(), parent_id))
diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs
index 0fdc9ac..e95911b 100644
--- a/src/librustc_privacy/lib.rs
+++ b/src/librustc_privacy/lib.rs
@@ -247,7 +247,7 @@
}
}
Node::Ctor(vdata) => {
- let parent_hir_id = tcx.hir().get_parent_node_by_hir_id(hir_id);
+ let parent_hir_id = tcx.hir().get_parent_node(hir_id);
match tcx.hir().get(parent_hir_id) {
Node::Variant(..) => {
let parent_did = tcx.hir().local_def_id_from_hir_id(parent_hir_id);
@@ -784,7 +784,7 @@
if module_id == hir::CRATE_HIR_ID {
break
}
- module_id = self.tcx.hir().get_parent_node_by_hir_id(module_id);
+ module_id = self.tcx.hir().get_parent_node(module_id);
}
}
}
@@ -1674,7 +1674,7 @@
has_old_errors = true;
break;
}
- let parent = self.tcx.hir().get_parent_node_by_hir_id(id);
+ let parent = self.tcx.hir().get_parent_node(id);
if parent == id {
break;
}
diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs
index edee8ee..7502224 100644
--- a/src/librustc_save_analysis/lib.rs
+++ b/src/librustc_save_analysis/lib.rs
@@ -622,7 +622,7 @@
match seg.res {
Some(res) if res != Res::Err => res,
_ => {
- let parent_node = self.tcx.hir().get_parent_node_by_hir_id(hir_id);
+ let parent_node = self.tcx.hir().get_parent_node(hir_id);
self.get_path_res(self.tcx.hir().hir_to_node_id(parent_node))
},
}
diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs
index 33d9b1f..0375ad4 100644
--- a/src/librustc_typeck/astconv.rs
+++ b/src/librustc_typeck/astconv.rs
@@ -2000,7 +2000,7 @@
self.prohibit_generics(&path.segments);
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
- let item_id = tcx.hir().get_parent_node_by_hir_id(hir_id);
+ let item_id = tcx.hir().get_parent_node(hir_id);
let item_def_id = tcx.hir().local_def_id_from_hir_id(item_id);
let generics = tcx.generics_of(item_def_id);
let index = generics.param_def_id_to_index[&def_id];
@@ -2190,7 +2190,7 @@
// Find the name and index of the const parameter by indexing the generics of the
// parent item and construct a `ParamConst`.
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
- let item_id = tcx.hir().get_parent_node_by_hir_id(hir_id);
+ let item_id = tcx.hir().get_parent_node(hir_id);
let item_def_id = tcx.hir().local_def_id_from_hir_id(item_id);
let generics = tcx.generics_of(item_def_id);
let index = generics.param_def_id_to_index[&tcx.hir().local_def_id_from_hir_id(hir_id)];
diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs
index 293b68c..b435c99 100644
--- a/src/librustc_typeck/check/_match.rs
+++ b/src/librustc_typeck/check/_match.rs
@@ -546,7 +546,7 @@
) {
let tcx = self.tcx;
if let PatKind::Binding(..) = inner.node {
- let parent_id = tcx.hir().get_parent_node_by_hir_id(pat.hir_id);
+ let parent_id = tcx.hir().get_parent_node(pat.hir_id);
let parent = tcx.hir().get(parent_id);
debug!("inner {:?} pat {:?} parent {:?}", inner, pat, parent);
match parent {
@@ -808,16 +808,16 @@
use hir::Node::{Block, Item, Local};
let hir = self.tcx.hir();
- let arm_id = hir.get_parent_node_by_hir_id(hir_id);
- let match_id = hir.get_parent_node_by_hir_id(arm_id);
- let containing_id = hir.get_parent_node_by_hir_id(match_id);
+ let arm_id = hir.get_parent_node(hir_id);
+ let match_id = hir.get_parent_node(arm_id);
+ let containing_id = hir.get_parent_node(match_id);
let node = hir.get(containing_id);
if let Block(block) = node {
// check that the body's parent is an fn
let parent = hir.get(
- hir.get_parent_node_by_hir_id(
- hir.get_parent_node_by_hir_id(block.hir_id),
+ hir.get_parent_node(
+ hir.get_parent_node(block.hir_id),
),
);
if let (Some(expr), Item(hir::Item {
diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs
index 87807ad..e6999f9 100644
--- a/src/librustc_typeck/check/callee.rs
+++ b/src/librustc_typeck/check/callee.rs
@@ -244,7 +244,7 @@
callee_node: &hir::ExprKind,
callee_span: Span,
) {
- let hir_id = self.tcx.hir().get_parent_node_by_hir_id(hir_id);
+ let hir_id = self.tcx.hir().get_parent_node(hir_id);
let parent_node = self.tcx.hir().get(hir_id);
if let (
hir::Node::Expr(hir::Expr { node: hir::ExprKind::Closure(_, _, _, sp, ..), .. }),
diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs
index 71a0ca0..4bd2f21 100644
--- a/src/librustc_typeck/check/coercion.rs
+++ b/src/librustc_typeck/check/coercion.rs
@@ -1231,7 +1231,7 @@
db.span_label(cause.span, "return type is not `()`");
}
ObligationCauseCode::BlockTailExpression(blk_id) => {
- let parent_id = fcx.tcx.hir().get_parent_node_by_hir_id(blk_id);
+ let parent_id = fcx.tcx.hir().get_parent_node(blk_id);
db = self.report_return_mismatched_types(
cause,
expected,
@@ -1281,7 +1281,7 @@
// Verify that this is a tail expression of a function, otherwise the
// label pointing out the cause for the type coercion will be wrong
// as prior return coercions would not be relevant (#57664).
- let parent_id = fcx.tcx.hir().get_parent_node_by_hir_id(id);
+ let parent_id = fcx.tcx.hir().get_parent_node(id);
let fn_decl = if let Some((expr, blk_id)) = expression {
pointing_at_return_type = fcx.suggest_mismatched_types_on_tail(
&mut db,
diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs
index aff8eba..180b1ea 100644
--- a/src/librustc_typeck/check/demand.rs
+++ b/src/librustc_typeck/check/demand.rs
@@ -236,13 +236,13 @@
) -> Option<(Span, &'static str, String)> {
if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = expr.node {
if let hir::def::Res::Local(id) = path.res {
- let parent = self.tcx.hir().get_parent_node_by_hir_id(id);
+ let parent = self.tcx.hir().get_parent_node(id);
if let Some(Node::Expr(hir::Expr {
hir_id,
node: hir::ExprKind::Closure(_, decl, ..),
..
})) = self.tcx.hir().find_by_hir_id(parent) {
- let parent = self.tcx.hir().get_parent_node_by_hir_id(*hir_id);
+ let parent = self.tcx.hir().get_parent_node(*hir_id);
if let (Some(Node::Expr(hir::Expr {
node: hir::ExprKind::MethodCall(path, span, expr),
..
@@ -276,7 +276,7 @@
sp: Span,
) -> bool {
let cm = self.sess().source_map();
- let parent_id = self.tcx.hir().get_parent_node_by_hir_id(hir_id);
+ let parent_id = self.tcx.hir().get_parent_node(hir_id);
if let Some(parent) = self.tcx.hir().find_by_hir_id(parent_id) {
// Account for fields
if let Node::Expr(hir::Expr {
@@ -422,7 +422,7 @@
node: hir::ExprKind::Assign(left_expr, _),
..
})) = self.tcx.hir().find_by_hir_id(
- self.tcx.hir().get_parent_node_by_hir_id(expr.hir_id),
+ self.tcx.hir().get_parent_node(expr.hir_id),
) {
if mutability == hir::Mutability::MutMutable {
// Found the following case:
@@ -551,7 +551,7 @@
if let Some(hir::Node::Expr(hir::Expr {
node: hir::ExprKind::Struct(_, fields, _),
..
- })) = self.tcx.hir().find_by_hir_id(self.tcx.hir().get_parent_node_by_hir_id(expr.hir_id)) {
+ })) = self.tcx.hir().find_by_hir_id(self.tcx.hir().get_parent_node(expr.hir_id)) {
// `expr` is a literal field for a struct, only suggest if appropriate
for field in fields {
if field.expr.hir_id == expr.hir_id && field.is_shorthand {
diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs
index 8ad67c2..fa1b07d 100644
--- a/src/librustc_typeck/check/method/suggest.rs
+++ b/src/librustc_typeck/check/method/suggest.rs
@@ -269,7 +269,7 @@
let filename = tcx.sess.source_map().span_to_filename(span);
let parent_node = self.tcx.hir().get(
- self.tcx.hir().get_parent_node_by_hir_id(hir_id),
+ self.tcx.hir().get_parent_node(hir_id),
);
let msg = format!(
"you must specify a type for this binding, like `{}`",
@@ -390,7 +390,7 @@
);
} else {
let call_expr = self.tcx.hir().expect_expr(
- self.tcx.hir().get_parent_node_by_hir_id(expr.hir_id),
+ self.tcx.hir().get_parent_node(expr.hir_id),
);
if let Some(span) = call_expr.span.trim_start(item_name.span) {
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index 0ec5c97..2da761f 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -4259,7 +4259,7 @@
// If our calling expression is indeed the function itself, we're good!
// If not, generate an error that this can only be called directly.
if let Node::Expr(expr) = self.tcx.hir().get(
- self.tcx.hir().get_parent_node_by_hir_id(hir_id))
+ self.tcx.hir().get_parent_node(hir_id))
{
if let ExprKind::Call(ref callee, ..) = expr.node {
if callee.hir_id == hir_id {
@@ -4334,7 +4334,7 @@
let mut contained_in_place = false;
while let hir::Node::Expr(parent_expr) =
- self.tcx.hir().get(self.tcx.hir().get_parent_node_by_hir_id(expr_id))
+ self.tcx.hir().get(self.tcx.hir().get_parent_node(expr_id))
{
match &parent_expr.node {
hir::ExprKind::Assign(lhs, ..) | hir::ExprKind::AssignOp(_, lhs, ..) => {
diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs
index 301168a..87e1166 100644
--- a/src/librustc_typeck/collect.rs
+++ b/src/librustc_typeck/collect.rs
@@ -1298,7 +1298,7 @@
}
Node::AnonConst(_) => {
- let parent_node = tcx.hir().get(tcx.hir().get_parent_node_by_hir_id(hir_id));
+ let parent_node = tcx.hir().get(tcx.hir().get_parent_node(hir_id));
match parent_node {
Node::Ty(&hir::Ty {
node: hir::TyKind::Array(_, ref constant),