about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/methods/clone_on_copy.rs9
-rw-r--r--tests/ui/clone_on_copy.fixed3
-rw-r--r--tests/ui/clone_on_copy.rs3
-rw-r--r--tests/ui/clone_on_copy.stderr4
4 files changed, 11 insertions, 8 deletions
diff --git a/clippy_lints/src/methods/clone_on_copy.rs b/clippy_lints/src/methods/clone_on_copy.rs
index a813d39441b..60e1355f9b9 100644
--- a/clippy_lints/src/methods/clone_on_copy.rs
+++ b/clippy_lints/src/methods/clone_on_copy.rs
@@ -86,10 +86,11 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, method_name: Symbol,
                 {
                     return;
                 },
-                ExprKind::Call(hir_callee, _) => match hir_callee.kind {
-                    ExprKind::Path(QPath::LangItem(rustc_hir::LangItem::TryTraitBranch, _, _)) => true,
-                    _ => false,
-                },
+                // ? is a Call, makes sure not to rec *x?, but rather (*x)?
+                ExprKind::Call(hir_callee, _) => matches!(
+                    hir_callee.kind,
+                    ExprKind::Path(QPath::LangItem(rustc_hir::LangItem::TryTraitBranch, _, _))
+                ),
                 ExprKind::MethodCall(_, [self_arg, ..], _) if expr.hir_id == self_arg.hir_id => true,
                 ExprKind::Match(_, _, MatchSource::TryDesugar | MatchSource::AwaitDesugar)
                 | ExprKind::Field(..)
diff --git a/tests/ui/clone_on_copy.fixed b/tests/ui/clone_on_copy.fixed
index 43849121b04..72b12227098 100644
--- a/tests/ui/clone_on_copy.fixed
+++ b/tests/ui/clone_on_copy.fixed
@@ -72,7 +72,8 @@ fn clone_on_copy() -> Option<(i32)> {
     let mut vec = Vec::new();
     vec.push(42);
 
+    //  Issue #9277
     let opt: &Option<i32> = &None;
-    let value = (*opt)?;
+    let value = (*opt)?; // operator precedence needed (*opt)?
     None
 }
diff --git a/tests/ui/clone_on_copy.rs b/tests/ui/clone_on_copy.rs
index 1f10599da22..03e210ebad9 100644
--- a/tests/ui/clone_on_copy.rs
+++ b/tests/ui/clone_on_copy.rs
@@ -72,7 +72,8 @@ fn clone_on_copy() -> Option<(i32)> {
     let mut vec = Vec::new();
     vec.push(42.clone());
 
+    //  Issue #9277
     let opt: &Option<i32> = &None;
-    let value = opt.clone()?;
+    let value = opt.clone()?; // operator precedence needed (*opt)?
     None
 }
diff --git a/tests/ui/clone_on_copy.stderr b/tests/ui/clone_on_copy.stderr
index 483ea35af2a..42ae227777c 100644
--- a/tests/ui/clone_on_copy.stderr
+++ b/tests/ui/clone_on_copy.stderr
@@ -49,9 +49,9 @@ LL |     vec.push(42.clone());
    |              ^^^^^^^^^^ help: try removing the `clone` call: `42`
 
 error: using `clone` on type `std::option::Option<i32>` which implements the `Copy` trait
-  --> $DIR/clone_on_copy.rs:76:17
+  --> $DIR/clone_on_copy.rs:77:17
    |
-LL |     let value = opt.clone()?;
+LL |     let value = opt.clone()?; // operator precedence needed (*opt)?
    |                 ^^^^^^^^^^^ help: try dereferencing it: `(*opt)`
 
 error: aborting due to 9 previous errors