1
Fork 0

rename get_parent_node to parent_id

This commit is contained in:
Michael Goulet 2023-01-03 07:31:04 +00:00
parent c7572670a1
commit a313ef05a7
48 changed files with 119 additions and 121 deletions

View file

@ -394,7 +394,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
} }
} }
let typeck = self.infcx.tcx.typeck(self.mir_def_id()); let typeck = self.infcx.tcx.typeck(self.mir_def_id());
let hir_id = hir.get_parent_node(expr.hir_id); let hir_id = hir.parent_id(expr.hir_id);
if let Some(parent) = hir.find(hir_id) { if let Some(parent) = hir.find(hir_id) {
let (def_id, args, offset) = if let hir::Node::Expr(parent_expr) = parent let (def_id, args, offset) = if let hir::Node::Expr(parent_expr) = parent
&& let hir::ExprKind::MethodCall(_, _, args, _) = parent_expr.kind && let hir::ExprKind::MethodCall(_, _, args, _) = parent_expr.kind

View file

@ -1004,7 +1004,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let hir = self.infcx.tcx.hir(); let hir = self.infcx.tcx.hir();
let closure_id = self.mir_hir_id(); let closure_id = self.mir_hir_id();
let closure_span = self.infcx.tcx.def_span(self.mir_def_id()); let closure_span = self.infcx.tcx.def_span(self.mir_def_id());
let fn_call_id = hir.get_parent_node(closure_id); let fn_call_id = hir.parent_id(closure_id);
let node = hir.get(fn_call_id); let node = hir.get(fn_call_id);
let def_id = hir.enclosing_body_owner(fn_call_id); let def_id = hir.enclosing_body_owner(fn_call_id);
let mut look_at_return = true; let mut look_at_return = true;

View file

@ -3460,7 +3460,7 @@ impl<'hir> Node<'hir> {
/// ```ignore (illustrative) /// ```ignore (illustrative)
/// ctor /// ctor
/// .ctor_hir_id() /// .ctor_hir_id()
/// .and_then(|ctor_id| tcx.hir().find(tcx.hir().get_parent_node(ctor_id))) /// .and_then(|ctor_id| tcx.hir().find(tcx.hir().parent_id(ctor_id)))
/// .and_then(|parent| parent.ident()) /// .and_then(|parent| parent.ident())
/// ``` /// ```
pub fn ident(&self) -> Option<Ident> { pub fn ident(&self) -> Option<Ident> {

View file

@ -2936,7 +2936,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), ident, .. }) = let hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), ident, .. }) =
hir.get(fn_hir_id) else { return None }; hir.get(fn_hir_id) else { return None };
let hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(i), .. }) = let hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(i), .. }) =
hir.get(hir.get_parent_node(fn_hir_id)) else { bug!("ImplItem should have Impl parent") }; hir.get(hir.parent_id(fn_hir_id)) else { bug!("ImplItem should have Impl parent") };
let trait_ref = self.instantiate_mono_trait_ref( let trait_ref = self.instantiate_mono_trait_ref(
i.of_trait.as_ref()?, i.of_trait.as_ref()?,

View file

@ -212,7 +212,7 @@ pub(crate) fn placeholder_type_error_diag<'tcx>(
is_fn = true; is_fn = true;
// Check if parent is const or static // Check if parent is const or static
let parent_id = tcx.hir().get_parent_node(hir_ty.hir_id); let parent_id = tcx.hir().parent_id(hir_ty.hir_id);
let parent_node = tcx.hir().get(parent_id); let parent_node = tcx.hir().get(parent_id);
is_const_or_static = matches!( is_const_or_static = matches!(
@ -1108,7 +1108,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
ImplItem(hir::ImplItem { kind: ImplItemKind::Fn(sig, _), generics, .. }) => { ImplItem(hir::ImplItem { kind: ImplItemKind::Fn(sig, _), generics, .. }) => {
// Do not try to infer the return type for a impl method coming from a trait // Do not try to infer the return type for a impl method coming from a trait
if let Item(hir::Item { kind: ItemKind::Impl(i), .. }) = if let Item(hir::Item { kind: ItemKind::Impl(i), .. }) =
tcx.hir().get(tcx.hir().get_parent_node(hir_id)) tcx.hir().get(tcx.hir().parent_id(hir_id))
&& i.of_trait.is_some() && i.of_trait.is_some()
{ {
<dyn AstConv<'_>>::ty_of_fn( <dyn AstConv<'_>>::ty_of_fn(

View file

@ -103,7 +103,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
// `min_const_generics`. // `min_const_generics`.
Some(parent_def_id.to_def_id()) Some(parent_def_id.to_def_id())
} else { } else {
let parent_node = tcx.hir().get(tcx.hir().get_parent_node(hir_id)); let parent_node = tcx.hir().get(tcx.hir().parent_id(hir_id));
match parent_node { match parent_node {
// HACK(eddyb) this provides the correct generics for repeat // HACK(eddyb) this provides the correct generics for repeat
// expressions' count (i.e. `N` in `[x; N]`), and explicit // 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 {
// provide junk type parameter defs for const blocks. // provide junk type parameter defs for const blocks.
if let Node::AnonConst(_) = node { if let Node::AnonConst(_) = node {
let parent_node = tcx.hir().get(tcx.hir().get_parent_node(hir_id)); let parent_node = tcx.hir().get(tcx.hir().parent_id(hir_id));
if let Node::Expr(&Expr { kind: ExprKind::ConstBlock(_), .. }) = parent_node { if let Node::Expr(&Expr { kind: ExprKind::ConstBlock(_), .. }) = parent_node {
params.push(ty::GenericParamDef { params.push(ty::GenericParamDef {
index: next_index(), index: next_index(),

View file

@ -682,7 +682,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
}; };
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id); let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
// Ensure that the parent of the def is an item, not HRTB // Ensure that the parent of the def is an item, not HRTB
let parent_id = self.tcx.hir().get_parent_node(hir_id); let parent_id = self.tcx.hir().parent_id(hir_id);
if !parent_id.is_owner() { if !parent_id.is_owner() {
struct_span_err!( struct_span_err!(
self.tcx.sess, self.tcx.sess,

View file

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

View file

@ -28,7 +28,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
_ => return None, _ => return None,
}; };
let parent_node_id = tcx.hir().get_parent_node(hir_id); let parent_node_id = tcx.hir().parent_id(hir_id);
let parent_node = tcx.hir().get(parent_node_id); let parent_node = tcx.hir().get(parent_node_id);
let (generics, arg_idx) = match parent_node { let (generics, arg_idx) = match parent_node {
@ -402,7 +402,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
} }
Node::AnonConst(_) => { Node::AnonConst(_) => {
let parent_node = tcx.hir().get(tcx.hir().get_parent_node(hir_id)); let parent_node = tcx.hir().get(tcx.hir().parent_id(hir_id));
match parent_node { match parent_node {
Node::Ty(&Ty { kind: TyKind::Array(_, ref constant), .. }) Node::Ty(&Ty { kind: TyKind::Array(_, ref constant), .. })
| Node::Expr(&Expr { kind: ExprKind::Repeat(_, ref constant), .. }) | Node::Expr(&Expr { kind: ExprKind::Repeat(_, ref constant), .. })
@ -445,7 +445,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
.. ..
}, },
) if let Node::TraitRef(trait_ref) = ) if let Node::TraitRef(trait_ref) =
tcx.hir().get(tcx.hir().get_parent_node(binding_id)) tcx.hir().get(tcx.hir().parent_id(binding_id))
&& e.hir_id == hir_id => && e.hir_id == hir_id =>
{ {
let Some(trait_def_id) = trait_ref.trait_def_id() else { 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<'_> {
Node::TypeBinding( Node::TypeBinding(
binding @ &TypeBinding { hir_id: binding_id, gen_args, ref kind, .. }, binding @ &TypeBinding { hir_id: binding_id, gen_args, ref kind, .. },
) if let Node::TraitRef(trait_ref) = ) if let Node::TraitRef(trait_ref) =
tcx.hir().get(tcx.hir().get_parent_node(binding_id)) tcx.hir().get(tcx.hir().parent_id(binding_id))
&& let Some((idx, _)) = && let Some((idx, _)) =
gen_args.args.iter().enumerate().find(|(_, arg)| { gen_args.args.iter().enumerate().find(|(_, arg)| {
if let GenericArg::Const(ct) = arg { if let GenericArg::Const(ct) = arg {

View file

@ -289,7 +289,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn maybe_get_coercion_reason(&self, hir_id: hir::HirId, sp: Span) -> Option<(Span, String)> { fn maybe_get_coercion_reason(&self, hir_id: hir::HirId, sp: Span) -> Option<(Span, String)> {
let node = { let node = {
let rslt = self.tcx.hir().get_parent_node(self.tcx.hir().get_parent_node(hir_id)); let rslt = self.tcx.hir().parent_id(self.tcx.hir().parent_id(hir_id));
self.tcx.hir().get(rslt) self.tcx.hir().get(rslt)
}; };
if let hir::Node::Block(block) = node { if let hir::Node::Block(block) = node {
@ -297,7 +297,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let parent = self let parent = self
.tcx .tcx
.hir() .hir()
.get(self.tcx.hir().get_parent_node(self.tcx.hir().get_parent_node(block.hir_id))); .get(self.tcx.hir().parent_id(self.tcx.hir().parent_id(block.hir_id)));
if let (Some(expr), hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(..), .. })) = if let (Some(expr), hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(..), .. })) =
(&block.expr, parent) (&block.expr, parent)
{ {

View file

@ -288,7 +288,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
callee_span: Span, callee_span: Span,
) { ) {
let hir = self.tcx.hir(); let hir = self.tcx.hir();
let parent_hir_id = hir.get_parent_node(hir_id); let parent_hir_id = hir.parent_id(hir_id);
let parent_node = hir.get(parent_hir_id); let parent_node = hir.get(parent_hir_id);
if let ( if let (
hir::Node::Expr(hir::Expr { hir::Node::Expr(hir::Expr {
@ -303,7 +303,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
{ {
// Actually need to unwrap a few more layers of HIR to get to // Actually need to unwrap a few more layers of HIR to get to
// the _real_ closure... // the _real_ closure...
let async_closure = hir.get_parent_node(hir.get_parent_node(parent_hir_id)); let async_closure = hir.parent_id(hir.parent_id(parent_hir_id));
if let hir::Node::Expr(hir::Expr { if let hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Closure(&hir::Closure { fn_decl_span, .. }), kind: hir::ExprKind::Closure(&hir::Closure { fn_decl_span, .. }),
.. ..
@ -336,7 +336,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
call_expr: &'tcx hir::Expr<'tcx>, call_expr: &'tcx hir::Expr<'tcx>,
callee_expr: &'tcx hir::Expr<'tcx>, callee_expr: &'tcx hir::Expr<'tcx>,
) -> bool { ) -> bool {
let hir_id = self.tcx.hir().get_parent_node(call_expr.hir_id); let hir_id = self.tcx.hir().parent_id(call_expr.hir_id);
let parent_node = self.tcx.hir().get(hir_id); let parent_node = self.tcx.hir().get(hir_id);
if let ( if let (
hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Array(_), .. }), hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Array(_), .. }),

View file

@ -1547,7 +1547,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
err.span_label(cause.span, "return type is not `()`"); err.span_label(cause.span, "return type is not `()`");
} }
ObligationCauseCode::BlockTailExpression(blk_id) => { ObligationCauseCode::BlockTailExpression(blk_id) => {
let parent_id = fcx.tcx.hir().get_parent_node(blk_id); let parent_id = fcx.tcx.hir().parent_id(blk_id);
err = self.report_return_mismatched_types( err = self.report_return_mismatched_types(
cause, cause,
expected, expected,
@ -1578,7 +1578,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
None, None,
); );
if !fcx.tcx.features().unsized_locals { if !fcx.tcx.features().unsized_locals {
let id = fcx.tcx.hir().get_parent_node(id); let id = fcx.tcx.hir().parent_id(id);
unsized_return = self.is_return_ty_unsized(fcx, id); unsized_return = self.is_return_ty_unsized(fcx, id);
} }
} }
@ -1668,7 +1668,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
let mut pointing_at_return_type = false; let mut pointing_at_return_type = false;
let mut fn_output = None; let mut fn_output = None;
let parent_id = fcx.tcx.hir().get_parent_node(id); let parent_id = fcx.tcx.hir().parent_id(id);
let parent = fcx.tcx.hir().get(parent_id); let parent = fcx.tcx.hir().get(parent_id);
if let Some(expr) = expression if let Some(expr) = expression
&& let hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(&hir::Closure { body, .. }), .. }) = parent && let hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(&hir::Closure { body, .. }), .. }) = parent

View file

@ -211,7 +211,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr: &hir::Expr<'_>, expr: &hir::Expr<'_>,
error: Option<TypeError<'tcx>>, error: Option<TypeError<'tcx>>,
) { ) {
let parent = self.tcx.hir().get_parent_node(expr.hir_id); let parent = self.tcx.hir().parent_id(expr.hir_id);
match (self.tcx.hir().find(parent), error) { match (self.tcx.hir().find(parent), error) {
(Some(hir::Node::Local(hir::Local { ty: Some(ty), init: Some(init), .. })), _) (Some(hir::Node::Local(hir::Local { ty: Some(ty), init: Some(init), .. })), _)
if init.hir_id == expr.hir_id => if init.hir_id == expr.hir_id =>
@ -258,7 +258,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
hir::Path { res: hir::def::Res::Local(hir_id), .. }, hir::Path { res: hir::def::Res::Local(hir_id), .. },
)) => { )) => {
if let Some(hir::Node::Pat(pat)) = self.tcx.hir().find(*hir_id) { if let Some(hir::Node::Pat(pat)) = self.tcx.hir().find(*hir_id) {
let parent = self.tcx.hir().get_parent_node(pat.hir_id); let parent = self.tcx.hir().parent_id(pat.hir_id);
primary_span = pat.span; primary_span = pat.span;
secondary_span = pat.span; secondary_span = pat.span;
match self.tcx.hir().find(parent) { match self.tcx.hir().find(parent) {
@ -326,7 +326,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr: &hir::Expr<'_>, expr: &hir::Expr<'_>,
error: Option<TypeError<'tcx>>, error: Option<TypeError<'tcx>>,
) { ) {
let parent = self.tcx.hir().get_parent_node(expr.hir_id); let parent = self.tcx.hir().parent_id(expr.hir_id);
let Some(TypeError::Sorts(ExpectedFound { expected, .. })) = error else {return;}; let Some(TypeError::Sorts(ExpectedFound { expected, .. })) = error else {return;};
let Some(hir::Node::Expr(hir::Expr { let Some(hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Assign(lhs, rhs, _), .. kind: hir::ExprKind::Assign(lhs, rhs, _), ..
@ -510,7 +510,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Unroll desugaring, to make sure this works for `for` loops etc. // Unroll desugaring, to make sure this works for `for` loops etc.
loop { loop {
parent = self.tcx.hir().get_parent_node(id); parent = self.tcx.hir().parent_id(id);
if let Some(parent_span) = self.tcx.hir().opt_span(parent) { if let Some(parent_span) = self.tcx.hir().opt_span(parent) {
if parent_span.find_ancestor_inside(expr.span).is_some() { if parent_span.find_ancestor_inside(expr.span).is_some() {
// The parent node is part of the same span, so is the result of the // The parent node is part of the same span, so is the result of the
@ -790,12 +790,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return None; return None;
}; };
let local_parent = self.tcx.hir().get_parent_node(local_id); let local_parent = self.tcx.hir().parent_id(local_id);
let Some(Node::Param(hir::Param { hir_id: param_hir_id, .. })) = self.tcx.hir().find(local_parent) else { let Some(Node::Param(hir::Param { hir_id: param_hir_id, .. })) = self.tcx.hir().find(local_parent) else {
return None; return None;
}; };
let param_parent = self.tcx.hir().get_parent_node(*param_hir_id); let param_parent = self.tcx.hir().parent_id(*param_hir_id);
let Some(Node::Expr(hir::Expr { let Some(Node::Expr(hir::Expr {
hir_id: expr_hir_id, hir_id: expr_hir_id,
kind: hir::ExprKind::Closure(hir::Closure { fn_decl: closure_fn_decl, .. }), kind: hir::ExprKind::Closure(hir::Closure { fn_decl: closure_fn_decl, .. }),
@ -804,7 +804,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return None; return None;
}; };
let expr_parent = self.tcx.hir().get_parent_node(*expr_hir_id); let expr_parent = self.tcx.hir().parent_id(*expr_hir_id);
let hir = self.tcx.hir().find(expr_parent); let hir = self.tcx.hir().find(expr_parent);
let closure_params_len = closure_fn_decl.inputs.len(); let closure_params_len = closure_fn_decl.inputs.len();
let ( let (
@ -857,7 +857,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
_ => None, _ => None,
}?; }?;
match hir.find(hir.get_parent_node(expr.hir_id))? { match hir.find(hir.parent_id(expr.hir_id))? {
Node::ExprField(field) => { Node::ExprField(field) => {
if field.ident.name == local.name && field.is_shorthand { if field.ident.name == local.name && field.is_shorthand {
return Some(local.name); return Some(local.name);
@ -883,7 +883,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Returns whether the given expression is an `else if`. /// Returns whether the given expression is an `else if`.
pub(crate) fn is_else_if_block(&self, expr: &hir::Expr<'_>) -> bool { pub(crate) fn is_else_if_block(&self, expr: &hir::Expr<'_>) -> bool {
if let hir::ExprKind::If(..) = expr.kind { if let hir::ExprKind::If(..) = expr.kind {
let parent_id = self.tcx.hir().get_parent_node(expr.hir_id); let parent_id = self.tcx.hir().parent_id(expr.hir_id);
if let Some(Node::Expr(hir::Expr { if let Some(Node::Expr(hir::Expr {
kind: hir::ExprKind::If(_, _, Some(else_expr)), kind: hir::ExprKind::If(_, _, Some(else_expr)),
.. ..
@ -1040,7 +1040,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let Some(hir::Node::Expr(hir::Expr { if let Some(hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Assign(..), kind: hir::ExprKind::Assign(..),
.. ..
})) = self.tcx.hir().find(self.tcx.hir().get_parent_node(expr.hir_id)) })) = self.tcx.hir().find(self.tcx.hir().parent_id(expr.hir_id))
{ {
if mutability.is_mut() { if mutability.is_mut() {
// Suppressing this diagnostic, we'll properly print it in `check_expr_assign` // Suppressing this diagnostic, we'll properly print it in `check_expr_assign`
@ -1268,7 +1268,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut sugg = vec![]; let mut sugg = vec![];
if let Some(hir::Node::ExprField(field)) = if let Some(hir::Node::ExprField(field)) =
self.tcx.hir().find(self.tcx.hir().get_parent_node(expr.hir_id)) self.tcx.hir().find(self.tcx.hir().parent_id(expr.hir_id))
{ {
// `expr` is a literal field for a struct, only suggest if appropriate // `expr` is a literal field for a struct, only suggest if appropriate
if field.is_shorthand { if field.is_shorthand {
@ -1625,7 +1625,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
[start, end], [start, end],
_, _,
) = expr.kind else { return; }; ) = expr.kind else { return; };
let parent = self.tcx.hir().get_parent_node(expr.hir_id); let parent = self.tcx.hir().parent_id(expr.hir_id);
if let Some(hir::Node::ExprField(_)) = self.tcx.hir().find(parent) { if let Some(hir::Node::ExprField(_)) = self.tcx.hir().find(parent) {
// Ignore `Foo { field: a..Default::default() }` // Ignore `Foo { field: a..Default::default() }`
return; return;

View file

@ -920,7 +920,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
original_expr_id: HirId, original_expr_id: HirId,
then: impl FnOnce(&hir::Expr<'_>), then: impl FnOnce(&hir::Expr<'_>),
) { ) {
let mut parent = self.tcx.hir().get_parent_node(original_expr_id); let mut parent = self.tcx.hir().parent_id(original_expr_id);
while let Some(node) = self.tcx.hir().find(parent) { while let Some(node) = self.tcx.hir().find(parent) {
match node { match node {
hir::Node::Expr(hir::Expr { hir::Node::Expr(hir::Expr {
@ -959,7 +959,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
| hir::Node::TraitItem(_) | hir::Node::TraitItem(_)
| hir::Node::Crate(_) => break, | hir::Node::Crate(_) => break,
_ => { _ => {
parent = self.tcx.hir().get_parent_node(parent); parent = self.tcx.hir().parent_id(parent);
} }
} }
} }
@ -1083,7 +1083,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Do not suggest `if let x = y` as `==` is way more likely to be the intention. // Do not suggest `if let x = y` as `==` is way more likely to be the intention.
let hir = self.tcx.hir(); let hir = self.tcx.hir();
if let hir::Node::Expr(hir::Expr { kind: ExprKind::If { .. }, .. }) = if let hir::Node::Expr(hir::Expr { kind: ExprKind::If { .. }, .. }) =
hir.get(hir.get_parent_node(hir.get_parent_node(expr.hir_id))) hir.get(hir.parent_id(hir.parent_id(expr.hir_id)))
{ {
err.span_suggestion_verbose( err.span_suggestion_verbose(
expr.span.shrink_to_lo(), expr.span.shrink_to_lo(),
@ -2462,7 +2462,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.span_label(field.span, "method, not a field"); err.span_label(field.span, "method, not a field");
let expr_is_call = let expr_is_call =
if let hir::Node::Expr(hir::Expr { kind: ExprKind::Call(callee, _args), .. }) = if let hir::Node::Expr(hir::Expr { kind: ExprKind::Call(callee, _args), .. }) =
self.tcx.hir().get(self.tcx.hir().get_parent_node(expr.hir_id)) self.tcx.hir().get(self.tcx.hir().parent_id(expr.hir_id))
{ {
expr.hir_id == callee.hir_id expr.hir_id == callee.hir_id
} else { } else {

View file

@ -1436,7 +1436,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut contained_in_place = false; let mut contained_in_place = false;
while let hir::Node::Expr(parent_expr) = while let hir::Node::Expr(parent_expr) =
self.tcx.hir().get(self.tcx.hir().get_parent_node(expr_id)) self.tcx.hir().get(self.tcx.hir().parent_id(expr_id))
{ {
match &parent_expr.kind { match &parent_expr.kind {
hir::ExprKind::Assign(lhs, ..) | hir::ExprKind::AssignOp(_, lhs, ..) => { hir::ExprKind::Assign(lhs, ..) | hir::ExprKind::AssignOp(_, lhs, ..) => {

View file

@ -1803,7 +1803,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
hir_id: call_hir_id, hir_id: call_hir_id,
span: call_span, span: call_span,
.. ..
}) = hir.get(hir.get_parent_node(expr.hir_id)) }) = hir.get(hir.parent_id(expr.hir_id))
&& callee.hir_id == expr.hir_id && callee.hir_id == expr.hir_id
{ {
if self.closure_span_overlaps_error(error, *call_span) { if self.closure_span_overlaps_error(error, *call_span) {

View file

@ -32,7 +32,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.typeck_results self.typeck_results
.borrow() .borrow()
.liberated_fn_sigs() .liberated_fn_sigs()
.get(self.tcx.hir().get_parent_node(self.body_id)) .get(self.tcx.hir().parent_id(self.body_id))
.copied() .copied()
} }
@ -642,7 +642,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Check if the parent expression is a call to Pin::new. If it // Check if the parent expression is a call to Pin::new. If it
// is and we were expecting a Box, ergo Pin<Box<expected>>, we // is and we were expecting a Box, ergo Pin<Box<expected>>, we
// can suggest Box::pin. // can suggest Box::pin.
let parent = self.tcx.hir().get_parent_node(expr.hir_id); let parent = self.tcx.hir().parent_id(expr.hir_id);
let Some(Node::Expr(Expr { kind: ExprKind::Call(fn_name, _), .. })) = self.tcx.hir().find(parent) else { let Some(Node::Expr(Expr { kind: ExprKind::Call(fn_name, _), .. })) = self.tcx.hir().find(parent) else {
return false; return false;
}; };

View file

@ -224,7 +224,7 @@ fn typeck_with_fallback<'tcx>(
_ => None, _ => None,
}) })
.unwrap_or_else(|| match tcx.hir().get(id) { .unwrap_or_else(|| match tcx.hir().get(id) {
Node::AnonConst(_) => match tcx.hir().get(tcx.hir().get_parent_node(id)) { Node::AnonConst(_) => match tcx.hir().get(tcx.hir().parent_id(id)) {
Node::Expr(&hir::Expr { Node::Expr(&hir::Expr {
kind: hir::ExprKind::ConstBlock(ref anon_const), kind: hir::ExprKind::ConstBlock(ref anon_const),
.. ..

View file

@ -116,7 +116,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let sugg_span = if let SelfSource::MethodCall(expr) = source { let sugg_span = if let SelfSource::MethodCall(expr) = source {
// Given `foo.bar(baz)`, `expr` is `bar`, but we want to point to the whole thing. // Given `foo.bar(baz)`, `expr` is `bar`, but we want to point to the whole thing.
self.tcx.hir().expect_expr(self.tcx.hir().get_parent_node(expr.hir_id)).span self.tcx.hir().expect_expr(self.tcx.hir().parent_id(expr.hir_id)).span
} else { } else {
span span
}; };
@ -334,7 +334,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let SelfSource::MethodCall(rcvr_expr) = source { if let SelfSource::MethodCall(rcvr_expr) = source {
self.suggest_fn_call(&mut err, rcvr_expr, rcvr_ty, |output_ty| { self.suggest_fn_call(&mut err, rcvr_expr, rcvr_ty, |output_ty| {
let call_expr = let call_expr =
self.tcx.hir().expect_expr(self.tcx.hir().get_parent_node(rcvr_expr.hir_id)); self.tcx.hir().expect_expr(self.tcx.hir().parent_id(rcvr_expr.hir_id));
let probe = let probe =
self.lookup_probe(item_name, output_ty, call_expr, ProbeScope::AllTraits); self.lookup_probe(item_name, output_ty, call_expr, ProbeScope::AllTraits);
probe.is_ok() probe.is_ok()
@ -916,8 +916,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let msg = "remove this method call"; let msg = "remove this method call";
let mut fallback_span = true; let mut fallback_span = true;
if let SelfSource::MethodCall(expr) = source { if let SelfSource::MethodCall(expr) = source {
let call_expr = let call_expr = self.tcx.hir().expect_expr(self.tcx.hir().parent_id(expr.hir_id));
self.tcx.hir().expect_expr(self.tcx.hir().get_parent_node(expr.hir_id));
if let Some(span) = call_expr.span.trim_start(expr.span) { if let Some(span) = call_expr.span.trim_start(expr.span) {
err.span_suggestion(span, msg, "", Applicability::MachineApplicable); err.span_suggestion(span, msg, "", Applicability::MachineApplicable);
fallback_span = false; fallback_span = false;
@ -1270,7 +1269,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Applicability::MachineApplicable, Applicability::MachineApplicable,
); );
} else { } else {
let call_expr = tcx.hir().expect_expr(tcx.hir().get_parent_node(expr.hir_id)); let call_expr = tcx.hir().expect_expr(tcx.hir().parent_id(expr.hir_id));
if let Some(span) = call_expr.span.trim_start(item_name.span) { if let Some(span) = call_expr.span.trim_start(item_name.span) {
err.span_suggestion( err.span_suggestion(
@ -1452,7 +1451,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let filename = tcx.sess.source_map().span_to_filename(span); let filename = tcx.sess.source_map().span_to_filename(span);
let parent_node = let parent_node =
self.tcx.hir().get(self.tcx.hir().get_parent_node(hir_id)); self.tcx.hir().get(self.tcx.hir().parent_id(hir_id));
let msg = format!( let msg = format!(
"you must specify a type for this binding, like `{}`", "you must specify a type for this binding, like `{}`",
concrete_type, concrete_type,
@ -1525,7 +1524,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut visitor = LetVisitor { result: None, ident_name: seg1.ident.name }; let mut visitor = LetVisitor { result: None, ident_name: seg1.ident.name };
visitor.visit_body(&body); visitor.visit_body(&body);
let parent = self.tcx.hir().get_parent_node(seg1.hir_id); let parent = self.tcx.hir().parent_id(seg1.hir_id);
if let Some(Node::Expr(call_expr)) = self.tcx.hir().find(parent) if let Some(Node::Expr(call_expr)) = self.tcx.hir().find(parent)
&& let Some(expr) = visitor.result && let Some(expr) = visitor.result
&& let Some(self_ty) = self.node_ty_opt(expr.hir_id) && let Some(self_ty) = self.node_ty_opt(expr.hir_id)
@ -1563,7 +1562,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&& let Some((fields, substs)) = && let Some((fields, substs)) =
self.get_field_candidates_considering_privacy(span, actual, mod_id) self.get_field_candidates_considering_privacy(span, actual, mod_id)
{ {
let call_expr = self.tcx.hir().expect_expr(self.tcx.hir().get_parent_node(expr.hir_id)); let call_expr = self.tcx.hir().expect_expr(self.tcx.hir().parent_id(expr.hir_id));
let lang_items = self.tcx.lang_items(); let lang_items = self.tcx.lang_items();
let never_mention_traits = [ let never_mention_traits = [
@ -1633,7 +1632,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) { ) {
let tcx = self.tcx; let tcx = self.tcx;
let SelfSource::MethodCall(expr) = source else { return; }; let SelfSource::MethodCall(expr) = source else { return; };
let call_expr = tcx.hir().expect_expr(tcx.hir().get_parent_node(expr.hir_id)); let call_expr = tcx.hir().expect_expr(tcx.hir().parent_id(expr.hir_id));
let ty::Adt(kind, substs) = actual.kind() else { return; }; let ty::Adt(kind, substs) = actual.kind() else { return; };
match kind.adt_kind() { match kind.adt_kind() {
@ -2594,7 +2593,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return false; return false;
} }
let parent = self.tcx.hir().get_parent_node(expr.hir_id); let parent = self.tcx.hir().parent_id(expr.hir_id);
if let Some(Node::Expr(call_expr)) = self.tcx.hir().find(parent) && if let Some(Node::Expr(call_expr)) = self.tcx.hir().find(parent) &&
let hir::ExprKind::MethodCall( let hir::ExprKind::MethodCall(
hir::PathSegment { ident: method_name, .. }, hir::PathSegment { ident: method_name, .. },

View file

@ -692,7 +692,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let tcx = self.tcx; let tcx = self.tcx;
if let PatKind::Ref(inner, mutbl) = pat.kind if let PatKind::Ref(inner, mutbl) = pat.kind
&& let PatKind::Binding(_, _, binding, ..) = inner.kind { && let PatKind::Binding(_, _, binding, ..) = inner.kind {
let binding_parent_id = tcx.hir().get_parent_node(pat.hir_id); let binding_parent_id = tcx.hir().parent_id(pat.hir_id);
let binding_parent = tcx.hir().get(binding_parent_id); let binding_parent = tcx.hir().get(binding_parent_id);
debug!(?inner, ?pat, ?binding_parent); debug!(?inner, ?pat, ?binding_parent);
@ -936,7 +936,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
res.descr(), res.descr(),
), ),
); );
match self.tcx.hir().get(self.tcx.hir().get_parent_node(pat.hir_id)) { match self.tcx.hir().get(self.tcx.hir().parent_id(pat.hir_id)) {
hir::Node::PatField(..) => { hir::Node::PatField(..) => {
e.span_suggestion_verbose( e.span_suggestion_verbose(
ident.span.shrink_to_hi(), ident.span.shrink_to_hi(),

View file

@ -411,7 +411,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
span: Span, span: Span,
) { ) {
let hir = self.tcx.hir(); let hir = self.tcx.hir();
let fn_hir_id = hir.get_parent_node(cause.body_id); let fn_hir_id = hir.parent_id(cause.body_id);
if let Some(node) = self.tcx.hir().find(fn_hir_id) && if let Some(node) = self.tcx.hir().find(fn_hir_id) &&
let hir::Node::Item(hir::Item { let hir::Node::Item(hir::Item {
kind: hir::ItemKind::Fn(_sig, _, body_id), .. kind: hir::ItemKind::Fn(_sig, _, body_id), ..
@ -585,9 +585,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
let hir::StmtKind::Local(local) = &stmt.kind else { continue; }; let hir::StmtKind::Local(local) = &stmt.kind else { continue; };
local.pat.walk(&mut find_compatible_candidates); local.pat.walk(&mut find_compatible_candidates);
} }
match hir.find(hir.get_parent_node(blk.hir_id)) { match hir.find(hir.parent_id(blk.hir_id)) {
Some(hir::Node::Expr(hir::Expr { hir_id, .. })) => { Some(hir::Node::Expr(hir::Expr { hir_id, .. })) => {
match hir.find(hir.get_parent_node(*hir_id)) { match hir.find(hir.parent_id(*hir_id)) {
Some(hir::Node::Arm(hir::Arm { pat, .. })) => { Some(hir::Node::Arm(hir::Arm { pat, .. })) => {
pat.walk(&mut find_compatible_candidates); pat.walk(&mut find_compatible_candidates);
} }

View file

@ -1526,7 +1526,7 @@ impl<'tcx> LateLintPass<'tcx> for UnreachablePub {
fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) { fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) {
let map = cx.tcx.hir(); let map = cx.tcx.hir();
if matches!(map.get(map.get_parent_node(field.hir_id)), Node::Variant(_)) { if matches!(map.get(map.parent_id(field.hir_id)), Node::Variant(_)) {
return; return;
} }
self.perform_lint(cx, "field", field.def_id, field.vis_span, false); self.perform_lint(cx, "field", field.def_id, field.vis_span, false);

View file

@ -143,7 +143,7 @@ impl<'tcx> LateLintPass<'tcx> for TyTyKind {
TyKind::Path(QPath::Resolved(_, path)) => { TyKind::Path(QPath::Resolved(_, path)) => {
if lint_ty_kind_usage(cx, &path.res) { if lint_ty_kind_usage(cx, &path.res) {
let hir = cx.tcx.hir(); let hir = cx.tcx.hir();
let span = match hir.find(hir.get_parent_node(ty.hir_id)) { let span = match hir.find(hir.parent_id(ty.hir_id)) {
Some(Node::Pat(Pat { Some(Node::Pat(Pat {
kind: kind:
PatKind::Path(qpath) PatKind::Path(qpath)

View file

@ -444,8 +444,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
fn check_pat(&mut self, cx: &LateContext<'_>, p: &hir::Pat<'_>) { fn check_pat(&mut self, cx: &LateContext<'_>, p: &hir::Pat<'_>) {
if let PatKind::Binding(_, hid, ident, _) = p.kind { if let PatKind::Binding(_, hid, ident, _) = p.kind {
if let hir::Node::PatField(field) = cx.tcx.hir().get(cx.tcx.hir().get_parent_node(hid)) if let hir::Node::PatField(field) = cx.tcx.hir().get(cx.tcx.hir().parent_id(hid)) {
{
if !field.is_shorthand { if !field.is_shorthand {
// Only check if a new name has been introduced, to avoid warning // Only check if a new name has been introduced, to avoid warning
// on both the struct definition and this pattern. // on both the struct definition and this pattern.

View file

@ -127,9 +127,9 @@ fn lint_overflowing_range_endpoint<'tcx>(
) -> bool { ) -> bool {
// We only want to handle exclusive (`..`) ranges, // We only want to handle exclusive (`..`) ranges,
// which are represented as `ExprKind::Struct`. // which are represented as `ExprKind::Struct`.
let par_id = cx.tcx.hir().get_parent_node(expr.hir_id); let par_id = cx.tcx.hir().parent_id(expr.hir_id);
let Node::ExprField(field) = cx.tcx.hir().get(par_id) else { return false }; let Node::ExprField(field) = cx.tcx.hir().get(par_id) else { return false };
let field_par_id = cx.tcx.hir().get_parent_node(field.hir_id); let field_par_id = cx.tcx.hir().parent_id(field.hir_id);
let Node::Expr(struct_expr) = cx.tcx.hir().get(field_par_id) else { return false }; let Node::Expr(struct_expr) = cx.tcx.hir().get(field_par_id) else { return false };
if !is_range_literal(struct_expr) { if !is_range_literal(struct_expr) {
return false; return false;
@ -404,7 +404,7 @@ fn lint_uint_literal<'tcx>(
_ => bug!(), _ => bug!(),
}; };
if lit_val < min || lit_val > max { if lit_val < min || lit_val > max {
let parent_id = cx.tcx.hir().get_parent_node(e.hir_id); let parent_id = cx.tcx.hir().parent_id(e.hir_id);
if let Node::Expr(par_e) = cx.tcx.hir().get(parent_id) { if let Node::Expr(par_e) = cx.tcx.hir().get(parent_id) {
match par_e.kind { match par_e.kind {
hir::ExprKind::Cast(..) => { hir::ExprKind::Cast(..) => {

View file

@ -69,7 +69,7 @@ impl<'hir> Iterator for ParentHirIterator<'hir> {
} }
loop { loop {
// There are nodes that do not have entries, so we need to skip them. // There are nodes that do not have entries, so we need to skip them.
let parent_id = self.map.get_parent_node(self.current_id); let parent_id = self.map.parent_id(self.current_id);
if parent_id == self.current_id { if parent_id == self.current_id {
self.current_id = CRATE_HIR_ID; self.current_id = CRATE_HIR_ID;
@ -246,7 +246,7 @@ impl<'hir> Map<'hir> {
}, },
Node::Variant(_) => DefKind::Variant, Node::Variant(_) => DefKind::Variant,
Node::Ctor(variant_data) => { Node::Ctor(variant_data) => {
let ctor_of = match self.find(self.get_parent_node(hir_id)) { let ctor_of = match self.find(self.parent_id(hir_id)) {
Some(Node::Item(..)) => def::CtorOf::Struct, Some(Node::Item(..)) => def::CtorOf::Struct,
Some(Node::Variant(..)) => def::CtorOf::Variant, Some(Node::Variant(..)) => def::CtorOf::Variant,
_ => unreachable!(), _ => unreachable!(),
@ -257,7 +257,7 @@ impl<'hir> Map<'hir> {
} }
} }
Node::AnonConst(_) => { Node::AnonConst(_) => {
let inline = match self.find(self.get_parent_node(hir_id)) { let inline = match self.find(self.parent_id(hir_id)) {
Some(Node::Expr(&Expr { Some(Node::Expr(&Expr {
kind: ExprKind::ConstBlock(ref anon_const), .. kind: ExprKind::ConstBlock(ref anon_const), ..
})) if anon_const.hir_id == hir_id => true, })) if anon_const.hir_id == hir_id => true,
@ -312,7 +312,7 @@ impl<'hir> Map<'hir> {
} }
#[track_caller] #[track_caller]
pub fn get_parent_node(self, hir_id: HirId) -> HirId { pub fn parent_id(self, hir_id: HirId) -> HirId {
self.find_parent_node(hir_id) self.find_parent_node(hir_id)
.unwrap_or_else(|| bug!("No parent for node {:?}", self.node_to_string(hir_id))) .unwrap_or_else(|| bug!("No parent for node {:?}", self.node_to_string(hir_id)))
} }
@ -414,7 +414,7 @@ impl<'hir> Map<'hir> {
/// which this is the body of, i.e., a `fn`, `const` or `static` /// which this is the body of, i.e., a `fn`, `const` or `static`
/// item (possibly associated), a closure, or a `hir::AnonConst`. /// item (possibly associated), a closure, or a `hir::AnonConst`.
pub fn body_owner(self, BodyId { hir_id }: BodyId) -> HirId { pub fn body_owner(self, BodyId { hir_id }: BodyId) -> HirId {
let parent = self.get_parent_node(hir_id); let parent = self.parent_id(hir_id);
assert!(self.find(parent).map_or(false, |n| is_body_owner(n, hir_id)), "{hir_id:?}"); assert!(self.find(parent).map_or(false, |n| is_body_owner(n, hir_id)), "{hir_id:?}");
parent parent
} }
@ -642,21 +642,21 @@ impl<'hir> Map<'hir> {
} }
/// Returns an iterator for the nodes in the ancestor tree of the `current_id` /// Returns an iterator for the nodes in the ancestor tree of the `current_id`
/// until the crate root is reached. Prefer this over your own loop using `get_parent_node`. /// until the crate root is reached. Prefer this over your own loop using `parent_id`.
#[inline] #[inline]
pub fn parent_id_iter(self, current_id: HirId) -> impl Iterator<Item = HirId> + 'hir { pub fn parent_id_iter(self, current_id: HirId) -> impl Iterator<Item = HirId> + 'hir {
ParentHirIterator { current_id, map: self } ParentHirIterator { current_id, map: self }
} }
/// Returns an iterator for the nodes in the ancestor tree of the `current_id` /// Returns an iterator for the nodes in the ancestor tree of the `current_id`
/// until the crate root is reached. Prefer this over your own loop using `get_parent_node`. /// until the crate root is reached. Prefer this over your own loop using `parent_id`.
#[inline] #[inline]
pub fn parent_iter(self, current_id: HirId) -> impl Iterator<Item = (HirId, Node<'hir>)> { pub fn parent_iter(self, current_id: HirId) -> impl Iterator<Item = (HirId, Node<'hir>)> {
self.parent_id_iter(current_id).filter_map(move |id| Some((id, self.find(id)?))) self.parent_id_iter(current_id).filter_map(move |id| Some((id, self.find(id)?)))
} }
/// Returns an iterator for the nodes in the ancestor tree of the `current_id` /// Returns an iterator for the nodes in the ancestor tree of the `current_id`
/// until the crate root is reached. Prefer this over your own loop using `get_parent_node`. /// until the crate root is reached. Prefer this over your own loop using `parent_id`.
#[inline] #[inline]
pub fn parent_owner_iter(self, current_id: HirId) -> ParentOwnerIterator<'hir> { pub fn parent_owner_iter(self, current_id: HirId) -> ParentOwnerIterator<'hir> {
ParentOwnerIterator { current_id, map: self } ParentOwnerIterator { current_id, map: self }
@ -664,7 +664,7 @@ impl<'hir> Map<'hir> {
/// Checks if the node is left-hand side of an assignment. /// Checks if the node is left-hand side of an assignment.
pub fn is_lhs(self, id: HirId) -> bool { pub fn is_lhs(self, id: HirId) -> bool {
match self.find(self.get_parent_node(id)) { match self.find(self.parent_id(id)) {
Some(Node::Expr(expr)) => match expr.kind { Some(Node::Expr(expr)) => match expr.kind {
ExprKind::Assign(lhs, _rhs, _span) => lhs.hir_id == id, ExprKind::Assign(lhs, _rhs, _span) => lhs.hir_id == id,
_ => false, _ => false,
@ -892,7 +892,7 @@ impl<'hir> Map<'hir> {
Node::Pat(&Pat { kind: PatKind::Binding(_, _, ident, _), .. }) => Some(ident), Node::Pat(&Pat { kind: PatKind::Binding(_, _, ident, _), .. }) => Some(ident),
// A `Ctor` doesn't have an identifier itself, but its parent // A `Ctor` doesn't have an identifier itself, but its parent
// struct/variant does. Compare with `hir::Map::opt_span`. // struct/variant does. Compare with `hir::Map::opt_span`.
Node::Ctor(..) => match self.find(self.get_parent_node(id))? { Node::Ctor(..) => match self.find(self.parent_id(id))? {
Node::Item(item) => Some(item.ident), Node::Item(item) => Some(item.ident),
Node::Variant(variant) => Some(variant.ident), Node::Variant(variant) => Some(variant.ident),
_ => unreachable!(), _ => unreachable!(),
@ -1021,7 +1021,7 @@ impl<'hir> Map<'hir> {
ForeignItemKind::Fn(decl, _, _) => until_within(item.span, decl.output.span()), ForeignItemKind::Fn(decl, _, _) => until_within(item.span, decl.output.span()),
_ => named_span(item.span, item.ident, None), _ => named_span(item.span, item.ident, None),
}, },
Node::Ctor(_) => return self.opt_span(self.get_parent_node(hir_id)), Node::Ctor(_) => return self.opt_span(self.parent_id(hir_id)),
Node::Expr(Expr { Node::Expr(Expr {
kind: ExprKind::Closure(Closure { fn_decl_span, .. }), kind: ExprKind::Closure(Closure { fn_decl_span, .. }),
span, span,
@ -1063,7 +1063,7 @@ impl<'hir> Map<'hir> {
Node::PatField(field) => field.span, Node::PatField(field) => field.span,
Node::Arm(arm) => arm.span, Node::Arm(arm) => arm.span,
Node::Block(block) => block.span, Node::Block(block) => block.span,
Node::Ctor(..) => self.span_with_body(self.get_parent_node(hir_id)), Node::Ctor(..) => self.span_with_body(self.parent_id(hir_id)),
Node::Lifetime(lifetime) => lifetime.ident.span, Node::Lifetime(lifetime) => lifetime.ident.span,
Node::GenericParam(param) => param.span, Node::GenericParam(param) => param.span,
Node::Infer(i) => i.span, Node::Infer(i) => i.span,
@ -1093,7 +1093,7 @@ impl<'hir> Map<'hir> {
/// Returns the HirId of `N` in `struct Foo<const N: usize = { ... }>` when /// Returns the HirId of `N` in `struct Foo<const N: usize = { ... }>` when
/// called with the HirId for the `{ ... }` anon const /// called with the HirId for the `{ ... }` anon const
pub fn opt_const_param_default_param_def_id(self, anon_const: HirId) -> Option<LocalDefId> { pub fn opt_const_param_default_param_def_id(self, anon_const: HirId) -> Option<LocalDefId> {
match self.get(self.get_parent_node(anon_const)) { match self.get(self.parent_id(anon_const)) {
Node::GenericParam(GenericParam { Node::GenericParam(GenericParam {
def_id: param_id, def_id: param_id,
kind: GenericParamKind::Const { .. }, kind: GenericParamKind::Const { .. },

View file

@ -182,7 +182,7 @@ impl TyCtxt<'_> {
if hir.attrs(id).iter().any(|attr| Level::from_attr(attr).is_some()) { if hir.attrs(id).iter().any(|attr| Level::from_attr(attr).is_some()) {
return id; return id;
} }
let next = hir.get_parent_node(id); let next = hir.parent_id(id);
if next == id { if next == id {
bug!("lint traversal reached the root of the crate"); bug!("lint traversal reached the root of the crate");
} }

View file

@ -457,7 +457,7 @@ impl<'tcx> TyCtxt<'tcx> {
.def_id .def_id
.as_local() .as_local()
.map(|id| hir.local_def_id_to_hir_id(id)) .map(|id| hir.local_def_id_to_hir_id(id))
.and_then(|id| self.hir().find(self.hir().get_parent_node(id))) .and_then(|id| self.hir().find(self.hir().parent_id(id)))
.as_ref() .as_ref()
.and_then(|node| node.generics()) .and_then(|node| node.generics())
{ {

View file

@ -247,14 +247,14 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
fn check_let_chain(&mut self, cx: &mut MatchCheckCtxt<'p, 'tcx>, pat_id: HirId) -> bool { fn check_let_chain(&mut self, cx: &mut MatchCheckCtxt<'p, 'tcx>, pat_id: HirId) -> bool {
let hir = self.tcx.hir(); let hir = self.tcx.hir();
let parent = hir.get_parent_node(pat_id); let parent = hir.parent_id(pat_id);
// First, figure out if the given pattern is part of a let chain, // First, figure out if the given pattern is part of a let chain,
// and if so, obtain the top node of the chain. // and if so, obtain the top node of the chain.
let mut top = parent; let mut top = parent;
let mut part_of_chain = false; let mut part_of_chain = false;
loop { loop {
let new_top = hir.get_parent_node(top); let new_top = hir.parent_id(top);
if let hir::Node::Expr( if let hir::Node::Expr(
hir::Expr { hir::Expr {
kind: hir::ExprKind::Binary(Spanned { node: hir::BinOpKind::And, .. }, lhs, rhs), kind: hir::ExprKind::Binary(Spanned { node: hir::BinOpKind::And, .. }, lhs, rhs),
@ -1054,7 +1054,7 @@ pub enum LetSource {
fn let_source(tcx: TyCtxt<'_>, pat_id: HirId) -> LetSource { fn let_source(tcx: TyCtxt<'_>, pat_id: HirId) -> LetSource {
let hir = tcx.hir(); let hir = tcx.hir();
let parent = hir.get_parent_node(pat_id); let parent = hir.parent_id(pat_id);
let_source_parent(tcx, parent, Some(pat_id)) let_source_parent(tcx, parent, Some(pat_id))
} }
@ -1073,7 +1073,7 @@ fn let_source_parent(tcx: TyCtxt<'_>, parent: HirId, pat_id: Option<HirId>) -> L
_ => {} _ => {}
} }
let parent_parent = hir.get_parent_node(parent); let parent_parent = hir.parent_id(parent);
let parent_parent_node = hir.get(parent_parent); let parent_parent_node = hir.get(parent_parent);
match parent_parent_node { match parent_parent_node {
hir::Node::Stmt(hir::Stmt { kind: hir::StmtKind::Local(_), .. }) => { hir::Node::Stmt(hir::Stmt { kind: hir::StmtKind::Local(_), .. }) => {
@ -1085,8 +1085,8 @@ fn let_source_parent(tcx: TyCtxt<'_>, parent: HirId, pat_id: Option<HirId>) -> L
_ => {} _ => {}
} }
let parent_parent_parent = hir.get_parent_node(parent_parent); let parent_parent_parent = hir.parent_id(parent_parent);
let parent_parent_parent_parent = hir.get_parent_node(parent_parent_parent); let parent_parent_parent_parent = hir.parent_id(parent_parent_parent);
let parent_parent_parent_parent_node = hir.get(parent_parent_parent_parent); let parent_parent_parent_parent_node = hir.get(parent_parent_parent_parent);
if let hir::Node::Expr(hir::Expr { if let hir::Node::Expr(hir::Expr {

View file

@ -2141,7 +2141,7 @@ fn check_private_in_public(tcx: TyCtxt<'_>, (): ()) {
if !old_error_set_ancestry.insert(id) { if !old_error_set_ancestry.insert(id) {
break; break;
} }
let parent = tcx.hir().get_parent_node(id); let parent = tcx.hir().parent_id(id);
if parent == id { if parent == id {
break; break;
} }

View file

@ -600,7 +600,7 @@ impl<'tcx> SaveContext<'tcx> {
if seg.res != Res::Err { if seg.res != Res::Err {
seg.res seg.res
} else { } else {
let parent_node = self.tcx.hir().get_parent_node(hir_id); let parent_node = self.tcx.hir().parent_id(hir_id);
self.get_path_res(parent_node) self.get_path_res(parent_node)
} }
} }

View file

@ -117,7 +117,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
Some(if movability.is_some() { "an async closure" } else { "a closure" }) Some(if movability.is_some() { "an async closure" } else { "a closure" })
}), }),
hir::Node::Expr(hir::Expr { .. }) => { hir::Node::Expr(hir::Expr { .. }) => {
let parent_hid = hir.get_parent_node(hir_id); let parent_hid = hir.parent_id(hir_id);
if parent_hid != hir_id { self.describe_enclosure(parent_hid) } else { None } if parent_hid != hir_id { self.describe_enclosure(parent_hid) } else { None }
} }
_ => None, _ => None,

View file

@ -838,7 +838,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
let hir = self.tcx.hir(); let hir = self.tcx.hir();
let hir_id = hir.local_def_id_to_hir_id(def_id.as_local()?); let hir_id = hir.local_def_id_to_hir_id(def_id.as_local()?);
let parent_node = hir.get_parent_node(hir_id); let parent_node = hir.parent_id(hir_id);
match hir.find(parent_node) { match hir.find(parent_node) {
Some(hir::Node::Stmt(hir::Stmt { kind: hir::StmtKind::Local(local), .. })) => { Some(hir::Node::Stmt(hir::Stmt { kind: hir::StmtKind::Local(local), .. })) => {
get_name(err, &local.pat.kind) get_name(err, &local.pat.kind)
@ -1421,7 +1421,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
trait_pred: ty::PolyTraitPredicate<'tcx>, trait_pred: ty::PolyTraitPredicate<'tcx>,
) -> bool { ) -> bool {
let hir = self.tcx.hir(); let hir = self.tcx.hir();
let parent_node = hir.get_parent_node(obligation.cause.body_id); let parent_node = hir.parent_id(obligation.cause.body_id);
let node = hir.find(parent_node); let node = hir.find(parent_node);
if let Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, _, body_id), .. })) = node if let Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, _, body_id), .. })) = node
&& let hir::ExprKind::Block(blk, _) = &hir.body(*body_id).value.kind && let hir::ExprKind::Block(blk, _) = &hir.body(*body_id).value.kind
@ -1458,7 +1458,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
fn return_type_span(&self, obligation: &PredicateObligation<'tcx>) -> Option<Span> { fn return_type_span(&self, obligation: &PredicateObligation<'tcx>) -> Option<Span> {
let hir = self.tcx.hir(); let hir = self.tcx.hir();
let parent_node = hir.get_parent_node(obligation.cause.body_id); let parent_node = hir.parent_id(obligation.cause.body_id);
let Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, ..), .. })) = hir.find(parent_node) else { let Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, ..), .. })) = hir.find(parent_node) else {
return None; return None;
}; };
@ -1483,7 +1483,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
} }
let hir = self.tcx.hir(); let hir = self.tcx.hir();
let fn_hir_id = hir.get_parent_node(obligation.cause.body_id); let fn_hir_id = hir.parent_id(obligation.cause.body_id);
let node = hir.find(fn_hir_id); let node = hir.find(fn_hir_id);
let Some(hir::Node::Item(hir::Item { let Some(hir::Node::Item(hir::Item {
kind: hir::ItemKind::Fn(sig, _, body_id), kind: hir::ItemKind::Fn(sig, _, body_id),
@ -1695,7 +1695,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
} }
let hir = self.tcx.hir(); let hir = self.tcx.hir();
let parent_node = hir.get_parent_node(obligation.cause.body_id); let parent_node = hir.parent_id(obligation.cause.body_id);
let node = hir.find(parent_node); let node = hir.find(parent_node);
if let Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, _, body_id), .. })) = if let Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, _, body_id), .. })) =
node node
@ -2291,7 +2291,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
let expr = hir.expect_expr(expr_id); let expr = hir.expect_expr(expr_id);
debug!("target_ty evaluated from {:?}", expr); debug!("target_ty evaluated from {:?}", expr);
let parent = hir.get_parent_node(expr_id); let parent = hir.parent_id(expr_id);
if let Some(hir::Node::Expr(e)) = hir.find(parent) { if let Some(hir::Node::Expr(e)) = hir.find(parent) {
let parent_span = hir.span(parent); let parent_span = hir.span(parent);
let parent_did = parent.owner.to_def_id(); let parent_did = parent.owner.to_def_id();
@ -2512,7 +2512,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
} }
} }
ObligationCauseCode::VariableType(hir_id) => { ObligationCauseCode::VariableType(hir_id) => {
let parent_node = self.tcx.hir().get_parent_node(hir_id); let parent_node = self.tcx.hir().parent_id(hir_id);
match self.tcx.hir().find(parent_node) { match self.tcx.hir().find(parent_node) {
Some(Node::Local(hir::Local { ty: Some(ty), .. })) => { Some(Node::Local(hir::Local { ty: Some(ty), .. })) => {
err.span_suggestion_verbose( err.span_suggestion_verbose(
@ -2992,7 +2992,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
span: Span, span: Span,
) { ) {
let body_hir_id = obligation.cause.body_id; let body_hir_id = obligation.cause.body_id;
let item_id = self.tcx.hir().get_parent_node(body_hir_id); let item_id = self.tcx.hir().parent_id(body_hir_id);
if let Some(body_id) = if let Some(body_id) =
self.tcx.hir().maybe_body_owned_by(self.tcx.hir().local_def_id(item_id)) self.tcx.hir().maybe_body_owned_by(self.tcx.hir().local_def_id(item_id))
@ -3219,7 +3219,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind
&& let hir::Path { res: hir::def::Res::Local(hir_id), .. } = path && let hir::Path { res: hir::def::Res::Local(hir_id), .. } = path
&& let Some(hir::Node::Pat(binding)) = self.tcx.hir().find(*hir_id) && let Some(hir::Node::Pat(binding)) = self.tcx.hir().find(*hir_id)
&& let parent_hir_id = self.tcx.hir().get_parent_node(binding.hir_id) && let parent_hir_id = self.tcx.hir().parent_id(binding.hir_id)
&& let Some(hir::Node::Local(local)) = self.tcx.hir().find(parent_hir_id) && let Some(hir::Node::Local(local)) = self.tcx.hir().find(parent_hir_id)
&& let Some(binding_expr) = local.init && let Some(binding_expr) = local.init
{ {
@ -3287,7 +3287,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind
&& let hir::Path { res: hir::def::Res::Local(hir_id), .. } = path && let hir::Path { res: hir::def::Res::Local(hir_id), .. } = path
&& let Some(hir::Node::Pat(binding)) = self.tcx.hir().find(*hir_id) && let Some(hir::Node::Pat(binding)) = self.tcx.hir().find(*hir_id)
&& let parent_hir_id = self.tcx.hir().get_parent_node(binding.hir_id) && let parent_hir_id = self.tcx.hir().parent_id(binding.hir_id)
&& let Some(parent) = self.tcx.hir().find(parent_hir_id) && let Some(parent) = self.tcx.hir().find(parent_hir_id)
{ {
// We've reached the root of the method call chain... // We've reached the root of the method call chain...

View file

@ -161,7 +161,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
kind: hir::ImplItemKind::Type(..) | hir::ImplItemKind::Fn(..), kind: hir::ImplItemKind::Type(..) | hir::ImplItemKind::Fn(..),
.. ..
}) => { }) => {
let parent_hir_id = tcx.hir().get_parent_node(hir_id); let parent_hir_id = tcx.hir().parent_id(hir_id);
match tcx.hir().get(parent_hir_id) { match tcx.hir().get(parent_hir_id) {
hir::Node::Item(hir::Item { hir::Node::Item(hir::Item {
kind: hir::ItemKind::Impl(hir::Impl { constness, .. }), kind: hir::ItemKind::Impl(hir::Impl { constness, .. }),

View file

@ -131,7 +131,7 @@ fn is_argument(map: rustc_middle::hir::map::Map<'_>, id: HirId) -> bool {
_ => return false, _ => return false,
} }
matches!(map.find(map.get_parent_node(id)), Some(Node::Param(_))) matches!(map.find(map.parent_id(id)), Some(Node::Param(_)))
} }
impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
@ -156,8 +156,8 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
let map = &self.cx.tcx.hir(); let map = &self.cx.tcx.hir();
if is_argument(*map, cmt.hir_id) { if is_argument(*map, cmt.hir_id) {
// Skip closure arguments // Skip closure arguments
let parent_id = map.get_parent_node(cmt.hir_id); let parent_id = map.parent_id(cmt.hir_id);
if let Some(Node::Expr(..)) = map.find(map.get_parent_node(parent_id)) { if let Some(Node::Expr(..)) = map.find(map.parent_id(parent_id)) {
return; return;
} }

View file

@ -251,7 +251,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'a, 'tcx> {
let map = cx.tcx.hir(); let map = cx.tcx.hir();
// Checking for slice indexing // Checking for slice indexing
let parent_id = map.get_parent_node(expr.hir_id); let parent_id = map.parent_id(expr.hir_id);
if let Some(hir::Node::Expr(parent_expr)) = map.find(parent_id); if let Some(hir::Node::Expr(parent_expr)) = map.find(parent_id);
if let hir::ExprKind::Index(_, index_expr) = parent_expr.kind; if let hir::ExprKind::Index(_, index_expr) = parent_expr.kind;
if let Some((Constant::Int(index_value), _)) = constant(cx, cx.typeck_results(), index_expr); if let Some((Constant::Int(index_value), _)) = constant(cx, cx.typeck_results(), index_expr);
@ -259,7 +259,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'a, 'tcx> {
if index_value < max_suggested_slice; if index_value < max_suggested_slice;
// Make sure that this slice index is read only // Make sure that this slice index is read only
let maybe_addrof_id = map.get_parent_node(parent_id); let maybe_addrof_id = map.parent_id(parent_id);
if let Some(hir::Node::Expr(maybe_addrof_expr)) = map.find(maybe_addrof_id); if let Some(hir::Node::Expr(maybe_addrof_expr)) = map.find(maybe_addrof_id);
if let hir::ExprKind::AddrOf(_kind, hir::Mutability::Not, _inner_expr) = maybe_addrof_expr.kind; if let hir::ExprKind::AddrOf(_kind, hir::Mutability::Not, _inner_expr) = maybe_addrof_expr.kind;
then { then {

View file

@ -63,7 +63,7 @@ pub(super) fn check<'tcx>(
if let Node::Pat(pat) = node; if let Node::Pat(pat) = node;
if let PatKind::Binding(bind_ann, ..) = pat.kind; if let PatKind::Binding(bind_ann, ..) = pat.kind;
if !matches!(bind_ann, BindingAnnotation(_, Mutability::Mut)); if !matches!(bind_ann, BindingAnnotation(_, Mutability::Mut));
let parent_node = cx.tcx.hir().get_parent_node(hir_id); let parent_node = cx.tcx.hir().parent_id(hir_id);
if let Some(Node::Local(parent_let_expr)) = cx.tcx.hir().find(parent_node); if let Some(Node::Local(parent_let_expr)) = cx.tcx.hir().find(parent_node);
if let Some(init) = parent_let_expr.init; if let Some(init) = parent_let_expr.init;
then { then {

View file

@ -74,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid {
&& let Some(hir_id) = path_to_local(expr3) && let Some(hir_id) = path_to_local(expr3)
&& let Some(Node::Pat(_)) = cx.tcx.hir().find(hir_id) { && let Some(Node::Pat(_)) = cx.tcx.hir().find(hir_id) {
// Apply only to params or locals with annotated types // Apply only to params or locals with annotated types
match cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { match cx.tcx.hir().find(cx.tcx.hir().parent_id(hir_id)) {
Some(Node::Param(..)) => (), Some(Node::Param(..)) => (),
Some(Node::Local(local)) => { Some(Node::Local(local)) => {
let Some(ty) = local.ty else { return }; let Some(ty) = local.ty else { return };

View file

@ -140,8 +140,8 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e
fn opt_parent_assign_span<'a>(cx: &LateContext<'a>, ex: &Expr<'a>) -> Option<AssignmentExpr> { fn opt_parent_assign_span<'a>(cx: &LateContext<'a>, ex: &Expr<'a>) -> Option<AssignmentExpr> {
let map = &cx.tcx.hir(); let map = &cx.tcx.hir();
if let Some(Node::Expr(parent_arm_expr)) = map.find(map.get_parent_node(ex.hir_id)) { if let Some(Node::Expr(parent_arm_expr)) = map.find(map.parent_id(ex.hir_id)) {
return match map.find(map.get_parent_node(parent_arm_expr.hir_id)) { return match map.find(map.parent_id(parent_arm_expr.hir_id)) {
Some(Node::Local(parent_let_expr)) => Some(AssignmentExpr::Local { Some(Node::Local(parent_let_expr)) => Some(AssignmentExpr::Local {
span: parent_let_expr.span, span: parent_let_expr.span,
pat_span: parent_let_expr.pat.span(), pat_span: parent_let_expr.pat.span(),
@ -183,7 +183,7 @@ fn sugg_with_curlies<'a>(
// If the parent is already an arm, and the body is another match statement, // If the parent is already an arm, and the body is another match statement,
// we need curly braces around suggestion // we need curly braces around suggestion
let parent_node_id = cx.tcx.hir().get_parent_node(match_expr.hir_id); let parent_node_id = cx.tcx.hir().parent_id(match_expr.hir_id);
if let Node::Arm(arm) = &cx.tcx.hir().get(parent_node_id) { if let Node::Arm(arm) = &cx.tcx.hir().get(parent_node_id) {
if let ExprKind::Match(..) = arm.body.kind { if let ExprKind::Match(..) = arm.body.kind {
cbrace_end = format!("\n{indent}}}"); cbrace_end = format!("\n{indent}}}");

View file

@ -186,7 +186,7 @@ fn check_for_unsequenced_reads(vis: &mut ReadVisitor<'_, '_>) {
let map = &vis.cx.tcx.hir(); let map = &vis.cx.tcx.hir();
let mut cur_id = vis.write_expr.hir_id; let mut cur_id = vis.write_expr.hir_id;
loop { loop {
let parent_id = map.get_parent_node(cur_id); let parent_id = map.parent_id(cur_id);
if parent_id == cur_id { if parent_id == cur_id {
break; break;
} }

View file

@ -100,7 +100,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
} }
// Exclude non-inherent impls // Exclude non-inherent impls
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().parent_id(hir_id)) {
if matches!( if matches!(
item.kind, item.kind,
ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..)

View file

@ -366,7 +366,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
let mut dereferenced_expr = expr; let mut dereferenced_expr = expr;
let mut needs_check_adjustment = true; let mut needs_check_adjustment = true;
loop { loop {
let parent_id = cx.tcx.hir().get_parent_node(cur_expr.hir_id); let parent_id = cx.tcx.hir().parent_id(cur_expr.hir_id);
if parent_id == cur_expr.hir_id { if parent_id == cur_expr.hir_id {
break; break;
} }

View file

@ -299,7 +299,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue {
} }
// Exclude non-inherent impls // Exclude non-inherent impls
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().parent_id(hir_id)) {
if matches!( if matches!(
item.kind, item.kind,
ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..)

View file

@ -21,7 +21,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
return; return;
} }
let map = &cx.tcx.hir(); let map = &cx.tcx.hir();
let opt_parent_node = map.find(map.get_parent_node(expr.hir_id)); let opt_parent_node = map.find(map.parent_id(expr.hir_id));
if_chain! { if_chain! {
if let Some(hir::Node::Expr(parent_expr)) = opt_parent_node; if let Some(hir::Node::Expr(parent_expr)) = opt_parent_node;
if is_questionmark_desugar_marked_call(parent_expr); if is_questionmark_desugar_marked_call(parent_expr);
@ -192,7 +192,7 @@ fn fmt_stmts_and_call(
let mut stmts_and_call_snippet = stmts_and_call.join(&format!("{}{}", ";\n", " ".repeat(call_expr_indent))); let mut stmts_and_call_snippet = stmts_and_call.join(&format!("{}{}", ";\n", " ".repeat(call_expr_indent)));
// expr is not in a block statement or result expression position, wrap in a block // expr is not in a block statement or result expression position, wrap in a block
let parent_node = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(call_expr.hir_id)); let parent_node = cx.tcx.hir().find(cx.tcx.hir().parent_id(call_expr.hir_id));
if !matches!(parent_node, Some(Node::Block(_))) && !matches!(parent_node, Some(Node::Stmt(_))) { if !matches!(parent_node, Some(Node::Block(_))) && !matches!(parent_node, Some(Node::Stmt(_))) {
let block_indent = call_expr_indent + 4; let block_indent = call_expr_indent + 4;
stmts_and_call_snippet = stmts_and_call_snippet =

View file

@ -91,7 +91,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps {
} }
// Abort if the method is implementing a trait or of it a trait method. // Abort if the method is implementing a trait or of it a trait method.
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().parent_id(hir_id)) {
if matches!( if matches!(
item.kind, item.kind,
ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..)

View file

@ -1058,7 +1058,7 @@ fn get_parent_local<'hir>(cx: &LateContext<'hir>, expr: &'hir hir::Expr<'hir>) -
fn get_parent_local_hir_id<'hir>(cx: &LateContext<'hir>, hir_id: hir::HirId) -> Option<&'hir hir::Local<'hir>> { fn get_parent_local_hir_id<'hir>(cx: &LateContext<'hir>, hir_id: hir::HirId) -> Option<&'hir hir::Local<'hir>> {
let map = cx.tcx.hir(); let map = cx.tcx.hir();
match map.find(map.get_parent_node(hir_id)) { match map.find(map.parent_id(hir_id)) {
Some(hir::Node::Local(local)) => Some(local), Some(hir::Node::Local(local)) => Some(local),
Some(hir::Node::Pat(pattern)) => get_parent_local_hir_id(cx, pattern.hir_id), Some(hir::Node::Pat(pattern)) => get_parent_local_hir_id(cx, pattern.hir_id),
_ => None, _ => None,

View file

@ -219,7 +219,7 @@ fn path_to_matched_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option<Ve
match peel_hir_expr_refs(expr).0.kind { match peel_hir_expr_refs(expr).0.kind {
ExprKind::Path(ref qpath) => match cx.qpath_res(qpath, expr.hir_id) { ExprKind::Path(ref qpath) => match cx.qpath_res(qpath, expr.hir_id) {
Res::Local(hir_id) => { Res::Local(hir_id) => {
let parent_id = cx.tcx.hir().get_parent_node(hir_id); let parent_id = cx.tcx.hir().parent_id(hir_id);
if let Some(Node::Local(Local { init: Some(init), .. })) = cx.tcx.hir().find(parent_id) { if let Some(Node::Local(Local { init: Some(init), .. })) = cx.tcx.hir().find(parent_id) {
path_to_matched_type(cx, init) path_to_matched_type(cx, init)
} else { } else {

View file

@ -174,7 +174,7 @@ pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<
if_chain! { if_chain! {
if let Some(Node::Pat(pat)) = hir.find(hir_id); if let Some(Node::Pat(pat)) = hir.find(hir_id);
if matches!(pat.kind, PatKind::Binding(BindingAnnotation::NONE, ..)); if matches!(pat.kind, PatKind::Binding(BindingAnnotation::NONE, ..));
let parent = hir.get_parent_node(hir_id); let parent = hir.parent_id(hir_id);
if let Some(Node::Local(local)) = hir.find(parent); if let Some(Node::Local(local)) = hir.find(parent);
then { then {
return local.init; return local.init;
@ -2075,7 +2075,7 @@ pub fn is_no_core_crate(cx: &LateContext<'_>) -> bool {
/// } /// }
/// ``` /// ```
pub fn is_trait_impl_item(cx: &LateContext<'_>, hir_id: HirId) -> bool { pub fn is_trait_impl_item(cx: &LateContext<'_>, hir_id: HirId) -> bool {
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().parent_id(hir_id)) {
matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })) matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }))
} else { } else {
false false