Remove redundant clone suggestion

This commit is contained in:
Esteban Küber 2022-12-25 17:16:54 -08:00
parent 2d6a2ff76e
commit bd890f9cd1
5 changed files with 13 additions and 25 deletions

View file

@ -194,7 +194,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
if !seen_spans.contains(&move_span) {
if !closure {
self.suggest_ref_or_clone(mpi, move_span, &mut err, &mut in_pattern);
self.suggest_ref_or_clone(
mpi,
move_span,
&mut err,
&mut in_pattern,
move_spans,
);
}
self.explain_captures(
@ -312,6 +318,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
move_span: Span,
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
in_pattern: &mut bool,
move_spans: UseSpans<'_>,
) {
struct ExpressionFinder<'hir> {
expr_span: Span,
@ -440,6 +447,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
) = call_expr.kind
{
// Do not suggest `.clone()` in a `for` loop, we already suggest borrowing.
} else if let UseSpans::FnSelfUse {
kind: CallKind::Normal { .. },
..
} = move_spans {
// We already suggest cloning for these cases in `explain_captures`.
} else {
self.suggest_cloning(err, ty, move_span);
}

View file

@ -12,10 +12,6 @@ LL | println!("{:?}", some_vec);
note: `into_iter` takes ownership of the receiver `self`, which moves `some_vec`
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider cloning the value if the performance cost is acceptable
|
LL | some_vec.clone().into_iter();
| ++++++++
help: you can `clone` the value and consume it, but this might not be your desired behavior
|
LL | some_vec.clone().into_iter();

View file

@ -97,10 +97,6 @@ note: `Foo::use_rc_self` takes ownership of the receiver `self`, which moves `rc
|
LL | fn use_rc_self(self: Rc<Self>) {}
| ^^^^
help: consider cloning the value if the performance cost is acceptable
|
LL | rc_foo.clone().use_rc_self();
| ++++++++
help: you can `clone` the value and consume it, but this might not be your desired behavior
|
LL | rc_foo.clone().use_rc_self();
@ -144,10 +140,6 @@ LL | for _val in explicit_into_iter.into_iter() {}
LL | explicit_into_iter;
| ^^^^^^^^^^^^^^^^^^ value used here after move
|
help: consider cloning the value if the performance cost is acceptable
|
LL | for _val in explicit_into_iter.clone().into_iter() {}
| ++++++++
help: you can `clone` the value and consume it, but this might not be your desired behavior
|
LL | for _val in explicit_into_iter.clone().into_iter() {}

View file

@ -10,10 +10,6 @@ LL | touch(&x[0]);
|
note: `into_iter` takes ownership of the receiver `self`, which moves `x`
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
help: consider cloning the value if the performance cost is acceptable
|
LL | consume(x.clone().into_iter().next().unwrap());
| ++++++++
help: you can `clone` the value and consume it, but this might not be your desired behavior
|
LL | consume(x.clone().into_iter().next().unwrap());

View file

@ -162,10 +162,6 @@ LL | touch(&x);
|
note: `into_iter` takes ownership of the receiver `self`, which moves `x`
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
help: consider cloning the value if the performance cost is acceptable
|
LL | let _y = x.clone().into_iter().next().unwrap();
| ++++++++
help: you can `clone` the value and consume it, but this might not be your desired behavior
|
LL | let _y = x.clone().into_iter().next().unwrap();
@ -183,10 +179,6 @@ LL | touch(&x);
|
note: `into_iter` takes ownership of the receiver `self`, which moves `x`
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
help: consider cloning the value if the performance cost is acceptable
|
LL | let _y = [x.clone().into_iter().next().unwrap(); 1];
| ++++++++
help: you can `clone` the value and consume it, but this might not be your desired behavior
|
LL | let _y = [x.clone().into_iter().next().unwrap(); 1];