@@ -54,25 +54,25 @@ impl<'tcx> LateLintPass<'tcx> for BorrowDerefRef {
5454 && !addrof_target. span . from_expansion ( )
5555 && let ExprKind :: Unary ( UnOp :: Deref , deref_target) = addrof_target. kind
5656 && !deref_target. span . from_expansion ( )
57- && !matches ! ( deref_target. kind, ExprKind :: Unary ( UnOp :: Deref , ..) )
57+ && !matches ! ( deref_target. kind, ExprKind :: Unary ( UnOp :: Deref , ..) )
5858 && let ref_ty = cx. typeck_results ( ) . expr_ty ( deref_target)
5959 && let ty:: Ref ( _, inner_ty, Mutability :: Not ) = ref_ty. kind ( )
6060 && !is_from_proc_macro ( cx, e)
6161 {
62-
63- if let Some ( parent_expr) = get_parent_expr ( cx , e ) {
64- if matches ! ( parent_expr . kind , ExprKind :: Unary ( UnOp :: Deref , .. ) ) &&
65- ! is_lint_allowed ( cx , DEREF_ADDROF , parent_expr . hir_id ) {
62+ if let Some ( parent_expr ) = get_parent_expr ( cx , e ) {
63+ if matches ! ( parent_expr. kind , ExprKind :: Unary ( UnOp :: Deref , .. ) )
64+ && ! is_lint_allowed ( cx , DEREF_ADDROF , parent_expr . hir_id )
65+ {
6666 return ;
6767 }
6868
6969 // modification to `&mut &*x` is different from `&mut x`
70- if matches ! ( deref_target . kind , ExprKind :: Path ( .. )
71- | ExprKind :: Field ( .. )
72- | ExprKind :: Index ( ..)
73- | ExprKind :: Unary ( UnOp :: Deref , .. ) )
74- && matches ! ( parent_expr . kind , ExprKind :: AddrOf ( _ , Mutability :: Mut , _ ) ) {
75- return ;
70+ if matches ! (
71+ deref_target . kind ,
72+ ExprKind :: Path ( .. ) | ExprKind :: Field ( .. ) | ExprKind :: Index ( .. ) | ExprKind :: Unary ( UnOp :: Deref , ..)
73+ ) && matches ! ( parent_expr . kind , ExprKind :: AddrOf ( _ , Mutability :: Mut , _ ) )
74+ {
75+ return ;
7676 }
7777 }
7878
@@ -86,12 +86,12 @@ impl<'tcx> LateLintPass<'tcx> for BorrowDerefRef {
8686 e. span ,
8787 "if you would like to reborrow, try removing `&*`" ,
8888 snippet_opt ( cx, deref_target. span ) . unwrap ( ) ,
89- Applicability :: MachineApplicable
89+ Applicability :: MachineApplicable ,
9090 ) ;
9191
9292 // has deref trait -> give 2 help
9393 // doesn't have deref trait -> give 1 help
94- if let Some ( deref_trait_id) = cx. tcx . lang_items ( ) . deref_trait ( ) {
94+ if let Some ( deref_trait_id) = cx. tcx . lang_items ( ) . deref_trait ( ) {
9595 if !implements_trait ( cx, * inner_ty, deref_trait_id, & [ ] ) {
9696 return ;
9797 }
@@ -100,16 +100,11 @@ impl<'tcx> LateLintPass<'tcx> for BorrowDerefRef {
100100 diag. span_suggestion (
101101 e. span ,
102102 "if you would like to deref, try using `&**`" ,
103- format ! (
104- "&**{}" ,
105- & snippet_opt( cx, deref_target. span) . unwrap( ) ,
106- ) ,
107- Applicability :: MaybeIncorrect
103+ format ! ( "&**{}" , & snippet_opt( cx, deref_target. span) . unwrap( ) ) ,
104+ Applicability :: MaybeIncorrect ,
108105 ) ;
109-
110- }
106+ } ,
111107 ) ;
112-
113108 }
114109 }
115110}
0 commit comments