about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2020-12-13 15:17:47 +0100
committerMatthias Krüger <matthias.krueger@famsik.de>2020-12-13 15:29:18 +0100
commitcd2a62cb0cf89f5b4105c1c40651cf0eeaa85b14 (patch)
tree5594a7e0aa6174fd471820415d03acda815a876d
parentb7db5bfc50095c259d2f128ddb96f7faf8654e3c (diff)
downloadrust-cd2a62cb0cf89f5b4105c1c40651cf0eeaa85b14.tar.gz
rust-cd2a62cb0cf89f5b4105c1c40651cf0eeaa85b14.zip
needless_borrow: print the type in the lint message
changelog: needless_borrow: print type in lint message
-rw-r--r--clippy_lints/src/needless_borrow.rs7
-rw-r--r--tests/ui/eta.stderr2
-rw-r--r--tests/ui/needless_borrow.stderr4
3 files changed, 8 insertions, 5 deletions
diff --git a/clippy_lints/src/needless_borrow.rs b/clippy_lints/src/needless_borrow.rs
index 405c21d608d..bff53eb8cca 100644
--- a/clippy_lints/src/needless_borrow.rs
+++ b/clippy_lints/src/needless_borrow.rs
@@ -47,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
             return;
         }
         if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = e.kind {
-            if let ty::Ref(..) = cx.typeck_results().expr_ty(inner).kind() {
+            if let ty::Ref(_, ty, _) = cx.typeck_results().expr_ty(inner).kind() {
                 for adj3 in cx.typeck_results().expr_adjustments(e).windows(3) {
                     if let [Adjustment {
                         kind: Adjust::Deref(_), ..
@@ -62,8 +62,11 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
                             cx,
                             NEEDLESS_BORROW,
                             e.span,
-                            "this expression borrows a reference that is immediately dereferenced \
+                            &format!(
+                                "this expression borrows a reference (`&{}`) that is immediately dereferenced \
                              by the compiler",
+                                ty
+                            ),
                             |diag| {
                                 if let Some(snippet) = snippet_opt(cx, inner.span) {
                                     diag.span_suggestion(
diff --git a/tests/ui/eta.stderr b/tests/ui/eta.stderr
index c4713ca8083..16aa1b07733 100644
--- a/tests/ui/eta.stderr
+++ b/tests/ui/eta.stderr
@@ -12,7 +12,7 @@ error: redundant closure found
 LL |     meta(|a| foo(a));
    |          ^^^^^^^^^^ help: remove closure as shown: `foo`
 
-error: this expression borrows a reference that is immediately dereferenced by the compiler
+error: this expression borrows a reference (`&u8`) that is immediately dereferenced by the compiler
   --> $DIR/eta.rs:24:21
    |
 LL |     all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted
diff --git a/tests/ui/needless_borrow.stderr b/tests/ui/needless_borrow.stderr
index 0bfeda7914d..bea4b41b803 100644
--- a/tests/ui/needless_borrow.stderr
+++ b/tests/ui/needless_borrow.stderr
@@ -1,4 +1,4 @@
-error: this expression borrows a reference that is immediately dereferenced by the compiler
+error: this expression borrows a reference (`&i32`) that is immediately dereferenced by the compiler
   --> $DIR/needless_borrow.rs:14:15
    |
 LL |     let c = x(&&a);
@@ -12,7 +12,7 @@ error: this pattern creates a reference to a reference
 LL |     if let Some(ref cake) = Some(&5) {}
    |                 ^^^^^^^^ help: change this to: `cake`
 
-error: this expression borrows a reference that is immediately dereferenced by the compiler
+error: this expression borrows a reference (`&i32`) that is immediately dereferenced by the compiler
   --> $DIR/needless_borrow.rs:28:15
    |
 LL |         46 => &&a,