@@ -54,25 +54,25 @@ impl<'tcx> LateLintPass<'tcx> for BorrowDerefRef {
54
54
&& !addrof_target. span . from_expansion ( )
55
55
&& let ExprKind :: Unary ( UnOp :: Deref , deref_target) = addrof_target. kind
56
56
&& !deref_target. span . from_expansion ( )
57
- && !matches ! ( deref_target. kind, ExprKind :: Unary ( UnOp :: Deref , ..) )
57
+ && !matches ! ( deref_target. kind, ExprKind :: Unary ( UnOp :: Deref , ..) )
58
58
&& let ref_ty = cx. typeck_results ( ) . expr_ty ( deref_target)
59
59
&& let ty:: Ref ( _, inner_ty, Mutability :: Not ) = ref_ty. kind ( )
60
60
&& !is_from_proc_macro ( cx, e)
61
61
{
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
+ {
66
66
return ;
67
67
}
68
68
69
69
// 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 ;
76
76
}
77
77
}
78
78
@@ -86,12 +86,12 @@ impl<'tcx> LateLintPass<'tcx> for BorrowDerefRef {
86
86
e. span ,
87
87
"if you would like to reborrow, try removing `&*`" ,
88
88
snippet_opt ( cx, deref_target. span ) . unwrap ( ) ,
89
- Applicability :: MachineApplicable
89
+ Applicability :: MachineApplicable ,
90
90
) ;
91
91
92
92
// has deref trait -> give 2 help
93
93
// 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 ( ) {
95
95
if !implements_trait ( cx, * inner_ty, deref_trait_id, & [ ] ) {
96
96
return ;
97
97
}
@@ -100,16 +100,11 @@ impl<'tcx> LateLintPass<'tcx> for BorrowDerefRef {
100
100
diag. span_suggestion (
101
101
e. span ,
102
102
"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 ,
108
105
) ;
109
-
110
- }
106
+ } ,
111
107
) ;
112
-
113
108
}
114
109
}
115
110
}
0 commit comments