Skip to content

Commit bd890f9

Browse files
committed
Remove redundant clone suggestion
1 parent 2d6a2ff commit bd890f9

File tree

5 files changed

+13
-25
lines changed

5 files changed

+13
-25
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
194194

195195
if !seen_spans.contains(&move_span) {
196196
if !closure {
197-
self.suggest_ref_or_clone(mpi, move_span, &mut err, &mut in_pattern);
197+
self.suggest_ref_or_clone(
198+
mpi,
199+
move_span,
200+
&mut err,
201+
&mut in_pattern,
202+
move_spans,
203+
);
198204
}
199205

200206
self.explain_captures(
@@ -312,6 +318,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
312318
move_span: Span,
313319
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
314320
in_pattern: &mut bool,
321+
move_spans: UseSpans<'_>,
315322
) {
316323
struct ExpressionFinder<'hir> {
317324
expr_span: Span,
@@ -440,6 +447,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
440447
) = call_expr.kind
441448
{
442449
// Do not suggest `.clone()` in a `for` loop, we already suggest borrowing.
450+
} else if let UseSpans::FnSelfUse {
451+
kind: CallKind::Normal { .. },
452+
..
453+
} = move_spans {
454+
// We already suggest cloning for these cases in `explain_captures`.
443455
} else {
444456
self.suggest_cloning(err, ty, move_span);
445457
}

src/test/ui/codemap_tests/tab_3.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ LL | println!("{:?}", some_vec);
1212
note: `into_iter` takes ownership of the receiver `self`, which moves `some_vec`
1313
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
1414
= 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)
15-
help: consider cloning the value if the performance cost is acceptable
16-
|
17-
LL | some_vec.clone().into_iter();
18-
| ++++++++
1915
help: you can `clone` the value and consume it, but this might not be your desired behavior
2016
|
2117
LL | some_vec.clone().into_iter();

src/test/ui/moves/move-fn-self-receiver.stderr

-8
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,6 @@ note: `Foo::use_rc_self` takes ownership of the receiver `self`, which moves `rc
9797
|
9898
LL | fn use_rc_self(self: Rc<Self>) {}
9999
| ^^^^
100-
help: consider cloning the value if the performance cost is acceptable
101-
|
102-
LL | rc_foo.clone().use_rc_self();
103-
| ++++++++
104100
help: you can `clone` the value and consume it, but this might not be your desired behavior
105101
|
106102
LL | rc_foo.clone().use_rc_self();
@@ -144,10 +140,6 @@ LL | for _val in explicit_into_iter.into_iter() {}
144140
LL | explicit_into_iter;
145141
| ^^^^^^^^^^^^^^^^^^ value used here after move
146142
|
147-
help: consider cloning the value if the performance cost is acceptable
148-
|
149-
LL | for _val in explicit_into_iter.clone().into_iter() {}
150-
| ++++++++
151143
help: you can `clone` the value and consume it, but this might not be your desired behavior
152144
|
153145
LL | for _val in explicit_into_iter.clone().into_iter() {}

src/test/ui/moves/moves-based-on-type-access-to-field.stderr

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

src/test/ui/moves/moves-based-on-type-exprs.stderr

-8
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@ LL | touch(&x);
162162
|
163163
note: `into_iter` takes ownership of the receiver `self`, which moves `x`
164164
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
165-
help: consider cloning the value if the performance cost is acceptable
166-
|
167-
LL | let _y = x.clone().into_iter().next().unwrap();
168-
| ++++++++
169165
help: you can `clone` the value and consume it, but this might not be your desired behavior
170166
|
171167
LL | let _y = x.clone().into_iter().next().unwrap();
@@ -183,10 +179,6 @@ LL | touch(&x);
183179
|
184180
note: `into_iter` takes ownership of the receiver `self`, which moves `x`
185181
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
186-
help: consider cloning the value if the performance cost is acceptable
187-
|
188-
LL | let _y = [x.clone().into_iter().next().unwrap(); 1];
189-
| ++++++++
190182
help: you can `clone` the value and consume it, but this might not be your desired behavior
191183
|
192184
LL | let _y = [x.clone().into_iter().next().unwrap(); 1];

0 commit comments

Comments
 (0)