Skip to content

Commit d08bd72

Browse files
committed
HIR: rename get_parent_node_by_hir_id to get_parent_node
1 parent c7e1f4d commit d08bd72

File tree

21 files changed

+47
-47
lines changed

21 files changed

+47
-47
lines changed

src/librustc/hir/map/blocks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'a> Code<'a> {
8787
match map.get(id) {
8888
map::Node::Block(_) => {
8989
// Use the parent, hopefully an expression node.
90-
Code::from_node(map, map.get_parent_node_by_hir_id(id))
90+
Code::from_node(map, map.get_parent_node(id))
9191
}
9292
map::Node::Expr(expr) => Some(Code::Expr(expr)),
9393
node => FnLikeNode::from_node(node).map(Code::FnLike)

src/librustc/hir/map/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl<'hir> Map<'hir> {
347347
if variant_data.ctor_hir_id().is_none() {
348348
return None;
349349
}
350-
let ctor_of = match self.find_by_hir_id(self.get_parent_node_by_hir_id(hir_id)) {
350+
let ctor_of = match self.find_by_hir_id(self.get_parent_node(hir_id)) {
351351
Some(Node::Item(..)) => def::CtorOf::Struct,
352352
Some(Node::Variant(..)) => def::CtorOf::Variant,
353353
_ => unreachable!(),
@@ -424,7 +424,7 @@ impl<'hir> Map<'hir> {
424424
/// which this is the body of, i.e., a `fn`, `const` or `static`
425425
/// item (possibly associated), a closure, or a `hir::AnonConst`.
426426
pub fn body_owner(&self, BodyId { hir_id }: BodyId) -> HirId {
427-
let parent = self.get_parent_node_by_hir_id(hir_id);
427+
let parent = self.get_parent_node(hir_id);
428428
assert!(self.lookup(parent).map_or(false, |e| e.is_body_owner(hir_id)));
429429
parent
430430
}
@@ -485,7 +485,7 @@ impl<'hir> Map<'hir> {
485485
match self.get(id) {
486486
Node::Item(&Item { node: ItemKind::Trait(..), .. }) |
487487
Node::Item(&Item { node: ItemKind::TraitAlias(..), .. }) => id,
488-
Node::GenericParam(_) => self.get_parent_node_by_hir_id(id),
488+
Node::GenericParam(_) => self.get_parent_node(id),
489489
_ => bug!("ty_param_owner: {} not a type parameter", self.node_to_string(id))
490490
}
491491
}
@@ -625,7 +625,7 @@ impl<'hir> Map<'hir> {
625625
/// never appear as the parent node. Thus, you can always walk the parent nodes
626626
/// from a node to the root of the HIR (unless you get back the same ID here,
627627
/// which can happen if the ID is not in the map itself or is just weird).
628-
pub fn get_parent_node_by_hir_id(&self, hir_id: HirId) -> HirId {
628+
pub fn get_parent_node(&self, hir_id: HirId) -> HirId {
629629
if self.dep_graph.is_fully_enabled() {
630630
let hir_id_owner = hir_id.owner;
631631
let def_path_hash = self.definitions.def_path_hash(hir_id_owner);
@@ -644,7 +644,7 @@ impl<'hir> Map<'hir> {
644644
Some(Node::Binding(_)) => (),
645645
_ => return false,
646646
}
647-
match self.find_by_hir_id(self.get_parent_node_by_hir_id(id)) {
647+
match self.find_by_hir_id(self.get_parent_node(id)) {
648648
Some(Node::Item(_)) |
649649
Some(Node::TraitItem(_)) |
650650
Some(Node::ImplItem(_)) => true,
@@ -680,7 +680,7 @@ impl<'hir> Map<'hir> {
680680
{
681681
let mut id = start_id;
682682
loop {
683-
let parent_id = self.get_parent_node_by_hir_id(id);
683+
let parent_id = self.get_parent_node(id);
684684
if parent_id == CRATE_HIR_ID {
685685
return Ok(CRATE_HIR_ID);
686686
}
@@ -1022,7 +1022,7 @@ impl<'hir> Map<'hir> {
10221022
Some(Node::Arm(arm)) => arm.span,
10231023
Some(Node::Block(block)) => block.span,
10241024
Some(Node::Ctor(..)) => match self.find_by_hir_id(
1025-
self.get_parent_node_by_hir_id(hir_id))
1025+
self.get_parent_node(hir_id))
10261026
{
10271027
Some(Node::Item(item)) => item.span,
10281028
Some(Node::Variant(variant)) => variant.span,

src/librustc/middle/resolve_lifetime.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
662662
if let Some(Region::LateBound(_, def_id, _)) = def {
663663
if let Some(hir_id) = self.tcx.hir().as_local_hir_id(def_id) {
664664
// Ensure that the parent of the def is an item, not HRTB
665-
let parent_id = self.tcx.hir().get_parent_node_by_hir_id(hir_id);
665+
let parent_id = self.tcx.hir().get_parent_node(hir_id);
666666
let parent_impl_id = hir::ImplItemId { hir_id: parent_id };
667667
let parent_trait_id = hir::TraitItemId { hir_id: parent_id };
668668
let krate = self.tcx.hir().forest.krate();
@@ -2051,7 +2051,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
20512051
// and whether there's a `self` argument (treated specially).
20522052
let mut assoc_item_kind = None;
20532053
let mut impl_self = None;
2054-
let parent = self.tcx.hir().get_parent_node_by_hir_id(output.hir_id);
2054+
let parent = self.tcx.hir().get_parent_node(output.hir_id);
20552055
let body = match self.tcx.hir().get(parent) {
20562056
// `fn` definitions and methods.
20572057
Node::Item(&hir::Item {

src/librustc/traits/error_reporting.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
938938
err: &mut DiagnosticBuilder<'tcx>,
939939
) {
940940
if let &ObligationCauseCode::VariableType(hir_id) = code {
941-
let parent_node = self.tcx.hir().get_parent_node_by_hir_id(hir_id);
941+
let parent_node = self.tcx.hir().get_parent_node(hir_id);
942942
if let Some(Node::Local(ref local)) = self.tcx.hir().find_by_hir_id(parent_node) {
943943
if let Some(ref expr) = local.init {
944944
if let hir::ExprKind::Index(_, _) = expr.node {
@@ -1013,7 +1013,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10131013
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
10141014
) {
10151015
let hir = self.tcx.hir();
1016-
let parent_node = hir.get_parent_node_by_hir_id(obligation.cause.body_id);
1016+
let parent_node = hir.get_parent_node(obligation.cause.body_id);
10171017
let node = hir.find_by_hir_id(parent_node);
10181018
if let Some(hir::Node::Item(hir::Item {
10191019
node: hir::ItemKind::Fn(decl, _, _, body_id),

src/librustc/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2880,7 +2880,7 @@ impl<'tcx> TyCtxt<'tcx> {
28802880
if lint::maybe_lint_level_root(self, id) {
28812881
return id;
28822882
}
2883-
let next = self.hir().get_parent_node_by_hir_id(id);
2883+
let next = self.hir().get_parent_node(id);
28842884
if next == id {
28852885
bug!("lint traversal reached the root of the crate");
28862886
}
@@ -2898,7 +2898,7 @@ impl<'tcx> TyCtxt<'tcx> {
28982898
if let Some(pair) = sets.level_and_source(lint, id, self.sess) {
28992899
return pair
29002900
}
2901-
let next = self.hir().get_parent_node_by_hir_id(id);
2901+
let next = self.hir().get_parent_node(id);
29022902
if next == id {
29032903
bug!("lint traversal reached the root of the crate");
29042904
}

src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub enum PatternSource<'tcx> {
4747
/// with a reference to the let
4848
fn get_pattern_source<'tcx>(tcx: TyCtxt<'tcx>, pat: &Pat) -> PatternSource<'tcx> {
4949

50-
let parent = tcx.hir().get_parent_node_by_hir_id(pat.hir_id);
50+
let parent = tcx.hir().get_parent_node(pat.hir_id);
5151

5252
match tcx.hir().get(parent) {
5353
Node::Expr(ref e) => {

src/librustc_borrowck/borrowck/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ impl BorrowckCtxt<'_, 'tcx> {
11891189
}
11901190

11911191
fn local_ty(&self, hir_id: hir::HirId) -> (Option<&hir::Ty>, bool) {
1192-
let parent = self.tcx.hir().get_parent_node_by_hir_id(hir_id);
1192+
let parent = self.tcx.hir().get_parent_node(hir_id);
11931193
let parent_node = self.tcx.hir().get(parent);
11941194

11951195
// The parent node is like a fn
@@ -1287,7 +1287,7 @@ impl BorrowckCtxt<'_, 'tcx> {
12871287
},
12881288
)) = ty.map(|t| &t.node)
12891289
{
1290-
let borrow_expr_id = self.tcx.hir().get_parent_node_by_hir_id(borrowed_hir_id);
1290+
let borrow_expr_id = self.tcx.hir().get_parent_node(borrowed_hir_id);
12911291
db.span_suggestion(
12921292
self.tcx.hir().span(borrow_expr_id),
12931293
"consider removing the `&mut`, as it is an \

src/librustc_driver/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ fn print_flowgraph<'tcx, W: Write>(
631631
if let Some(n) = hir::map::blocks::FnLikeNode::from_node(node) {
632632
break n.body();
633633
}
634-
let parent = tcx.hir().get_parent_node_by_hir_id(hir_id);
634+
let parent = tcx.hir().get_parent_node(hir_id);
635635
assert_ne!(hir_id, parent);
636636
hir_id = parent;
637637
}

src/librustc_lint/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ fn lint_int_literal<'a, 'tcx>(
275275
return;
276276
}
277277

278-
let par_id = cx.tcx.hir().get_parent_node_by_hir_id(e.hir_id);
278+
let par_id = cx.tcx.hir().get_parent_node(e.hir_id);
279279
if let Node::Expr(par_e) = cx.tcx.hir().get(par_id) {
280280
if let hir::ExprKind::Struct(..) = par_e.node {
281281
if is_range_literal(cx.sess(), par_e)
@@ -314,7 +314,7 @@ fn lint_uint_literal<'a, 'tcx>(
314314
_ => bug!(),
315315
};
316316
if lit_val < min || lit_val > max {
317-
let parent_id = cx.tcx.hir().get_parent_node_by_hir_id(e.hir_id);
317+
let parent_id = cx.tcx.hir().get_parent_node(e.hir_id);
318318
if let Node::Expr(par_e) = cx.tcx.hir().get(parent_id) {
319319
match par_e.node {
320320
hir::ExprKind::Cast(..) => {

src/librustc_mir/hair/cx/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ fn convert_path_expr<'a, 'tcx>(
909909

910910
Res::Def(DefKind::ConstParam, def_id) => {
911911
let hir_id = cx.tcx.hir().as_local_hir_id(def_id).unwrap();
912-
let item_id = cx.tcx.hir().get_parent_node_by_hir_id(hir_id);
912+
let item_id = cx.tcx.hir().get_parent_node(hir_id);
913913
let item_def_id = cx.tcx.hir().local_def_id_from_hir_id(item_id);
914914
let generics = cx.tcx.generics_of(item_def_id);
915915
let local_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);

src/librustc_mir/transform/check_unsafety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ fn is_enclosed(
570570
used_unsafe: &FxHashSet<hir::HirId>,
571571
id: hir::HirId,
572572
) -> Option<(String, hir::HirId)> {
573-
let parent_id = tcx.hir().get_parent_node_by_hir_id(id);
573+
let parent_id = tcx.hir().get_parent_node(id);
574574
if parent_id != id {
575575
if used_unsafe.contains(&parent_id) {
576576
Some(("block".to_string(), parent_id))

src/librustc_privacy/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ fn def_id_visibility<'tcx>(
247247
}
248248
}
249249
Node::Ctor(vdata) => {
250-
let parent_hir_id = tcx.hir().get_parent_node_by_hir_id(hir_id);
250+
let parent_hir_id = tcx.hir().get_parent_node(hir_id);
251251
match tcx.hir().get(parent_hir_id) {
252252
Node::Variant(..) => {
253253
let parent_did = tcx.hir().local_def_id_from_hir_id(parent_hir_id);
@@ -784,7 +784,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
784784
if module_id == hir::CRATE_HIR_ID {
785785
break
786786
}
787-
module_id = self.tcx.hir().get_parent_node_by_hir_id(module_id);
787+
module_id = self.tcx.hir().get_parent_node(module_id);
788788
}
789789
}
790790
}
@@ -1674,7 +1674,7 @@ impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> {
16741674
has_old_errors = true;
16751675
break;
16761676
}
1677-
let parent = self.tcx.hir().get_parent_node_by_hir_id(id);
1677+
let parent = self.tcx.hir().get_parent_node(id);
16781678
if parent == id {
16791679
break;
16801680
}

src/librustc_save_analysis/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
622622
match seg.res {
623623
Some(res) if res != Res::Err => res,
624624
_ => {
625-
let parent_node = self.tcx.hir().get_parent_node_by_hir_id(hir_id);
625+
let parent_node = self.tcx.hir().get_parent_node(hir_id);
626626
self.get_path_res(self.tcx.hir().hir_to_node_id(parent_node))
627627
},
628628
}

src/librustc_typeck/astconv.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2000,7 +2000,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
20002000
self.prohibit_generics(&path.segments);
20012001

20022002
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
2003-
let item_id = tcx.hir().get_parent_node_by_hir_id(hir_id);
2003+
let item_id = tcx.hir().get_parent_node(hir_id);
20042004
let item_def_id = tcx.hir().local_def_id_from_hir_id(item_id);
20052005
let generics = tcx.generics_of(item_def_id);
20062006
let index = generics.param_def_id_to_index[&def_id];
@@ -2190,7 +2190,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
21902190
// Find the name and index of the const parameter by indexing the generics of the
21912191
// parent item and construct a `ParamConst`.
21922192
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
2193-
let item_id = tcx.hir().get_parent_node_by_hir_id(hir_id);
2193+
let item_id = tcx.hir().get_parent_node(hir_id);
21942194
let item_def_id = tcx.hir().local_def_id_from_hir_id(item_id);
21952195
let generics = tcx.generics_of(item_def_id);
21962196
let index = generics.param_def_id_to_index[&tcx.hir().local_def_id_from_hir_id(hir_id)];

src/librustc_typeck/check/_match.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
546546
) {
547547
let tcx = self.tcx;
548548
if let PatKind::Binding(..) = inner.node {
549-
let parent_id = tcx.hir().get_parent_node_by_hir_id(pat.hir_id);
549+
let parent_id = tcx.hir().get_parent_node(pat.hir_id);
550550
let parent = tcx.hir().get(parent_id);
551551
debug!("inner {:?} pat {:?} parent {:?}", inner, pat, parent);
552552
match parent {
@@ -808,16 +808,16 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
808808
use hir::Node::{Block, Item, Local};
809809

810810
let hir = self.tcx.hir();
811-
let arm_id = hir.get_parent_node_by_hir_id(hir_id);
812-
let match_id = hir.get_parent_node_by_hir_id(arm_id);
813-
let containing_id = hir.get_parent_node_by_hir_id(match_id);
811+
let arm_id = hir.get_parent_node(hir_id);
812+
let match_id = hir.get_parent_node(arm_id);
813+
let containing_id = hir.get_parent_node(match_id);
814814

815815
let node = hir.get(containing_id);
816816
if let Block(block) = node {
817817
// check that the body's parent is an fn
818818
let parent = hir.get(
819-
hir.get_parent_node_by_hir_id(
820-
hir.get_parent_node_by_hir_id(block.hir_id),
819+
hir.get_parent_node(
820+
hir.get_parent_node(block.hir_id),
821821
),
822822
);
823823
if let (Some(expr), Item(hir::Item {

src/librustc_typeck/check/callee.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
244244
callee_node: &hir::ExprKind,
245245
callee_span: Span,
246246
) {
247-
let hir_id = self.tcx.hir().get_parent_node_by_hir_id(hir_id);
247+
let hir_id = self.tcx.hir().get_parent_node(hir_id);
248248
let parent_node = self.tcx.hir().get(hir_id);
249249
if let (
250250
hir::Node::Expr(hir::Expr { node: hir::ExprKind::Closure(_, _, _, sp, ..), .. }),

src/librustc_typeck/check/coercion.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
12311231
db.span_label(cause.span, "return type is not `()`");
12321232
}
12331233
ObligationCauseCode::BlockTailExpression(blk_id) => {
1234-
let parent_id = fcx.tcx.hir().get_parent_node_by_hir_id(blk_id);
1234+
let parent_id = fcx.tcx.hir().get_parent_node(blk_id);
12351235
db = self.report_return_mismatched_types(
12361236
cause,
12371237
expected,
@@ -1281,7 +1281,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
12811281
// Verify that this is a tail expression of a function, otherwise the
12821282
// label pointing out the cause for the type coercion will be wrong
12831283
// as prior return coercions would not be relevant (#57664).
1284-
let parent_id = fcx.tcx.hir().get_parent_node_by_hir_id(id);
1284+
let parent_id = fcx.tcx.hir().get_parent_node(id);
12851285
let fn_decl = if let Some((expr, blk_id)) = expression {
12861286
pointing_at_return_type = fcx.suggest_mismatched_types_on_tail(
12871287
&mut db,

src/librustc_typeck/check/demand.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
236236
) -> Option<(Span, &'static str, String)> {
237237
if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = expr.node {
238238
if let hir::def::Res::Local(id) = path.res {
239-
let parent = self.tcx.hir().get_parent_node_by_hir_id(id);
239+
let parent = self.tcx.hir().get_parent_node(id);
240240
if let Some(Node::Expr(hir::Expr {
241241
hir_id,
242242
node: hir::ExprKind::Closure(_, decl, ..),
243243
..
244244
})) = self.tcx.hir().find_by_hir_id(parent) {
245-
let parent = self.tcx.hir().get_parent_node_by_hir_id(*hir_id);
245+
let parent = self.tcx.hir().get_parent_node(*hir_id);
246246
if let (Some(Node::Expr(hir::Expr {
247247
node: hir::ExprKind::MethodCall(path, span, expr),
248248
..
@@ -276,7 +276,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
276276
sp: Span,
277277
) -> bool {
278278
let cm = self.sess().source_map();
279-
let parent_id = self.tcx.hir().get_parent_node_by_hir_id(hir_id);
279+
let parent_id = self.tcx.hir().get_parent_node(hir_id);
280280
if let Some(parent) = self.tcx.hir().find_by_hir_id(parent_id) {
281281
// Account for fields
282282
if let Node::Expr(hir::Expr {
@@ -422,7 +422,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
422422
node: hir::ExprKind::Assign(left_expr, _),
423423
..
424424
})) = self.tcx.hir().find_by_hir_id(
425-
self.tcx.hir().get_parent_node_by_hir_id(expr.hir_id),
425+
self.tcx.hir().get_parent_node(expr.hir_id),
426426
) {
427427
if mutability == hir::Mutability::MutMutable {
428428
// Found the following case:
@@ -551,7 +551,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
551551
if let Some(hir::Node::Expr(hir::Expr {
552552
node: hir::ExprKind::Struct(_, fields, _),
553553
..
554-
})) = self.tcx.hir().find_by_hir_id(self.tcx.hir().get_parent_node_by_hir_id(expr.hir_id)) {
554+
})) = self.tcx.hir().find_by_hir_id(self.tcx.hir().get_parent_node(expr.hir_id)) {
555555
// `expr` is a literal field for a struct, only suggest if appropriate
556556
for field in fields {
557557
if field.expr.hir_id == expr.hir_id && field.is_shorthand {

src/librustc_typeck/check/method/suggest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
269269
let filename = tcx.sess.source_map().span_to_filename(span);
270270

271271
let parent_node = self.tcx.hir().get(
272-
self.tcx.hir().get_parent_node_by_hir_id(hir_id),
272+
self.tcx.hir().get_parent_node(hir_id),
273273
);
274274
let msg = format!(
275275
"you must specify a type for this binding, like `{}`",
@@ -390,7 +390,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
390390
);
391391
} else {
392392
let call_expr = self.tcx.hir().expect_expr(
393-
self.tcx.hir().get_parent_node_by_hir_id(expr.hir_id),
393+
self.tcx.hir().get_parent_node(expr.hir_id),
394394
);
395395

396396
if let Some(span) = call_expr.span.trim_start(item_name.span) {

0 commit comments

Comments
 (0)