File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change
1
+ use crate :: reference:: DEREF_ADDROF ;
1
2
use clippy_utils:: diagnostics:: { span_lint_and_help, span_lint_and_then} ;
3
+ use clippy_utils:: is_lint_allowed;
2
4
use clippy_utils:: source:: snippet_opt;
3
5
use clippy_utils:: ty:: implements_trait;
4
6
use rustc_hir:: { ExprKind , UnOp } ;
@@ -55,11 +57,14 @@ impl LateLintPass<'_> for NeedlessDeref {
55
57
if span. from_expansion( ) {
56
58
return ;
57
59
}
58
- if matches!( deref_expr. kind, ExprKind :: Path ( ..) ) {
60
+ if matches!( deref_expr. kind, ExprKind :: Path ( ..) ) {
59
61
let parent_node = map. find( parent_hir_id) ;
60
62
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) {
63
68
return ;
64
69
}
65
70
}
You can’t perform that action at this time.
0 commit comments