about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/dereference.rs11
-rw-r--r--tests/ui/needless_borrow.fixed3
-rw-r--r--tests/ui/needless_borrow.rs3
-rw-r--r--tests/ui/needless_borrow.stderr2
4 files changed, 12 insertions, 7 deletions
diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs
index f63413bd575..3fd4d6383b1 100644
--- a/clippy_lints/src/dereference.rs
+++ b/clippy_lints/src/dereference.rs
@@ -1014,10 +1014,13 @@ fn report<'tcx>(
                         },
                         _ => (0, false),
                     };
-                    let is_in_tuple = match cx.tcx.parent_hir_node(data.first_expr.hir_id) {
-                        Node::Expr(e) => matches!(e.kind, ExprKind::Tup(_)),
-                        _ => false,
-                    };
+                    let is_in_tuple = matches!(
+                        get_parent_expr(cx, data.first_expr),
+                        Some(Expr {
+                            kind: ExprKind::Tup(..),
+                            ..
+                        })
+                    );
 
                     let sugg = if !snip_is_macro
                         && (calls_field || expr.precedence().order() < precedence)
diff --git a/tests/ui/needless_borrow.fixed b/tests/ui/needless_borrow.fixed
index adc92be0e1a..5121077b4ca 100644
--- a/tests/ui/needless_borrow.fixed
+++ b/tests/ui/needless_borrow.fixed
@@ -255,6 +255,7 @@ mod issue_10253 {
 fn issue_12268() {
     let option = Some((&1,));
     let x = (&1,);
-    // Lint here.
     option.unwrap_or((x.0,));
+    //~^ ERROR: this expression creates a reference which is immediately dereferenced by the
+    // compiler
 }
diff --git a/tests/ui/needless_borrow.rs b/tests/ui/needless_borrow.rs
index b1f51a29978..e3a5cb280ba 100644
--- a/tests/ui/needless_borrow.rs
+++ b/tests/ui/needless_borrow.rs
@@ -255,6 +255,7 @@ mod issue_10253 {
 fn issue_12268() {
     let option = Some((&1,));
     let x = (&1,);
-    // Lint here.
     option.unwrap_or((&x.0,));
+    //~^ ERROR: this expression creates a reference which is immediately dereferenced by the
+    // compiler
 }
diff --git a/tests/ui/needless_borrow.stderr b/tests/ui/needless_borrow.stderr
index 56fcf1268a1..4b2b17e7e57 100644
--- a/tests/ui/needless_borrow.stderr
+++ b/tests/ui/needless_borrow.stderr
@@ -164,7 +164,7 @@ LL |         let _ = &mut (&mut { x.u }).x;
    |                      ^^^^^^^^^^^^^^ help: change this to: `{ x.u }`
 
 error: this expression creates a reference which is immediately dereferenced by the compiler
-  --> tests/ui/needless_borrow.rs:259:23
+  --> tests/ui/needless_borrow.rs:258:23
    |
 LL |     option.unwrap_or((&x.0,));
    |                       ^^^^ help: change this to: `x.0`