@@ -19,6 +19,16 @@ declare_clippy_lint! {
19
19
/// if you want to deref explicitly, `&** (&T)` is what you need.
20
20
/// If you want to reborrow, `&T` is enough (`&T` is Copy).
21
21
///
22
+ /// ### Known problems
23
+ /// false negative on such code:
24
+ /// ```
25
+ /// let x = &12;
26
+ /// let addr_x = &x as *const _ as usize;
27
+ /// let addr_y = &&*x as *const _ as usize; // assert ok now, and lint triggerd.
28
+ /// // But if we apply it, it will assert fail.
29
+ /// assert_ne!(addr_x, addr_y);
30
+ /// ```
31
+ ///
22
32
/// ### Example
23
33
/// ```rust
24
34
/// let s = &String::new();
@@ -60,7 +70,7 @@ impl LateLintPass<'_> for NeedlessDeref {
60
70
if matches!( deref_expr. kind, ExprKind :: Path ( ..) ) {
61
71
let parent_node = map. find( parent_hir_id) ;
62
72
if let Some ( rustc_hir:: Node :: Expr ( parent_expr) ) = parent_node {
63
- if matches!( parent_expr. kind, ExprKind :: AddrOf ( .. ) ) {
73
+ if matches!( parent_expr. kind, ExprKind :: AddrOf ( _ , Mutability :: Mut , _ ) ) {
64
74
return ;
65
75
}
66
76
if matches!( parent_expr. kind, ExprKind :: Unary ( UnOp :: Deref , ..) ) &&
@@ -73,8 +83,8 @@ impl LateLintPass<'_> for NeedlessDeref {
73
83
74
84
let mut give_2_help = true ;
75
85
76
- // if has deref trait, give 2 help
77
- // if has no deref trait, give 1 help
86
+ // has deref trait -> give 2 help
87
+ // doesn't have deref trait -> give 1 help
78
88
if let Some ( deref_trait_id) = cx. tcx. lang_items( ) . deref_trait( ) {
79
89
if !implements_trait( cx, inner_ty, deref_trait_id, & [ ] ) {
80
90
give_2_help = false ;
0 commit comments