@@ -19,6 +19,16 @@ declare_clippy_lint! {
1919 /// if you want to deref explicitly, `&** (&T)` is what you need.
2020 /// If you want to reborrow, `&T` is enough (`&T` is Copy).
2121 ///
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+ ///
2232 /// ### Example
2333 /// ```rust
2434 /// let s = &String::new();
@@ -60,7 +70,7 @@ impl LateLintPass<'_> for NeedlessDeref {
6070 if matches!( deref_expr. kind, ExprKind :: Path ( ..) ) {
6171 let parent_node = map. find( parent_hir_id) ;
6272 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 , _ ) ) {
6474 return ;
6575 }
6676 if matches!( parent_expr. kind, ExprKind :: Unary ( UnOp :: Deref , ..) ) &&
@@ -73,8 +83,8 @@ impl LateLintPass<'_> for NeedlessDeref {
7383
7484 let mut give_2_help = true ;
7585
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
7888 if let Some ( deref_trait_id) = cx. tcx. lang_items( ) . deref_trait( ) {
7989 if !implements_trait( cx, inner_ty, deref_trait_id, & [ ] ) {
8090 give_2_help = false ;
0 commit comments