Skip to content

Commit 10c9903

Browse files
committed
Auto merge of #12348 - Alexendoo:remove-get-parent-node, r=y21
Remove `clippy_utils::get_parent_node` Since it's forwarding to a single method it seems reasonable to use that one directly instead changelog: none
2 parents c469cb0 + bee4111 commit 10c9903

20 files changed

+47
-58
lines changed

clippy_lints/src/box_default.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::macros::macro_backtrace;
33
use clippy_utils::ty::expr_sig;
4-
use clippy_utils::{get_parent_node, is_default_equivalent, path_def_id};
4+
use clippy_utils::{is_default_equivalent, path_def_id};
55
use rustc_errors::Applicability;
66
use rustc_hir::def::Res;
77
use rustc_hir::intravisit::{walk_ty, Visitor};
@@ -100,7 +100,7 @@ impl<'tcx> Visitor<'tcx> for InferVisitor {
100100
}
101101

102102
fn given_type(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
103-
match get_parent_node(cx.tcx, expr.hir_id) {
103+
match cx.tcx.parent_hir_node(expr.hir_id) {
104104
Node::Local(Local { ty: Some(ty), .. }) => {
105105
let mut v = InferVisitor::default();
106106
v.visit_ty(ty);

clippy_lints/src/casts/unnecessary_cast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::numeric_literal::NumericLiteral;
33
use clippy_utils::source::snippet_opt;
44
use clippy_utils::visitors::{for_each_expr, Visitable};
5-
use clippy_utils::{get_parent_expr, get_parent_node, is_hir_ty_cfg_dependant, is_ty_alias, path_to_local};
5+
use clippy_utils::{get_parent_expr, is_hir_ty_cfg_dependant, is_ty_alias, path_to_local};
66
use rustc_ast::{LitFloatType, LitIntType, LitKind};
77
use rustc_errors::Applicability;
88
use rustc_hir::def::{DefKind, Res};
@@ -264,7 +264,7 @@ fn is_cast_from_ty_alias<'tcx>(cx: &LateContext<'tcx>, expr: impl Visitable<'tcx
264264
}
265265
// Local usage
266266
} else if let Res::Local(hir_id) = res
267-
&& let Node::Local(l) = get_parent_node(cx.tcx, hir_id)
267+
&& let Node::Local(l) = cx.tcx.parent_hir_node(hir_id)
268268
{
269269
if let Some(e) = l.init
270270
&& is_cast_from_ty_alias(cx, e, cast_from)

clippy_lints/src/collection_is_never_read.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint;
22
use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item};
33
use clippy_utils::visitors::for_each_expr_with_closures;
4-
use clippy_utils::{get_enclosing_block, get_parent_node, path_to_local_id};
4+
use clippy_utils::{get_enclosing_block, path_to_local_id};
55
use core::ops::ControlFlow;
66
use rustc_hir::{Block, ExprKind, HirId, LangItem, Local, Node, PatKind};
77
use rustc_lint::{LateContext, LateLintPass};
@@ -94,7 +94,7 @@ fn has_no_read_access<'tcx>(cx: &LateContext<'tcx>, id: HirId, block: &'tcx Bloc
9494
// `id` appearing in the left-hand side of an assignment is not a read access:
9595
//
9696
// id = ...; // Not reading `id`.
97-
if let Node::Expr(parent) = get_parent_node(cx.tcx, expr.hir_id)
97+
if let Node::Expr(parent) = cx.tcx.parent_hir_node(expr.hir_id)
9898
&& let ExprKind::Assign(lhs, ..) = parent.kind
9999
&& path_to_local_id(lhs, id)
100100
{
@@ -108,7 +108,7 @@ fn has_no_read_access<'tcx>(cx: &LateContext<'tcx>, id: HirId, block: &'tcx Bloc
108108
// Only assuming this for "official" methods defined on the type. For methods defined in extension
109109
// traits (identified as local, based on the orphan rule), pessimistically assume that they might
110110
// have side effects, so consider them a read.
111-
if let Node::Expr(parent) = get_parent_node(cx.tcx, expr.hir_id)
111+
if let Node::Expr(parent) = cx.tcx.parent_hir_node(expr.hir_id)
112112
&& let ExprKind::MethodCall(_, receiver, _, _) = parent.kind
113113
&& path_to_local_id(receiver, id)
114114
&& let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id)
@@ -117,7 +117,7 @@ fn has_no_read_access<'tcx>(cx: &LateContext<'tcx>, id: HirId, block: &'tcx Bloc
117117
// The method call is a statement, so the return value is not used. That's not a read access:
118118
//
119119
// id.foo(args);
120-
if let Node::Stmt(..) = get_parent_node(cx.tcx, parent.hir_id) {
120+
if let Node::Stmt(..) = cx.tcx.parent_hir_node(parent.hir_id) {
121121
return ControlFlow::Continue(());
122122
}
123123

clippy_lints/src/dereference.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then};
22
use clippy_utils::source::{snippet_with_applicability, snippet_with_context};
33
use clippy_utils::sugg::has_enclosing_paren;
44
use clippy_utils::ty::{implements_trait, is_manually_drop, peel_mid_ty_refs};
5-
use clippy_utils::{
6-
expr_use_ctxt, get_parent_expr, get_parent_node, is_lint_allowed, path_to_local, DefinedTy, ExprUseNode,
7-
};
5+
use clippy_utils::{expr_use_ctxt, get_parent_expr, is_lint_allowed, path_to_local, DefinedTy, ExprUseNode};
86
use core::mem;
97
use rustc_ast::util::parser::{PREC_POSTFIX, PREC_PREFIX};
108
use rustc_data_structures::fx::FxIndexMap;
@@ -1008,7 +1006,7 @@ fn report<'tcx>(
10081006
data.first_expr.span,
10091007
state.msg,
10101008
|diag| {
1011-
let (precedence, calls_field) = match get_parent_node(cx.tcx, data.first_expr.hir_id) {
1009+
let (precedence, calls_field) = match cx.tcx.parent_hir_node(data.first_expr.hir_id) {
10121010
Node::Expr(e) => match e.kind {
10131011
ExprKind::Call(callee, _) if callee.hir_id != data.first_expr.hir_id => (0, false),
10141012
ExprKind::Call(..) => (PREC_POSTFIX, matches!(expr.kind, ExprKind::Field(..))),

clippy_lints/src/drop_forget_ref.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_note;
2+
use clippy_utils::is_must_use_func_call;
23
use clippy_utils::ty::{is_copy, is_must_use_ty, is_type_lang_item};
3-
use clippy_utils::{get_parent_node, is_must_use_func_call};
44
use rustc_hir::{Arm, Expr, ExprKind, LangItem, Node};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_session::declare_lint_pass;
@@ -144,7 +144,7 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
144144
// }
145145
fn is_single_call_in_arm<'tcx>(cx: &LateContext<'tcx>, arg: &'tcx Expr<'_>, drop_expr: &'tcx Expr<'_>) -> bool {
146146
if matches!(arg.kind, ExprKind::Call(..) | ExprKind::MethodCall(..)) {
147-
if let Node::Arm(Arm { body, .. }) = get_parent_node(cx.tcx, drop_expr.hir_id) {
147+
if let Node::Arm(Arm { body, .. }) = cx.tcx.parent_hir_node(drop_expr.hir_id) {
148148
return body.hir_id == drop_expr.hir_id;
149149
}
150150
}

clippy_lints/src/iter_not_returning_iterator.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use clippy_utils::diagnostics::span_lint;
2-
use clippy_utils::get_parent_node;
32
use clippy_utils::ty::implements_trait;
43
use rustc_hir::def_id::LocalDefId;
54
use rustc_hir::{FnSig, ImplItem, ImplItemKind, Item, ItemKind, Node, TraitItem, TraitItemKind};
@@ -56,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for IterNotReturningIterator {
5655
let name = item.ident.name.as_str();
5756
if matches!(name, "iter" | "iter_mut")
5857
&& !matches!(
59-
get_parent_node(cx.tcx, item.hir_id()),
58+
cx.tcx.parent_hir_node(item.hir_id()),
6059
Node::Item(Item { kind: ItemKind::Impl(i), .. }) if i.of_trait.is_some()
6160
)
6261
{

clippy_lints/src/matches/needless_match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
33
use clippy_utils::source::snippet_with_applicability;
44
use clippy_utils::ty::{is_type_diagnostic_item, same_type_and_consts};
55
use clippy_utils::{
6-
eq_expr_value, get_parent_expr_for_hir, get_parent_node, higher, is_else_clause, is_res_lang_ctor, over, path_res,
6+
eq_expr_value, get_parent_expr_for_hir, higher, is_else_clause, is_res_lang_ctor, over, path_res,
77
peel_blocks_with_stmt,
88
};
99
use rustc_errors::Applicability;
@@ -123,7 +123,7 @@ fn strip_return<'hir>(expr: &'hir Expr<'hir>) -> &'hir Expr<'hir> {
123123
/// Manually check for coercion casting by checking if the type of the match operand or let expr
124124
/// differs with the assigned local variable or the function return type.
125125
fn expr_ty_matches_p_ty(cx: &LateContext<'_>, expr: &Expr<'_>, p_expr: &Expr<'_>) -> bool {
126-
match get_parent_node(cx.tcx, p_expr.hir_id) {
126+
match cx.tcx.parent_hir_node(p_expr.hir_id) {
127127
// Compare match_expr ty with local in `let local = match match_expr {..}`
128128
Node::Local(local) => {
129129
let results = cx.typeck_results();

clippy_lints/src/methods/clone_on_copy.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
2-
use clippy_utils::get_parent_node;
32
use clippy_utils::source::snippet_with_context;
43
use clippy_utils::ty::is_copy;
54
use rustc_errors::Applicability;
@@ -48,7 +47,7 @@ pub(super) fn check(
4847
}
4948

5049
if is_copy(cx, ty) {
51-
let parent_is_suffix_expr = match get_parent_node(cx.tcx, expr.hir_id) {
50+
let parent_is_suffix_expr = match cx.tcx.parent_hir_node(expr.hir_id) {
5251
Node::Expr(parent) => match parent.kind {
5352
// &*x is a nop, &x.clone() is not
5453
ExprKind::AddrOf(..) => return,

clippy_lints/src/methods/needless_collect.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use clippy_utils::source::{snippet, snippet_with_applicability};
44
use clippy_utils::sugg::Sugg;
55
use clippy_utils::ty::{is_type_diagnostic_item, make_normalized_projection, make_projection};
66
use clippy_utils::{
7-
can_move_expr_to_closure, fn_def_id, get_enclosing_block, get_parent_node, higher, is_trait_method, path_to_local,
8-
path_to_local_id, CaptureKind,
7+
can_move_expr_to_closure, fn_def_id, get_enclosing_block, higher, is_trait_method, path_to_local, path_to_local_id,
8+
CaptureKind,
99
};
1010
use rustc_data_structures::fx::FxHashMap;
1111
use rustc_errors::{Applicability, MultiSpan};
@@ -28,7 +28,7 @@ pub(super) fn check<'tcx>(
2828
iter_expr: &'tcx Expr<'tcx>,
2929
call_span: Span,
3030
) {
31-
match get_parent_node(cx.tcx, collect_expr.hir_id) {
31+
match cx.tcx.parent_hir_node(collect_expr.hir_id) {
3232
Node::Expr(parent) => {
3333
check_collect_into_intoiterator(cx, parent, collect_expr, call_span, iter_expr);
3434

clippy_lints/src/needless_bool.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg};
66
use clippy_utils::source::snippet_with_applicability;
77
use clippy_utils::sugg::Sugg;
88
use clippy_utils::{
9-
get_parent_node, higher, is_else_clause, is_expn_of, peel_blocks, peel_blocks_with_stmt, span_extract_comment,
10-
SpanlessEq,
9+
higher, is_else_clause, is_expn_of, peel_blocks, peel_blocks_with_stmt, span_extract_comment, SpanlessEq,
1110
};
1211
use rustc_ast::ast::LitKind;
1312
use rustc_errors::Applicability;
@@ -138,7 +137,7 @@ fn condition_needs_parentheses(e: &Expr<'_>) -> bool {
138137

139138
fn is_parent_stmt(cx: &LateContext<'_>, id: HirId) -> bool {
140139
matches!(
141-
get_parent_node(cx.tcx, id),
140+
cx.tcx.parent_hir_node(id),
142141
Node::Stmt(..) | Node::Block(Block { stmts: &[], .. })
143142
)
144143
}

clippy_lints/src/needless_pass_by_ref_mut.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::needless_pass_by_value::requires_exact_signature;
22
use clippy_utils::diagnostics::span_lint_hir_and_then;
33
use clippy_utils::source::snippet;
44
use clippy_utils::visitors::for_each_expr_with_closures;
5-
use clippy_utils::{get_parent_node, inherits_cfg, is_from_proc_macro, is_self};
5+
use clippy_utils::{inherits_cfg, is_from_proc_macro, is_self};
66
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
77
use rustc_errors::Applicability;
88
use rustc_hir::intravisit::FnKind;
@@ -239,7 +239,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
239239
&& let ty::FnDef(def_id, _) = cx.typeck_results().expr_ty(expr).kind()
240240
&& let Some(def_id) = def_id.as_local()
241241
{
242-
if let Node::Expr(e) = get_parent_node(cx.tcx, expr.hir_id)
242+
if let Node::Expr(e) = cx.tcx.parent_hir_node(expr.hir_id)
243243
&& let ExprKind::Call(call, _) = e.kind
244244
&& call.hir_id == expr.hir_id
245245
{

clippy_lints/src/no_effect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::{span_lint_hir, span_lint_hir_and_then};
22
use clippy_utils::source::snippet_opt;
33
use clippy_utils::ty::has_drop;
4-
use clippy_utils::{any_parent_is_automatically_derived, get_parent_node, is_lint_allowed, path_to_local, peel_blocks};
4+
use clippy_utils::{any_parent_is_automatically_derived, is_lint_allowed, path_to_local, peel_blocks};
55
use rustc_errors::Applicability;
66
use rustc_hir::def::{DefKind, Res};
77
use rustc_hir::{
@@ -140,7 +140,7 @@ impl NoEffect {
140140
for parent in cx.tcx.hir().parent_iter(stmt.hir_id) {
141141
if let Node::Item(item) = parent.1
142142
&& let ItemKind::Fn(..) = item.kind
143-
&& let Node::Block(block) = get_parent_node(cx.tcx, stmt.hir_id)
143+
&& let Node::Block(block) = cx.tcx.parent_hir_node(stmt.hir_id)
144144
&& let [.., final_stmt] = block.stmts
145145
&& final_stmt.hir_id == stmt.hir_id
146146
{

clippy_lints/src/non_canonical_impls.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
22
use clippy_utils::ty::implements_trait;
3-
use clippy_utils::{get_parent_node, is_res_lang_ctor, last_path_segment, path_res, std_or_core};
3+
use clippy_utils::{is_res_lang_ctor, last_path_segment, path_res, std_or_core};
44
use rustc_errors::Applicability;
55
use rustc_hir::def_id::LocalDefId;
66
use rustc_hir::{Expr, ExprKind, ImplItem, ImplItemKind, LangItem, Node, UnOp};
@@ -112,7 +112,7 @@ declare_lint_pass!(NonCanonicalImpls => [NON_CANONICAL_CLONE_IMPL, NON_CANONICAL
112112
impl LateLintPass<'_> for NonCanonicalImpls {
113113
#[expect(clippy::too_many_lines)]
114114
fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &ImplItem<'_>) {
115-
let Node::Item(item) = get_parent_node(cx.tcx, impl_item.hir_id()) else {
115+
let Node::Item(item) = cx.tcx.parent_hir_node(impl_item.hir_id()) else {
116116
return;
117117
};
118118
let Some(trait_impl) = cx.tcx.impl_trait_ref(item.owner_id).map(EarlyBinder::skip_binder) else {

clippy_lints/src/only_used_in_recursion.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
2-
use clippy_utils::{get_expr_use_or_unification_node, get_parent_node, path_def_id, path_to_local, path_to_local_id};
2+
use clippy_utils::{get_expr_use_or_unification_node, path_def_id, path_to_local, path_to_local_id};
33
use core::cell::Cell;
44
use rustc_data_structures::fx::FxHashMap;
55
use rustc_errors::Applicability;
@@ -227,7 +227,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
227227
}
228228
// `skip_params` is either `0` or `1` to skip the `self` parameter in trait functions.
229229
// It can't be renamed, and it can't be removed without removing it from multiple functions.
230-
let (fn_id, fn_kind, skip_params) = match get_parent_node(cx.tcx, body.value.hir_id) {
230+
let (fn_id, fn_kind, skip_params) = match cx.tcx.parent_hir_node(body.value.hir_id) {
231231
Node::Item(i) => (i.owner_id.to_def_id(), FnKind::Fn, 0),
232232
Node::TraitItem(&TraitItem {
233233
kind: TraitItemKind::Fn(ref sig, _),
@@ -244,7 +244,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
244244
..
245245
}) => {
246246
#[allow(trivial_casts)]
247-
if let Node::Item(item) = get_parent_node(cx.tcx, owner_id.into())
247+
if let Node::Item(item) = cx.tcx.parent_hir_node(owner_id.into())
248248
&& let Some(trait_ref) = cx
249249
.tcx
250250
.impl_trait_ref(item.owner_id)

clippy_lints/src/question_mark.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
66
use clippy_utils::source::snippet_with_applicability;
77
use clippy_utils::ty::is_type_diagnostic_item;
88
use clippy_utils::{
9-
eq_expr_value, get_parent_node, higher, in_constant, is_else_clause, is_lint_allowed, is_path_lang_item,
10-
is_res_lang_ctor, pat_and_expr_can_be_question_mark, path_to_local, path_to_local_id, peel_blocks,
11-
peel_blocks_with_stmt, span_contains_comment,
9+
eq_expr_value, higher, in_constant, is_else_clause, is_lint_allowed, is_path_lang_item, is_res_lang_ctor,
10+
pat_and_expr_can_be_question_mark, path_to_local, path_to_local_id, peel_blocks, peel_blocks_with_stmt,
11+
span_contains_comment,
1212
};
1313
use rustc_errors::Applicability;
1414
use rustc_hir::def::Res;
@@ -289,7 +289,7 @@ impl QuestionMark {
289289
{
290290
let mut applicability = Applicability::MachineApplicable;
291291
let receiver_str = snippet_with_applicability(cx, let_expr.span, "..", &mut applicability);
292-
let requires_semi = matches!(get_parent_node(cx.tcx, expr.hir_id), Node::Stmt(_));
292+
let requires_semi = matches!(cx.tcx.parent_hir_node(expr.hir_id), Node::Stmt(_));
293293
let sugg = format!(
294294
"{receiver_str}{}?{}",
295295
if by_ref == ByRef::Yes { ".as_ref()" } else { "" },

clippy_lints/src/redundant_closure_call.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::rustc_lint::LintContext;
22
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
3+
use clippy_utils::get_parent_expr;
34
use clippy_utils::sugg::Sugg;
4-
use clippy_utils::{get_parent_expr, get_parent_node};
55
use hir::Param;
66
use rustc_errors::Applicability;
77
use rustc_hir as hir;
@@ -200,7 +200,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall {
200200
hint = hint.asyncify();
201201
}
202202

203-
let is_in_fn_call_arg = if let Node::Expr(expr) = get_parent_node(cx.tcx, expr.hir_id) {
203+
let is_in_fn_call_arg = if let Node::Expr(expr) = cx.tcx.parent_hir_node(expr.hir_id) {
204204
matches!(expr.kind, hir::ExprKind::Call(_, _))
205205
} else {
206206
false

clippy_lints/src/strlen_on_c_strings.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
2+
use clippy_utils::match_libc_symbol;
23
use clippy_utils::source::snippet_with_context;
34
use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item};
45
use clippy_utils::visitors::is_expr_unsafe;
5-
use clippy_utils::{get_parent_node, match_libc_symbol};
66
use rustc_errors::Applicability;
77
use rustc_hir::{Block, BlockCheckMode, Expr, ExprKind, LangItem, Node, UnsafeSource};
88
use rustc_lint::{LateContext, LateLintPass};
@@ -50,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for StrlenOnCStrings {
5050
&& path.ident.name == sym::as_ptr
5151
{
5252
let ctxt = expr.span.ctxt();
53-
let span = match get_parent_node(cx.tcx, expr.hir_id) {
53+
let span = match cx.tcx.parent_hir_node(expr.hir_id) {
5454
Node::Block(&Block {
5555
rules: BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided),
5656
span,

0 commit comments

Comments
 (0)