File tree 1 file changed +9
-3
lines changed
1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -104,7 +104,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
104
104
if e. span . from_expansion ( ) {
105
105
return ;
106
106
}
107
- if let ExprKind :: AddrOf ( BorrowKind :: Ref , Mutability :: Not , inner) = e. kind {
107
+ if let ExprKind :: AddrOf ( BorrowKind :: Ref , mutability , inner) = e. kind {
108
108
if let ty:: Ref ( _, ty, _) = cx. typeck_results ( ) . expr_ty ( inner) . kind ( ) {
109
109
for adj3 in cx. typeck_results ( ) . expr_adjustments ( e) . windows ( 3 ) {
110
110
if let [ Adjustment {
@@ -116,14 +116,20 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
116
116
..
117
117
} ] = * adj3
118
118
{
119
+ let help_msg_ty = if matches ! ( mutability, Mutability :: Not ) {
120
+ format ! ( "&{}" , ty)
121
+ } else {
122
+ format ! ( "&mut {}" , ty)
123
+ } ;
124
+
119
125
span_lint_and_then (
120
126
cx,
121
127
NEEDLESS_BORROW ,
122
128
e. span ,
123
129
& format ! (
124
- "this expression borrows a reference (`& {}`) that is immediately dereferenced \
130
+ "this expression borrows a reference (`{}`) that is immediately dereferenced \
125
131
by the compiler",
126
- ty
132
+ help_msg_ty
127
133
) ,
128
134
|diag| {
129
135
if let Some ( snippet) = snippet_opt ( cx, inner. span ) {
You can’t perform that action at this time.
0 commit comments