Skip to content

Commit

Permalink
Remove redundant clone suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Dec 26, 2022
1 parent 2d6a2ff commit bd890f9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 25 deletions.
14 changes: 13 additions & 1 deletion compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 0 additions & 4 deletions src/test/ui/codemap_tests/tab_3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 0 additions & 8 deletions src/test/ui/moves/move-fn-self-receiver.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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() {}
Expand Down
4 changes: 0 additions & 4 deletions src/test/ui/moves/moves-based-on-type-access-to-field.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
8 changes: 0 additions & 8 deletions src/test/ui/moves/moves-based-on-type-exprs.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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];
Expand Down

0 comments on commit bd890f9

Please sign in to comment.