Skip to content

Commit b1b19bd

Browse files
get_parent and find_parent
1 parent 6af339d commit b1b19bd

File tree

29 files changed

+86
-93
lines changed

29 files changed

+86
-93
lines changed

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3460,7 +3460,7 @@ impl<'hir> Node<'hir> {
34603460
/// ```ignore (illustrative)
34613461
/// ctor
34623462
/// .ctor_hir_id()
3463-
/// .and_then(|ctor_id| tcx.hir().find(tcx.hir().parent_id(ctor_id)))
3463+
/// .and_then(|ctor_id| tcx.hir().find_parent(ctor_id))
34643464
/// .and_then(|parent| parent.ident())
34653465
/// ```
34663466
pub fn ident(&self) -> Option<Ident> {

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2936,7 +2936,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
29362936
let hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), ident, .. }) =
29372937
hir.get(fn_hir_id) else { return None };
29382938
let hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(i), .. }) =
2939-
hir.get(hir.parent_id(fn_hir_id)) else { bug!("ImplItem should have Impl parent") };
2939+
hir.get_parent(fn_hir_id) else { bug!("ImplItem should have Impl parent") };
29402940

29412941
let trait_ref = self.instantiate_mono_trait_ref(
29422942
i.of_trait.as_ref()?,

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
11081108
ImplItem(hir::ImplItem { kind: ImplItemKind::Fn(sig, _), generics, .. }) => {
11091109
// Do not try to infer the return type for a impl method coming from a trait
11101110
if let Item(hir::Item { kind: ItemKind::Impl(i), .. }) =
1111-
tcx.hir().get(tcx.hir().parent_id(hir_id))
1111+
tcx.hir().get_parent(hir_id)
11121112
&& i.of_trait.is_some()
11131113
{
11141114
<dyn AstConv<'_>>::ty_of_fn(

compiler/rustc_hir_analysis/src/collect/generics_of.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
103103
// `min_const_generics`.
104104
Some(parent_def_id.to_def_id())
105105
} else {
106-
let parent_node = tcx.hir().get(tcx.hir().parent_id(hir_id));
106+
let parent_node = tcx.hir().get_parent(hir_id);
107107
match parent_node {
108108
// HACK(eddyb) this provides the correct generics for repeat
109109
// expressions' count (i.e. `N` in `[x; N]`), and explicit
@@ -320,7 +320,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
320320

321321
// provide junk type parameter defs for const blocks.
322322
if let Node::AnonConst(_) = node {
323-
let parent_node = tcx.hir().get(tcx.hir().parent_id(hir_id));
323+
let parent_node = tcx.hir().get_parent(hir_id);
324324
if let Node::Expr(&Expr { kind: ExprKind::ConstBlock(_), .. }) = parent_node {
325325
params.push(ty::GenericParamDef {
326326
index: next_index(),

compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
402402
}
403403

404404
Node::AnonConst(_) => {
405-
let parent_node = tcx.hir().get(tcx.hir().parent_id(hir_id));
405+
let parent_node = tcx.hir().get_parent(hir_id);
406406
match parent_node {
407407
Node::Ty(&Ty { kind: TyKind::Array(_, ref constant), .. })
408408
| Node::Expr(&Expr { kind: ExprKind::Repeat(_, ref constant), .. })
@@ -445,7 +445,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
445445
..
446446
},
447447
) if let Node::TraitRef(trait_ref) =
448-
tcx.hir().get(tcx.hir().parent_id(binding_id))
448+
tcx.hir().get_parent(binding_id)
449449
&& e.hir_id == hir_id =>
450450
{
451451
let Some(trait_def_id) = trait_ref.trait_def_id() else {
@@ -472,7 +472,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
472472
Node::TypeBinding(
473473
binding @ &TypeBinding { hir_id: binding_id, gen_args, ref kind, .. },
474474
) if let Node::TraitRef(trait_ref) =
475-
tcx.hir().get(tcx.hir().parent_id(binding_id))
475+
tcx.hir().get_parent(binding_id)
476476
&& let Some((idx, _)) =
477477
gen_args.args.iter().enumerate().find(|(_, arg)| {
478478
if let GenericArg::Const(ct) = arg {

compiler/rustc_hir_typeck/src/_match.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
294294
};
295295
if let hir::Node::Block(block) = node {
296296
// check that the body's parent is an fn
297-
let parent = self
298-
.tcx
299-
.hir()
300-
.get(self.tcx.hir().parent_id(self.tcx.hir().parent_id(block.hir_id)));
297+
let parent = self.tcx.hir().get_parent(self.tcx.hir().parent_id(block.hir_id));
301298
if let (Some(expr), hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(..), .. })) =
302299
(&block.expr, parent)
303300
{

compiler/rustc_hir_typeck/src/demand.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
258258
hir::Path { res: hir::def::Res::Local(hir_id), .. },
259259
)) => {
260260
if let Some(hir::Node::Pat(pat)) = self.tcx.hir().find(*hir_id) {
261-
let parent = self.tcx.hir().parent_id(pat.hir_id);
262261
primary_span = pat.span;
263262
secondary_span = pat.span;
264-
match self.tcx.hir().find(parent) {
263+
match self.tcx.hir().find_parent(pat.hir_id) {
265264
Some(hir::Node::Local(hir::Local { ty: Some(ty), .. })) => {
266265
primary_span = ty.span;
267266
post_message = " type";
@@ -857,7 +856,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
857856
_ => None,
858857
}?;
859858

860-
match hir.find(hir.parent_id(expr.hir_id))? {
859+
match hir.find_parent(expr.hir_id)? {
861860
Node::ExprField(field) => {
862861
if field.ident.name == local.name && field.is_shorthand {
863862
return Some(local.name);
@@ -1040,7 +1039,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10401039
if let Some(hir::Node::Expr(hir::Expr {
10411040
kind: hir::ExprKind::Assign(..),
10421041
..
1043-
})) = self.tcx.hir().find(self.tcx.hir().parent_id(expr.hir_id))
1042+
})) = self.tcx.hir().find_parent(expr.hir_id)
10441043
{
10451044
if mutability.is_mut() {
10461045
// Suppressing this diagnostic, we'll properly print it in `check_expr_assign`
@@ -1267,9 +1266,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12671266

12681267
let mut sugg = vec![];
12691268

1270-
if let Some(hir::Node::ExprField(field)) =
1271-
self.tcx.hir().find(self.tcx.hir().parent_id(expr.hir_id))
1272-
{
1269+
if let Some(hir::Node::ExprField(field)) = self.tcx.hir().find_parent(expr.hir_id) {
12731270
// `expr` is a literal field for a struct, only suggest if appropriate
12741271
if field.is_shorthand {
12751272
// This is a field literal

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10831083
// Do not suggest `if let x = y` as `==` is way more likely to be the intention.
10841084
let hir = self.tcx.hir();
10851085
if let hir::Node::Expr(hir::Expr { kind: ExprKind::If { .. }, .. }) =
1086-
hir.get(hir.parent_id(hir.parent_id(expr.hir_id)))
1086+
hir.get_parent(hir.parent_id(expr.hir_id))
10871087
{
10881088
err.span_suggestion_verbose(
10891089
expr.span.shrink_to_lo(),
@@ -2462,7 +2462,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24622462
err.span_label(field.span, "method, not a field");
24632463
let expr_is_call =
24642464
if let hir::Node::Expr(hir::Expr { kind: ExprKind::Call(callee, _args), .. }) =
2465-
self.tcx.hir().get(self.tcx.hir().parent_id(expr.hir_id))
2465+
self.tcx.hir().get_parent(expr.hir_id)
24662466
{
24672467
expr.hir_id == callee.hir_id
24682468
} else {

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,9 +1435,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14351435
pub(in super::super) fn expr_in_place(&self, mut expr_id: hir::HirId) -> bool {
14361436
let mut contained_in_place = false;
14371437

1438-
while let hir::Node::Expr(parent_expr) =
1439-
self.tcx.hir().get(self.tcx.hir().parent_id(expr_id))
1440-
{
1438+
while let hir::Node::Expr(parent_expr) = self.tcx.hir().get_parent(expr_id) {
14411439
match &parent_expr.kind {
14421440
hir::ExprKind::Assign(lhs, ..) | hir::ExprKind::AssignOp(_, lhs, ..) => {
14431441
if lhs.hir_id == expr_id {

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1803,7 +1803,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18031803
hir_id: call_hir_id,
18041804
span: call_span,
18051805
..
1806-
}) = hir.get(hir.parent_id(expr.hir_id))
1806+
}) = hir.get_parent(expr.hir_id)
18071807
&& callee.hir_id == expr.hir_id
18081808
{
18091809
if self.closure_span_overlaps_error(error, *call_span) {

0 commit comments

Comments
 (0)