Skip to content

Commit 0eaff09

Browse files
committed
lint if deref_addrof is allowed
1 parent c68d9e7 commit 0eaff09

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

clippy_lints/src/needless_deref.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
use crate::reference::DEREF_ADDROF;
12
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then};
3+
use clippy_utils::is_lint_allowed;
24
use clippy_utils::source::snippet_opt;
35
use clippy_utils::ty::implements_trait;
46
use rustc_hir::{ExprKind, UnOp};
@@ -55,11 +57,14 @@ impl LateLintPass<'_> for NeedlessDeref {
5557
if span.from_expansion() {
5658
return;
5759
}
58-
if matches!(deref_expr.kind, ExprKind::Path(..) ){
60+
if matches!(deref_expr.kind, ExprKind::Path(..)) {
5961
let parent_node = map.find(parent_hir_id);
6062
if let Some(rustc_hir::Node::Expr(parent_expr)) = parent_node {
61-
if matches!(parent_expr.kind, ExprKind::Unary(UnOp::Deref, ..)) ||
62-
matches!(parent_expr.kind, ExprKind::AddrOf(..) ) {
63+
if matches!(parent_expr.kind, ExprKind::AddrOf(..)) {
64+
return;
65+
}
66+
if matches!(parent_expr.kind, ExprKind::Unary(UnOp::Deref, ..)) &&
67+
!is_lint_allowed(cx, DEREF_ADDROF, parent_expr.hir_id) {
6368
return;
6469
}
6570
}

0 commit comments

Comments
 (0)