File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 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 {
104104 if e. span . from_expansion ( ) {
105105 return ;
106106 }
107- if let ExprKind :: AddrOf ( BorrowKind :: Ref , Mutability :: Not , inner) = e. kind {
107+ if let ExprKind :: AddrOf ( BorrowKind :: Ref , mutability , inner) = e. kind {
108108 if let ty:: Ref ( _, ty, _) = cx. typeck_results ( ) . expr_ty ( inner) . kind ( ) {
109109 for adj3 in cx. typeck_results ( ) . expr_adjustments ( e) . windows ( 3 ) {
110110 if let [ Adjustment {
@@ -116,14 +116,20 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
116116 ..
117117 } ] = * adj3
118118 {
119+ let help_msg_ty = if matches ! ( mutability, Mutability :: Not ) {
120+ format ! ( "&{}" , ty)
121+ } else {
122+ format ! ( "&mut {}" , ty)
123+ } ;
124+
119125 span_lint_and_then (
120126 cx,
121127 NEEDLESS_BORROW ,
122128 e. span ,
123129 & format ! (
124- "this expression borrows a reference (`& {}`) that is immediately dereferenced \
130+ "this expression borrows a reference (`{}`) that is immediately dereferenced \
125131 by the compiler",
126- ty
132+ help_msg_ty
127133 ) ,
128134 |diag| {
129135 if let Some ( snippet) = snippet_opt ( cx, inner. span ) {
You can’t perform that action at this time.
0 commit comments