Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit fc8f662

Browse files
committed
hir: Remove hir::Map::{opt_parent_id,parent_id,get_parent,find_parent}
1 parent 8f00ffc commit fc8f662

39 files changed

+78
-102
lines changed

clippy_lints/src/assertions_on_constants.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants {
4646
return;
4747
};
4848
if let ConstantSource::Constant = source
49-
&& let Some(node) = cx.tcx.hir().find_parent(e.hir_id)
5049
&& let Node::Item(Item {
5150
kind: ItemKind::Const(..),
5251
..
53-
}) = node
52+
}) = cx.tcx.parent_hir_node(e.hir_id)
5453
{
5554
return;
5655
}

clippy_lints/src/casts/cast_slice_different_sizes.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,20 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: &Msrv
6767
}
6868

6969
fn is_child_of_cast(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
70-
let map = cx.tcx.hir();
71-
if let Some(parent_id) = map.opt_parent_id(expr.hir_id) {
72-
let parent = cx.tcx.hir_node(parent_id);
73-
let expr = match parent {
74-
Node::Block(block) => {
75-
if let Some(parent_expr) = block.expr {
76-
parent_expr
77-
} else {
78-
return false;
79-
}
80-
},
81-
Node::Expr(expr) => expr,
82-
_ => return false,
83-
};
70+
let parent = cx.tcx.parent_hir_node(expr.hir_id);
71+
let expr = match parent {
72+
Node::Block(block) => {
73+
if let Some(parent_expr) = block.expr {
74+
parent_expr
75+
} else {
76+
return false;
77+
}
78+
},
79+
Node::Expr(expr) => expr,
80+
_ => return false,
81+
};
8482

85-
matches!(expr.kind, ExprKind::Cast(..))
86-
} else {
87-
false
88-
}
83+
matches!(expr.kind, ExprKind::Cast(..))
8984
}
9085

9186
/// Returns the type T of the pointed to *const [T] or *mut [T] and the mutability of the slice if

clippy_lints/src/casts/unnecessary_cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub(super) fn check<'tcx>(
6565
&& let ExprKind::Path(qpath) = inner.kind
6666
&& let QPath::Resolved(None, Path { res, .. }) = qpath
6767
&& let Res::Local(hir_id) = res
68-
&& let parent = cx.tcx.hir().get_parent(*hir_id)
68+
&& let parent = cx.tcx.parent_hir_node(*hir_id)
6969
&& let Node::Local(local) = parent
7070
{
7171
if let Some(ty) = local.ty

clippy_lints/src/dbg_macro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl LateLintPass<'_> for DbgMacro {
6363
ExprKind::Block(..) => {
6464
// If the `dbg!` macro is a "free" statement and not contained within other expressions,
6565
// remove the whole statement.
66-
if let Some(Node::Stmt(_)) = cx.tcx.hir().find_parent(expr.hir_id)
66+
if let Node::Stmt(_) = cx.tcx.parent_hir_node(expr.hir_id)
6767
&& let Some(semi_span) = cx.sess().source_map().mac_call_stmt_semi_span(macro_call.span)
6868
{
6969
(macro_call.span.to(semi_span), String::new())

clippy_lints/src/default_numeric_fallback.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
128128
},
129129
_,
130130
) => {
131-
if let Some(parent) = self.cx.tcx.hir().find_parent(expr.hir_id)
132-
&& let Some(fn_sig) = parent.fn_sig()
131+
if let Some(fn_sig) = self.cx.tcx.parent_hir_node(expr.hir_id).fn_sig()
133132
&& let FnRetTy::Return(_ty) = fn_sig.decl.output
134133
{
135134
// We cannot check the exact type since it's a `hir::Ty`` which does not implement `is_numeric`

clippy_lints/src/dereference.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ fn report<'tcx>(
10881088
//
10891089
// e.g. `&mut x.y.z` where `x` is a union, and accessing `z` requires a
10901090
// deref through `ManuallyDrop<_>` will not compile.
1091-
let parent_id = cx.tcx.hir().parent_id(expr.hir_id);
1091+
let parent_id = cx.tcx.parent_hir_id(expr.hir_id);
10921092
if parent_id == data.first_expr.hir_id {
10931093
return;
10941094
}

clippy_lints/src/escape.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fn is_argument(tcx: TyCtxt<'_>, id: HirId) -> bool {
131131
_ => return false,
132132
}
133133

134-
matches!(tcx.hir().find_parent(id), Some(Node::Param(_)))
134+
matches!(tcx.parent_hir_node(id), Node::Param(_))
135135
}
136136

137137
impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
@@ -156,8 +156,8 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
156156
let map = &self.cx.tcx.hir();
157157
if is_argument(self.cx.tcx, cmt.hir_id) {
158158
// Skip closure arguments
159-
let parent_id = map.parent_id(cmt.hir_id);
160-
if let Some(Node::Expr(..)) = map.find_parent(parent_id) {
159+
let parent_id = self.cx.tcx.parent_hir_id(cmt.hir_id);
160+
if let Node::Expr(..) = self.cx.tcx.parent_hir_node(parent_id) {
161161
return;
162162
}
163163

clippy_lints/src/functions/impl_trait_in_params.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub(super) fn check_fn<'tcx>(cx: &LateContext<'_>, kind: &'tcx FnKind<'_>, body:
5353

5454
pub(super) fn check_impl_item(cx: &LateContext<'_>, impl_item: &ImplItem<'_>) {
5555
if let ImplItemKind::Fn(_, body_id) = impl_item.kind
56-
&& let hir::Node::Item(item) = cx.tcx.hir().get_parent(impl_item.hir_id())
56+
&& let hir::Node::Item(item) = cx.tcx.parent_hir_node(impl_item.hir_id())
5757
&& let hir::ItemKind::Impl(impl_) = item.kind
5858
&& let hir::Impl { of_trait, .. } = *impl_
5959
&& of_trait.is_none()
@@ -72,7 +72,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, impl_item: &ImplItem<'_>) {
7272
pub(super) fn check_trait_item(cx: &LateContext<'_>, trait_item: &TraitItem<'_>, avoid_breaking_exported_api: bool) {
7373
if !avoid_breaking_exported_api
7474
&& let TraitItemKind::Fn(_, _) = trait_item.kind
75-
&& let hir::Node::Item(item) = cx.tcx.hir().get_parent(trait_item.hir_id())
75+
&& let hir::Node::Item(item) = cx.tcx.parent_hir_node(trait_item.hir_id())
7676
// ^^ (Will always be a trait)
7777
&& !item.vis_span.is_empty() // Is public
7878
&& !is_in_test_function(cx.tcx, trait_item.hir_id())

clippy_lints/src/ignored_unit_patterns.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ impl<'tcx> LateLintPass<'tcx> for IgnoredUnitPatterns {
4141
return;
4242
}
4343

44-
match cx.tcx.hir().get_parent(pat.hir_id) {
45-
Node::Param(param) if matches!(cx.tcx.hir().get_parent(param.hir_id), Node::Item(_)) => {
44+
match cx.tcx.parent_hir_node(pat.hir_id) {
45+
Node::Param(param) if matches!(cx.tcx.parent_hir_node(param.hir_id), Node::Item(_)) => {
4646
// Ignore function parameters
4747
return;
4848
},

clippy_lints/src/index_refutable_slice.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,24 +242,19 @@ impl<'a, 'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'a, 'tcx> {
242242
} = *self;
243243

244244
if let Some(use_info) = slice_lint_info.get_mut(&local_id)
245-
// Check if this is even a local we're interested in
246-
247-
&& let map = cx.tcx.hir()
248-
249245
// Checking for slice indexing
250-
&& let parent_id = map.parent_id(expr.hir_id)
246+
&& let parent_id = cx.tcx.parent_hir_id(expr.hir_id)
251247
&& let hir::Node::Expr(parent_expr) = cx.tcx.hir_node(parent_id)
252248
&& let hir::ExprKind::Index(_, index_expr, _) = parent_expr.kind
253249
&& let Some(Constant::Int(index_value)) = constant(cx, cx.typeck_results(), index_expr)
254250
&& let Ok(index_value) = index_value.try_into()
255251
&& index_value < max_suggested_slice
256252

257253
// Make sure that this slice index is read only
258-
&& let maybe_addrof_id = map.parent_id(parent_id)
259-
&& let hir::Node::Expr(maybe_addrof_expr) = cx.tcx.hir_node(maybe_addrof_id)
254+
&& let hir::Node::Expr(maybe_addrof_expr) = cx.tcx.parent_hir_node(parent_id)
260255
&& let hir::ExprKind::AddrOf(_kind, hir::Mutability::Not, _inner_expr) = maybe_addrof_expr.kind
261256
{
262-
use_info.index_use.push((index_value, map.span(parent_expr.hir_id)));
257+
use_info.index_use.push((index_value, cx.tcx.hir().span(parent_expr.hir_id)));
263258
return;
264259
}
265260

0 commit comments

Comments
 (0)