Skip to content

Commit edbab30

Browse files
Rollup merge of rust-lang#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.
2 parents b6efe90 + b1b19bd commit edbab30

File tree

54 files changed

+168
-177
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+168
-177
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
394394
}
395395
}
396396
let typeck = self.infcx.tcx.typeck(self.mir_def_id());
397-
let hir_id = hir.get_parent_node(expr.hir_id);
397+
let hir_id = hir.parent_id(expr.hir_id);
398398
if let Some(parent) = hir.find(hir_id) {
399399
let (def_id, args, offset) = if let hir::Node::Expr(parent_expr) = parent
400400
&& let hir::ExprKind::MethodCall(_, _, args, _) = parent_expr.kind

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
10041004
let hir = self.infcx.tcx.hir();
10051005
let closure_id = self.mir_hir_id();
10061006
let closure_span = self.infcx.tcx.def_span(self.mir_def_id());
1007-
let fn_call_id = hir.get_parent_node(closure_id);
1007+
let fn_call_id = hir.parent_id(closure_id);
10081008
let node = hir.get(fn_call_id);
10091009
let def_id = hir.enclosing_body_owner(fn_call_id);
10101010
let mut look_at_return = true;

compiler/rustc_const_eval/src/transform/check_consts/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fn is_parent_const_stable_trait(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
115115
let local_def_id = def_id.expect_local();
116116
let hir_id = tcx.local_def_id_to_hir_id(local_def_id);
117117

118-
let Some(parent) = tcx.hir().find_parent_node(hir_id) else { return false };
118+
let Some(parent) = tcx.hir().opt_parent_id(hir_id) else { return false };
119119
let parent_def = tcx.hir().get(parent);
120120

121121
if !matches!(

compiler/rustc_hir/src/hir.rs

+1-1
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().get_parent_node(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

+1-1
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.get_parent_node(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

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ pub(crate) fn placeholder_type_error_diag<'tcx>(
213213
is_fn = true;
214214

215215
// Check if parent is const or static
216-
let parent_id = tcx.hir().get_parent_node(hir_ty.hir_id);
216+
let parent_id = tcx.hir().parent_id(hir_ty.hir_id);
217217
let parent_node = tcx.hir().get(parent_id);
218218

219219
is_const_or_static = matches!(
@@ -1109,7 +1109,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
11091109
ImplItem(hir::ImplItem { kind: ImplItemKind::Fn(sig, _), generics, .. }) => {
11101110
// Do not try to infer the return type for a impl method coming from a trait
11111111
if let Item(hir::Item { kind: ItemKind::Impl(i), .. }) =
1112-
tcx.hir().get(tcx.hir().get_parent_node(hir_id))
1112+
tcx.hir().get_parent(hir_id)
11131113
&& i.of_trait.is_some()
11141114
{
11151115
<dyn AstConv<'_>>::ty_of_fn(

compiler/rustc_hir_analysis/src/collect/generics_of.rs

+2-2
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().get_parent_node(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().get_parent_node(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/lifetimes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
682682
};
683683
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
684684
// Ensure that the parent of the def is an item, not HRTB
685-
let parent_id = self.tcx.hir().get_parent_node(hir_id);
685+
let parent_id = self.tcx.hir().parent_id(hir_id);
686686
if !parent_id.is_owner() {
687687
struct_span_err!(
688688
self.tcx.sess,

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
270270
// We create bi-directional Outlives predicates between the original
271271
// and the duplicated parameter, to ensure that they do not get out of sync.
272272
if let Node::Item(&Item { kind: ItemKind::OpaqueTy(..), .. }) = node {
273-
let opaque_ty_id = tcx.hir().get_parent_node(hir_id);
273+
let opaque_ty_id = tcx.hir().parent_id(hir_id);
274274
let opaque_ty_node = tcx.hir().get(opaque_ty_id);
275275
let Node::Ty(&Ty { kind: TyKind::OpaqueDef(_, lifetimes, _), .. }) = opaque_ty_node else {
276276
bug!("unexpected {opaque_ty_node:?}")

compiler/rustc_hir_analysis/src/collect/type_of.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
2828
_ => return None,
2929
};
3030

31-
let parent_node_id = tcx.hir().get_parent_node(hir_id);
31+
let parent_node_id = tcx.hir().parent_id(hir_id);
3232
let parent_node = tcx.hir().get(parent_node_id);
3333

3434
let (generics, arg_idx) = match parent_node {
@@ -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().get_parent_node(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().get_parent_node(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().get_parent_node(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_analysis/src/structured_errors/wrong_number_of_generic_args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
716716
num = num_trait_generics_except_self,
717717
);
718718

719-
if let Some(parent_node) = self.tcx.hir().find_parent_node(self.path_segment.hir_id)
719+
if let Some(parent_node) = self.tcx.hir().opt_parent_id(self.path_segment.hir_id)
720720
&& let Some(parent_node) = self.tcx.hir().find(parent_node)
721721
&& let hir::Node::Expr(expr) = parent_node {
722722
match expr.kind {

compiler/rustc_hir_typeck/src/_match.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
289289

290290
fn maybe_get_coercion_reason(&self, hir_id: hir::HirId, sp: Span) -> Option<(Span, String)> {
291291
let node = {
292-
let rslt = self.tcx.hir().get_parent_node(self.tcx.hir().get_parent_node(hir_id));
292+
let rslt = self.tcx.hir().parent_id(self.tcx.hir().parent_id(hir_id));
293293
self.tcx.hir().get(rslt)
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().get_parent_node(self.tcx.hir().get_parent_node(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/callee.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
288288
callee_span: Span,
289289
) {
290290
let hir = self.tcx.hir();
291-
let parent_hir_id = hir.get_parent_node(hir_id);
291+
let parent_hir_id = hir.parent_id(hir_id);
292292
let parent_node = hir.get(parent_hir_id);
293293
if let (
294294
hir::Node::Expr(hir::Expr {
@@ -303,7 +303,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
303303
{
304304
// Actually need to unwrap a few more layers of HIR to get to
305305
// the _real_ closure...
306-
let async_closure = hir.get_parent_node(hir.get_parent_node(parent_hir_id));
306+
let async_closure = hir.parent_id(hir.parent_id(parent_hir_id));
307307
if let hir::Node::Expr(hir::Expr {
308308
kind: hir::ExprKind::Closure(&hir::Closure { fn_decl_span, .. }),
309309
..
@@ -336,7 +336,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
336336
call_expr: &'tcx hir::Expr<'tcx>,
337337
callee_expr: &'tcx hir::Expr<'tcx>,
338338
) -> bool {
339-
let hir_id = self.tcx.hir().get_parent_node(call_expr.hir_id);
339+
let hir_id = self.tcx.hir().parent_id(call_expr.hir_id);
340340
let parent_node = self.tcx.hir().get(hir_id);
341341
if let (
342342
hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Array(_), .. }),

compiler/rustc_hir_typeck/src/coercion.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15471547
err.span_label(cause.span, "return type is not `()`");
15481548
}
15491549
ObligationCauseCode::BlockTailExpression(blk_id) => {
1550-
let parent_id = fcx.tcx.hir().get_parent_node(blk_id);
1550+
let parent_id = fcx.tcx.hir().parent_id(blk_id);
15511551
err = self.report_return_mismatched_types(
15521552
cause,
15531553
expected,
@@ -1578,7 +1578,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15781578
None,
15791579
);
15801580
if !fcx.tcx.features().unsized_locals {
1581-
let id = fcx.tcx.hir().get_parent_node(id);
1581+
let id = fcx.tcx.hir().parent_id(id);
15821582
unsized_return = self.is_return_ty_unsized(fcx, id);
15831583
}
15841584
}
@@ -1668,7 +1668,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
16681668
let mut pointing_at_return_type = false;
16691669
let mut fn_output = None;
16701670

1671-
let parent_id = fcx.tcx.hir().get_parent_node(id);
1671+
let parent_id = fcx.tcx.hir().parent_id(id);
16721672
let parent = fcx.tcx.hir().get(parent_id);
16731673
if let Some(expr) = expression
16741674
&& let hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(&hir::Closure { body, .. }), .. }) = parent

compiler/rustc_hir_typeck/src/demand.rs

+12-15
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
430430
expr: &hir::Expr<'_>,
431431
error: Option<TypeError<'tcx>>,
432432
) {
433-
let parent = self.tcx.hir().get_parent_node(expr.hir_id);
433+
let parent = self.tcx.hir().parent_id(expr.hir_id);
434434
match (self.tcx.hir().find(parent), error) {
435435
(Some(hir::Node::Local(hir::Local { ty: Some(ty), init: Some(init), .. })), _)
436436
if init.hir_id == expr.hir_id =>
@@ -477,10 +477,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
477477
hir::Path { res: hir::def::Res::Local(hir_id), .. },
478478
)) => {
479479
if let Some(hir::Node::Pat(pat)) = self.tcx.hir().find(*hir_id) {
480-
let parent = self.tcx.hir().get_parent_node(pat.hir_id);
481480
primary_span = pat.span;
482481
secondary_span = pat.span;
483-
match self.tcx.hir().find(parent) {
482+
match self.tcx.hir().find_parent(pat.hir_id) {
484483
Some(hir::Node::Local(hir::Local { ty: Some(ty), .. })) => {
485484
primary_span = ty.span;
486485
post_message = " type";
@@ -545,7 +544,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
545544
expr: &hir::Expr<'_>,
546545
error: Option<TypeError<'tcx>>,
547546
) {
548-
let parent = self.tcx.hir().get_parent_node(expr.hir_id);
547+
let parent = self.tcx.hir().parent_id(expr.hir_id);
549548
let Some(TypeError::Sorts(ExpectedFound { expected, .. })) = error else {return;};
550549
let Some(hir::Node::Expr(hir::Expr {
551550
kind: hir::ExprKind::Assign(lhs, rhs, _), ..
@@ -729,7 +728,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
729728

730729
// Unroll desugaring, to make sure this works for `for` loops etc.
731730
loop {
732-
parent = self.tcx.hir().get_parent_node(id);
731+
parent = self.tcx.hir().parent_id(id);
733732
if let Some(parent_span) = self.tcx.hir().opt_span(parent) {
734733
if parent_span.find_ancestor_inside(expr.span).is_some() {
735734
// The parent node is part of the same span, so is the result of the
@@ -1009,12 +1008,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10091008
return None;
10101009
};
10111010

1012-
let local_parent = self.tcx.hir().get_parent_node(local_id);
1011+
let local_parent = self.tcx.hir().parent_id(local_id);
10131012
let Some(Node::Param(hir::Param { hir_id: param_hir_id, .. })) = self.tcx.hir().find(local_parent) else {
10141013
return None;
10151014
};
10161015

1017-
let param_parent = self.tcx.hir().get_parent_node(*param_hir_id);
1016+
let param_parent = self.tcx.hir().parent_id(*param_hir_id);
10181017
let Some(Node::Expr(hir::Expr {
10191018
hir_id: expr_hir_id,
10201019
kind: hir::ExprKind::Closure(hir::Closure { fn_decl: closure_fn_decl, .. }),
@@ -1023,7 +1022,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10231022
return None;
10241023
};
10251024

1026-
let expr_parent = self.tcx.hir().get_parent_node(*expr_hir_id);
1025+
let expr_parent = self.tcx.hir().parent_id(*expr_hir_id);
10271026
let hir = self.tcx.hir().find(expr_parent);
10281027
let closure_params_len = closure_fn_decl.inputs.len();
10291028
let (
@@ -1076,7 +1075,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10761075
_ => None,
10771076
}?;
10781077

1079-
match hir.find(hir.get_parent_node(expr.hir_id))? {
1078+
match hir.find_parent(expr.hir_id)? {
10801079
Node::ExprField(field) => {
10811080
if field.ident.name == local.name && field.is_shorthand {
10821081
return Some(local.name);
@@ -1102,7 +1101,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11021101
/// Returns whether the given expression is an `else if`.
11031102
pub(crate) fn is_else_if_block(&self, expr: &hir::Expr<'_>) -> bool {
11041103
if let hir::ExprKind::If(..) = expr.kind {
1105-
let parent_id = self.tcx.hir().get_parent_node(expr.hir_id);
1104+
let parent_id = self.tcx.hir().parent_id(expr.hir_id);
11061105
if let Some(Node::Expr(hir::Expr {
11071106
kind: hir::ExprKind::If(_, _, Some(else_expr)),
11081107
..
@@ -1259,7 +1258,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12591258
if let Some(hir::Node::Expr(hir::Expr {
12601259
kind: hir::ExprKind::Assign(..),
12611260
..
1262-
})) = self.tcx.hir().find(self.tcx.hir().get_parent_node(expr.hir_id))
1261+
})) = self.tcx.hir().find_parent(expr.hir_id)
12631262
{
12641263
if mutability.is_mut() {
12651264
// Suppressing this diagnostic, we'll properly print it in `check_expr_assign`
@@ -1486,9 +1485,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14861485

14871486
let mut sugg = vec![];
14881487

1489-
if let Some(hir::Node::ExprField(field)) =
1490-
self.tcx.hir().find(self.tcx.hir().get_parent_node(expr.hir_id))
1491-
{
1488+
if let Some(hir::Node::ExprField(field)) = self.tcx.hir().find_parent(expr.hir_id) {
14921489
// `expr` is a literal field for a struct, only suggest if appropriate
14931490
if field.is_shorthand {
14941491
// This is a field literal
@@ -1844,7 +1841,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18441841
[start, end],
18451842
_,
18461843
) = expr.kind else { return; };
1847-
let parent = self.tcx.hir().get_parent_node(expr.hir_id);
1844+
let parent = self.tcx.hir().parent_id(expr.hir_id);
18481845
if let Some(hir::Node::ExprField(_)) = self.tcx.hir().find(parent) {
18491846
// Ignore `Foo { field: a..Default::default() }`
18501847
return;

compiler/rustc_hir_typeck/src/expr.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
921921
original_expr_id: HirId,
922922
then: impl FnOnce(&hir::Expr<'_>),
923923
) {
924-
let mut parent = self.tcx.hir().get_parent_node(original_expr_id);
924+
let mut parent = self.tcx.hir().parent_id(original_expr_id);
925925
while let Some(node) = self.tcx.hir().find(parent) {
926926
match node {
927927
hir::Node::Expr(hir::Expr {
@@ -944,7 +944,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
944944
}) => {
945945
// Check if our original expression is a child of the condition of a while loop
946946
let expr_is_ancestor = std::iter::successors(Some(original_expr_id), |id| {
947-
self.tcx.hir().find_parent_node(*id)
947+
self.tcx.hir().opt_parent_id(*id)
948948
})
949949
.take_while(|id| *id != parent)
950950
.any(|id| id == expr.hir_id);
@@ -960,7 +960,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
960960
| hir::Node::TraitItem(_)
961961
| hir::Node::Crate(_) => break,
962962
_ => {
963-
parent = self.tcx.hir().get_parent_node(parent);
963+
parent = self.tcx.hir().parent_id(parent);
964964
}
965965
}
966966
}
@@ -1084,7 +1084,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10841084
// Do not suggest `if let x = y` as `==` is way more likely to be the intention.
10851085
let hir = self.tcx.hir();
10861086
if let hir::Node::Expr(hir::Expr { kind: ExprKind::If { .. }, .. }) =
1087-
hir.get(hir.get_parent_node(hir.get_parent_node(expr.hir_id)))
1087+
hir.get_parent(hir.parent_id(expr.hir_id))
10881088
{
10891089
err.span_suggestion_verbose(
10901090
expr.span.shrink_to_lo(),
@@ -2463,7 +2463,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24632463
err.span_label(field.span, "method, not a field");
24642464
let expr_is_call =
24652465
if let hir::Node::Expr(hir::Expr { kind: ExprKind::Call(callee, _args), .. }) =
2466-
self.tcx.hir().get(self.tcx.hir().get_parent_node(expr.hir_id))
2466+
self.tcx.hir().get_parent(expr.hir_id)
24672467
{
24682468
expr.hir_id == callee.hir_id
24692469
} else {

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+1-3
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().get_parent_node(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 {

0 commit comments

Comments
 (0)