Skip to content

Commit 5a9959f

Browse files
Suppress useless clone suggestion
1 parent d565605 commit 5a9959f

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1442,9 +1442,14 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
14421442
// See `tests/ui/moves/needs-clone-through-deref.rs`
14431443
return false;
14441444
}
1445+
// We don't want to suggest `.clone()` in a move closure, since the value has already been captured.
14451446
if self.in_move_closure(expr) {
14461447
return false;
14471448
}
1449+
// We also don't want to suggest cloning a closure itself, since the value has already been captured.
1450+
if let hir::ExprKind::Closure(_) = expr.kind {
1451+
return false;
1452+
}
14481453
// Try to find predicates on *generic params* that would allow copying `ty`
14491454
let mut suggestion =
14501455
if let Some(symbol) = tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) {

tests/ui/async-await/async-closures/without-precise-captures-we-are-powerless.stderr

-5
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ LL | outlives::<'a>(call_once(c));
5656
LL |
5757
LL | let c = async move || { println!("{}", *x.0); };
5858
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ move out of `x` occurs here
59-
|
60-
help: consider cloning the value if the performance cost is acceptable
61-
|
62-
LL | let c = async || { println!("{}", *x.0); }.clone();
63-
| ++++++++
6459

6560
error[E0597]: `c` does not live long enough
6661
--> $DIR/without-precise-captures-we-are-powerless.rs:33:20

0 commit comments

Comments
 (0)