Skip to content

Commit 036d00b

Browse files
committed
Auto merge of rust-lang#120951 - matthiaskrgr:rollup-0nnm7dv, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#110483 (Create try_new function for ThinBox) - rust-lang#120740 (Make cmath.rs a single file) - rust-lang#120872 (hir: Refactor getters for HIR parents) - rust-lang#120880 (add note on comparing vtables / function pointers) - rust-lang#120885 (interpret/visitor: ensure we only see normalized types) - rust-lang#120888 (assert_unsafe_precondition cleanup) - rust-lang#120897 (Encode `coroutine_for_closure` for foreign crates) - rust-lang#120937 ([docs] Update armv6k-nintendo-3ds platform docs for outdated info) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 70a8dc7 + fc8f662 commit 036d00b

39 files changed

+78
-102
lines changed

clippy_lints/src/assertions_on_constants.rs

+1-2
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

+13-18
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

+1-1
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

+1-1
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

+1-2
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

+1-1
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

+3-3
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

+2-2
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

+2-2
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

+3-8
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

clippy_lints/src/iter_without_into_iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl {self_ty_without_ref} {{
269269
// }
270270
let span_behind_impl = cx
271271
.tcx
272-
.def_span(cx.tcx.hir().parent_id(item.hir_id()).owner.def_id)
272+
.def_span(cx.tcx.parent_hir_id(item.hir_id()).owner.def_id)
273273
.shrink_to_lo();
274274

275275
let sugg = format!(

clippy_lints/src/lifetimes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ fn elision_suggestions(
285285
.iter()
286286
.filter(|usage| named_lifetime(usage).map_or(false, |id| elidable_lts.contains(&id)))
287287
.map(|usage| {
288-
match cx.tcx.hir().get_parent(usage.hir_id) {
288+
match cx.tcx.parent_hir_node(usage.hir_id) {
289289
Node::Ty(Ty {
290290
kind: TyKind::Ref(..), ..
291291
}) => {

clippy_lints/src/loops/same_item_push.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ pub(super) fn check<'tcx>(
6262
if let Node::Pat(pat) = node
6363
&& let PatKind::Binding(bind_ann, ..) = pat.kind
6464
&& !matches!(bind_ann, BindingAnnotation(_, Mutability::Mut))
65-
&& let parent_node = cx.tcx.hir().parent_id(hir_id)
66-
&& let Node::Local(parent_let_expr) = cx.tcx.hir_node(parent_node)
65+
&& let Node::Local(parent_let_expr) = cx.tcx.parent_hir_node(hir_id)
6766
&& let Some(init) = parent_let_expr.init
6867
{
6968
match init.kind {

clippy_lints/src/manual_hash_one.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ impl LateLintPass<'_> for ManualHashOne {
6868
&& let ExprKind::MethodCall(seg, build_hasher, [], _) = init.kind
6969
&& seg.ident.name == sym!(build_hasher)
7070

71-
&& let Node::Stmt(local_stmt) = cx.tcx.hir().get_parent(local.hir_id)
72-
&& let Node::Block(block) = cx.tcx.hir().get_parent(local_stmt.hir_id)
71+
&& let Node::Stmt(local_stmt) = cx.tcx.parent_hir_node(local.hir_id)
72+
&& let Node::Block(block) = cx.tcx.parent_hir_node(local_stmt.hir_id)
7373

7474
&& let mut stmts = block.stmts.iter()
7575
.skip_while(|stmt| stmt.hir_id != local_stmt.hir_id)
@@ -91,7 +91,7 @@ impl LateLintPass<'_> for ManualHashOne {
9191

9292
// `hasher.finish()`, may be anywhere in a statement or the trailing expr of the block
9393
&& let Some(path_expr) = local_used_once(cx, (maybe_finish_stmt, block.expr), hasher)
94-
&& let Node::Expr(finish_expr) = cx.tcx.hir().get_parent(path_expr.hir_id)
94+
&& let Node::Expr(finish_expr) = cx.tcx.parent_hir_node(path_expr.hir_id)
9595
&& !finish_expr.span.from_expansion()
9696
&& let ExprKind::MethodCall(seg, _, [], _) = finish_expr.kind
9797
&& seg.ident.name == sym!(finish)

clippy_lints/src/manual_rem_euclid.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid {
7979
&& let Node::Pat(_) = cx.tcx.hir_node(hir_id)
8080
{
8181
// Apply only to params or locals with annotated types
82-
match cx.tcx.hir().find_parent(hir_id) {
83-
Some(Node::Param(..)) => (),
84-
Some(Node::Local(local)) => {
82+
match cx.tcx.parent_hir_node(hir_id) {
83+
Node::Param(..) => (),
84+
Node::Local(local) => {
8585
let Some(ty) = local.ty else { return };
8686
if matches!(ty.kind, TyKind::Infer) {
8787
return;

clippy_lints/src/matches/match_single_binding.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e
3636
.to_string();
3737

3838
// Do we need to add ';' to suggestion ?
39-
if let Node::Stmt(stmt) = cx.tcx.hir().get_parent(expr.hir_id)
39+
if let Node::Stmt(stmt) = cx.tcx.parent_hir_node(expr.hir_id)
4040
&& let StmtKind::Expr(_) = stmt.kind
4141
&& match match_body.kind {
4242
// We don't need to add a ; to blocks, unless that block is from a macro expansion
@@ -146,18 +146,16 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e
146146

147147
/// Returns true if the `ex` match expression is in a local (`let`) or assign expression
148148
fn opt_parent_assign_span<'a>(cx: &LateContext<'a>, ex: &Expr<'a>) -> Option<AssignmentExpr> {
149-
let map = &cx.tcx.hir();
150-
151-
if let Some(Node::Expr(parent_arm_expr)) = map.find_parent(ex.hir_id) {
152-
return match map.find_parent(parent_arm_expr.hir_id) {
153-
Some(Node::Local(parent_let_expr)) => Some(AssignmentExpr::Local {
149+
if let Node::Expr(parent_arm_expr) = cx.tcx.parent_hir_node(ex.hir_id) {
150+
return match cx.tcx.parent_hir_node(parent_arm_expr.hir_id) {
151+
Node::Local(parent_let_expr) => Some(AssignmentExpr::Local {
154152
span: parent_let_expr.span,
155153
pat_span: parent_let_expr.pat.span(),
156154
}),
157-
Some(Node::Expr(Expr {
155+
Node::Expr(Expr {
158156
kind: ExprKind::Assign(parent_assign_expr, match_expr, _),
159157
..
160-
})) => Some(AssignmentExpr::Assign {
158+
}) => Some(AssignmentExpr::Assign {
161159
span: parent_assign_expr.span,
162160
match_span: match_expr.span,
163161
}),
@@ -191,7 +189,7 @@ fn sugg_with_curlies<'a>(
191189

192190
// If the parent is already an arm, and the body is another match statement,
193191
// we need curly braces around suggestion
194-
if let Node::Arm(arm) = &cx.tcx.hir().get_parent(match_expr.hir_id) {
192+
if let Node::Arm(arm) = &cx.tcx.parent_hir_node(match_expr.hir_id) {
195193
if let ExprKind::Match(..) = arm.body.kind {
196194
cbrace_end = format!("\n{indent}}}");
197195
// Fix body indent due to the match

clippy_lints/src/matches/redundant_guards.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ fn get_pat_binding<'tcx>(
199199
return span.map(|span| PatBindingInfo {
200200
span,
201201
byref_ident,
202-
is_field: matches!(cx.tcx.hir().get_parent(local), Node::PatField(_)),
202+
is_field: matches!(cx.tcx.parent_hir_node(local), Node::PatField(_)),
203203
});
204204
}
205205
}

clippy_lints/src/methods/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4458,7 +4458,7 @@ impl Methods {
44584458
_ => {},
44594459
},
44604460
("drain", ..) => {
4461-
if let Node::Stmt(Stmt { hir_id: _, kind, .. }) = cx.tcx.hir().get_parent(expr.hir_id)
4461+
if let Node::Stmt(Stmt { hir_id: _, kind, .. }) = cx.tcx.parent_hir_node(expr.hir_id)
44624462
&& matches!(kind, StmtKind::Semi(_))
44634463
&& args.len() <= 1
44644464
{

clippy_lints/src/methods/readonly_write_lock.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ fn is_unwrap_call(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
2121

2222
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, receiver: &Expr<'_>) {
2323
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(receiver).peel_refs(), sym::RwLock)
24-
&& let Node::Expr(unwrap_call_expr) = cx.tcx.hir().get_parent(expr.hir_id)
24+
&& let Node::Expr(unwrap_call_expr) = cx.tcx.parent_hir_node(expr.hir_id)
2525
&& is_unwrap_call(cx, unwrap_call_expr)
26-
&& let parent = cx.tcx.hir().get_parent(unwrap_call_expr.hir_id)
26+
&& let parent = cx.tcx.parent_hir_node(unwrap_call_expr.hir_id)
2727
&& let Node::Local(local) = parent
2828
&& let Some(mir) = enclosing_mir(cx.tcx, expr.hir_id)
2929
&& let Some((local, _)) = mir

clippy_lints/src/methods/unnecessary_fold.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use super::UNNECESSARY_FOLD;
1616
/// Changing `fold` to `sum` needs it sometimes when the return type can't be
1717
/// inferred. This checks for some common cases where it can be safely omitted
1818
fn needs_turbofish(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool {
19-
let parent = cx.tcx.hir().get_parent(expr.hir_id);
19+
let parent = cx.tcx.parent_hir_node(expr.hir_id);
2020

2121
// some common cases where turbofish isn't needed:
2222
// - assigned to a local variable with a type annotation

clippy_lints/src/methods/unnecessary_literal_unwrap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub(super) fn check(
7676
(expr.span.with_lo(call_args[0].span.hi()), String::new()),
7777
];
7878
// try to also remove the unsafe block if present
79-
if let hir::Node::Block(block) = cx.tcx.hir().get_parent(expr.hir_id)
79+
if let hir::Node::Block(block) = cx.tcx.parent_hir_node(expr.hir_id)
8080
&& let hir::BlockCheckMode::UnsafeBlock(hir::UnsafeSource::UserProvided) = block.rules
8181
{
8282
suggs.extend([

clippy_lints/src/mixed_read_write_in_expression.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,9 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> {
206206
///
207207
/// When such a read is found, the lint is triggered.
208208
fn check_for_unsequenced_reads(vis: &mut ReadVisitor<'_, '_>) {
209-
let map = &vis.cx.tcx.hir();
210209
let mut cur_id = vis.write_expr.hir_id;
211210
loop {
212-
let parent_id = map.parent_id(cur_id);
211+
let parent_id = vis.cx.tcx.parent_hir_id(cur_id);
213212
if parent_id == cur_id {
214213
break;
215214
}

clippy_lints/src/needless_pass_by_ref_mut.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
161161
};
162162

163163
// Exclude non-inherent impls
164-
if let Some(Node::Item(item)) = cx.tcx.hir().find_parent(hir_id) {
164+
if let Node::Item(item) = cx.tcx.parent_hir_node(hir_id) {
165165
if matches!(
166166
item.kind,
167167
ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..)

clippy_lints/src/needless_pass_by_value.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
100100
}
101101

102102
// Exclude non-inherent impls
103-
if let Some(Node::Item(item)) = cx.tcx.hir().find_parent(hir_id) {
103+
if let Node::Item(item) = cx.tcx.parent_hir_node(hir_id) {
104104
if matches!(
105105
item.kind,
106106
ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..)

clippy_lints/src/non_copy_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
449449
let mut dereferenced_expr = expr;
450450
let mut needs_check_adjustment = true;
451451
loop {
452-
let parent_id = cx.tcx.hir().parent_id(cur_expr.hir_id);
452+
let parent_id = cx.tcx.parent_hir_id(cur_expr.hir_id);
453453
if parent_id == cur_expr.hir_id {
454454
break;
455455
}

clippy_lints/src/operators/modulo_arithmetic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub(super) fn check<'tcx>(
3434
}
3535

3636
fn used_in_comparison_with_zero(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
37-
let Some(Node::Expr(parent_expr)) = cx.tcx.hir().find_parent(expr.hir_id) else {
37+
let Node::Expr(parent_expr) = cx.tcx.parent_hir_node(expr.hir_id) else {
3838
return false;
3939
};
4040
let ExprKind::Binary(op, lhs, rhs) = parent_expr.kind else {

clippy_lints/src/pass_by_ref_or_value.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue {
301301
}
302302

303303
// Exclude non-inherent impls
304-
if let Some(Node::Item(item)) = cx.tcx.hir().find_parent(hir_id) {
304+
if let Node::Item(item) = cx.tcx.parent_hir_node(hir_id) {
305305
if matches!(
306306
item.kind,
307307
ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..)

clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub(super) fn check<'tcx>(
4141
_ => return false,
4242
};
4343

44-
if let Node::Expr(parent) = cx.tcx.hir().get_parent(e.hir_id)
44+
if let Node::Expr(parent) = cx.tcx.parent_hir_node(e.hir_id)
4545
&& parent.precedence().order() > ExprPrecedence::Cast.order()
4646
{
4747
sugg = format!("({sugg})");

clippy_lints/src/tuple_array_conversions.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,10 @@ fn all_bindings_are_for_conv<'tcx>(
153153
let Some(locals) = locals.iter().map(|e| path_to_local(e)).collect::<Option<Vec<_>>>() else {
154154
return false;
155155
};
156-
let Some(local_parents) = locals
156+
let local_parents = locals
157157
.iter()
158-
.map(|&l| cx.tcx.hir().find_parent(l))
159-
.collect::<Option<Vec<_>>>()
160-
else {
161-
return false;
162-
};
158+
.map(|l| cx.tcx.parent_hir_node(*l))
159+
.collect::<Vec<_>>();
163160

164161
local_parents
165162
.iter()

0 commit comments

Comments
 (0)