Skip to content

Commit 503c03c

Browse files
committed
clean up
1 parent 145ebb1 commit 503c03c

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

clippy_lints/src/methods/clone_on_copy.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,11 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, method_name: Symbol,
8686
{
8787
return;
8888
},
89-
ExprKind::Call(hir_callee, _) => match hir_callee.kind {
90-
ExprKind::Path(QPath::LangItem(rustc_hir::LangItem::TryTraitBranch, _, _)) => true,
91-
_ => false,
92-
},
89+
// ? is a Call, makes sure not to rec *x?, but rather (*x)?
90+
ExprKind::Call(hir_callee, _) => matches!(
91+
hir_callee.kind,
92+
ExprKind::Path(QPath::LangItem(rustc_hir::LangItem::TryTraitBranch, _, _))
93+
),
9394
ExprKind::MethodCall(_, [self_arg, ..], _) if expr.hir_id == self_arg.hir_id => true,
9495
ExprKind::Match(_, _, MatchSource::TryDesugar | MatchSource::AwaitDesugar)
9596
| ExprKind::Field(..)

tests/ui/clone_on_copy.fixed

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ fn clone_on_copy() -> Option<(i32)> {
7272
let mut vec = Vec::new();
7373
vec.push(42);
7474

75+
// Issue #9277
7576
let opt: &Option<i32> = &None;
76-
let value = (*opt)?;
77+
let value = (*opt)?; // operator precedence needed (*opt)?
7778
None
7879
}

tests/ui/clone_on_copy.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ fn clone_on_copy() -> Option<(i32)> {
7272
let mut vec = Vec::new();
7373
vec.push(42.clone());
7474

75+
// Issue #9277
7576
let opt: &Option<i32> = &None;
76-
let value = opt.clone()?;
77+
let value = opt.clone()?; // operator precedence needed (*opt)?
7778
None
7879
}

tests/ui/clone_on_copy.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ LL | vec.push(42.clone());
4949
| ^^^^^^^^^^ help: try removing the `clone` call: `42`
5050

5151
error: using `clone` on type `std::option::Option<i32>` which implements the `Copy` trait
52-
--> $DIR/clone_on_copy.rs:76:17
52+
--> $DIR/clone_on_copy.rs:77:17
5353
|
54-
LL | let value = opt.clone()?;
54+
LL | let value = opt.clone()?; // operator precedence needed (*opt)?
5555
| ^^^^^^^^^^^ help: try dereferencing it: `(*opt)`
5656

5757
error: aborting due to 9 previous errors

0 commit comments

Comments
 (0)