mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-30 05:51:58 +00:00
Suppress useless clone suggestion
This commit is contained in:
parent
d5656059a1
commit
5a9959fd9d
@ -1442,9 +1442,14 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
// See `tests/ui/moves/needs-clone-through-deref.rs`
|
||||
return false;
|
||||
}
|
||||
// We don't want to suggest `.clone()` in a move closure, since the value has already been captured.
|
||||
if self.in_move_closure(expr) {
|
||||
return false;
|
||||
}
|
||||
// We also don't want to suggest cloning a closure itself, since the value has already been captured.
|
||||
if let hir::ExprKind::Closure(_) = expr.kind {
|
||||
return false;
|
||||
}
|
||||
// Try to find predicates on *generic params* that would allow copying `ty`
|
||||
let mut suggestion =
|
||||
if let Some(symbol) = tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) {
|
||||
|
@ -56,11 +56,6 @@ LL | outlives::<'a>(call_once(c));
|
||||
LL |
|
||||
LL | let c = async move || { println!("{}", *x.0); };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ move out of `x` occurs here
|
||||
|
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL | let c = async || { println!("{}", *x.0); }.clone();
|
||||
| ++++++++
|
||||
|
||||
error[E0597]: `c` does not live long enough
|
||||
--> $DIR/without-precise-captures-we-are-powerless.rs:33:20
|
||||
|
Loading…
Reference in New Issue
Block a user