Skip to content

Commit f3f9075

Browse files
committed
get_parent_expr
1 parent 56ed747 commit f3f9075

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

clippy_lints/src/borrow_deref_ref.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::reference::DEREF_ADDROF;
22
use clippy_utils::diagnostics::span_lint_and_then;
3-
use clippy_utils::is_lint_allowed;
43
use clippy_utils::source::snippet_opt;
54
use clippy_utils::ty::implements_trait;
5+
use clippy_utils::{get_parent_expr, is_lint_allowed};
66
use rustc_hir::{ExprKind, UnOp};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_middle::mir::Mutability;
@@ -62,21 +62,19 @@ impl LateLintPass<'_> for BorrowDerefRef {
6262
if let ty::Ref(_, inner_ty, Mutability::Not) = ref_ty.kind();
6363
then{
6464

65-
let map = cx.tcx.hir();
66-
if let Some(parent_hir_id) = map.find_parent_node(e.hir_id){
67-
let span = map.span(parent_hir_id);
65+
if let Some(parent_expr) = get_parent_expr(cx, e){
66+
let map = cx.tcx.hir();
67+
let span = map.span(parent_expr.hir_id);
6868
if span.from_expansion() {
6969
return;
7070
}
7171
if matches!(deref_target.kind, ExprKind::Path(..) | ExprKind::Field(..)) {
72-
if let Some(rustc_hir::Node::Expr(parent_expr)) = map.find(parent_hir_id) {
73-
if matches!(parent_expr.kind, ExprKind::AddrOf(_, Mutability::Mut, _)) {
74-
return;
75-
}
76-
if matches!(parent_expr.kind, ExprKind::Unary(UnOp::Deref, ..)) &&
77-
!is_lint_allowed(cx, DEREF_ADDROF, parent_expr.hir_id) {
78-
return;
79-
}
72+
if matches!(parent_expr.kind, ExprKind::AddrOf(_, Mutability::Mut, _)) {
73+
return;
74+
}
75+
if matches!(parent_expr.kind, ExprKind::Unary(UnOp::Deref, ..)) &&
76+
!is_lint_allowed(cx, DEREF_ADDROF, parent_expr.hir_id) {
77+
return;
8078
}
8179
}
8280
}

0 commit comments

Comments
 (0)