1
Fork 0

HIR: rename get_parent_node_by_hir_id to get_parent_node

This commit is contained in:
ljedrz 2019-06-24 09:46:38 +02:00
parent c7e1f4dcb7
commit d08bd72e97
21 changed files with 47 additions and 47 deletions

View file

@ -87,7 +87,7 @@ impl<'a> Code<'a> {
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)

View file

@ -347,7 +347,7 @@ impl<'hir> Map<'hir> {
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 @@ impl<'hir> Map<'hir> {
/// 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 @@ impl<'hir> Map<'hir> {
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 @@ impl<'hir> Map<'hir> {
/// 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 @@ impl<'hir> Map<'hir> {
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 @@ impl<'hir> Map<'hir> {
{
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 @@ impl<'hir> Map<'hir> {
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,

View file

@ -662,7 +662,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
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 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
// 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 {

View file

@ -938,7 +938,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
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 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
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),

View file

@ -2880,7 +2880,7 @@ impl<'tcx> TyCtxt<'tcx> {
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 @@ impl<'tcx> TyCtxt<'tcx> {
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");
}

View file

@ -47,7 +47,7 @@ pub enum PatternSource<'tcx> {
/// 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) => {

View file

@ -1189,7 +1189,7 @@ impl BorrowckCtxt<'_, 'tcx> {
}
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 @@ impl BorrowckCtxt<'_, 'tcx> {
},
)) = 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 \

View file

@ -631,7 +631,7 @@ fn print_flowgraph<'tcx, W: Write>(
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;
}

View file

@ -275,7 +275,7 @@ fn lint_int_literal<'a, 'tcx>(
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 @@ fn lint_uint_literal<'a, 'tcx>(
_ => 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(..) => {

View file

@ -909,7 +909,7 @@ fn convert_path_expr<'a, 'tcx>(
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);

View file

@ -570,7 +570,7 @@ fn is_enclosed(
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))

View file

@ -247,7 +247,7 @@ fn def_id_visibility<'tcx>(
}
}
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 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
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 @@ impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> {
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;
}

View file

@ -622,7 +622,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
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))
},
}

View file

@ -2000,7 +2000,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
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 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// 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)];

View file

@ -546,7 +546,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) {
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 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
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 {

View file

@ -244,7 +244,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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, ..), .. }),

View file

@ -1231,7 +1231,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
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 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
// 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,

View file

@ -236,13 +236,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) -> 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 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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 {

View file

@ -269,7 +269,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
} 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) {

View file

@ -4259,7 +4259,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// 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 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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, ..) => {

View file

@ -1298,7 +1298,7 @@ pub fn checked_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fail: bool) -> Op
}
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),