Fix accuracy of T: Clone
check in suggestion
This commit is contained in:
parent
259348cf7e
commit
5a7caa3174
@ -988,6 +988,7 @@ fn visit_expr(&mut self, ex: &'hir hir::Expr<'hir>) {
|
||||
}
|
||||
|
||||
pub(crate) fn suggest_cloning(&self, err: &mut Diag<'_>, ty: Ty<'tcx>, expr: &hir::Expr<'_>) {
|
||||
let ty = ty.peel_refs();
|
||||
if let Some(clone_trait_def) = self.infcx.tcx.lang_items().clone_trait()
|
||||
&& self
|
||||
.infcx
|
||||
|
@ -10,12 +10,6 @@ LL | drop(x);
|
||||
| ^ move out of `x` occurs here
|
||||
LL | return f(y);
|
||||
| - borrow later used here
|
||||
|
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL - 's: loop { y = denormalise(&x); break }
|
||||
LL + 's: loop { y = denormalise(x.clone()); break }
|
||||
|
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
@ -51,12 +51,6 @@ LL | x
|
||||
...
|
||||
LL | use_mut(n); use_imm(m);
|
||||
| - borrow later used here
|
||||
|
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL - let m = &x;
|
||||
LL + let m = x.clone();
|
||||
|
|
||||
|
||||
error[E0505]: cannot move out of `y` because it is borrowed
|
||||
--> $DIR/binop-move-semantics.rs:23:5
|
||||
|
@ -17,6 +17,11 @@ LL | {src};
|
||||
| --- value moved here
|
||||
LL | src.0 = 66;
|
||||
| ^^^^^^^^^^ value used here after move
|
||||
|
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL | {src.clone()};
|
||||
| ++++++++
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
@ -9,12 +9,6 @@ LL | let S { x: ax } = a;
|
||||
| ^^ move out of `a.x` occurs here
|
||||
LL | f(pb);
|
||||
| -- borrow later used here
|
||||
|
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL - let pb = &a;
|
||||
LL + let pb = a.clone();
|
||||
|
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
@ -11,6 +11,12 @@ LL | println!("{}", f[s]);
|
||||
...
|
||||
LL | use_mut(rs);
|
||||
| -- borrow later used here
|
||||
|
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL - let rs = &mut s;
|
||||
LL + let rs = s.clone();
|
||||
|
|
||||
|
||||
error[E0505]: cannot move out of `s` because it is borrowed
|
||||
--> $DIR/borrowck-overloaded-index-move-index.rs:53:7
|
||||
@ -25,6 +31,12 @@ LL | f[s] = 10;
|
||||
...
|
||||
LL | use_mut(rs);
|
||||
| -- borrow later used here
|
||||
|
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL - let rs = &mut s;
|
||||
LL + let rs = s.clone();
|
||||
|
|
||||
|
||||
error[E0382]: use of moved value: `s`
|
||||
--> $DIR/borrowck-overloaded-index-move-index.rs:53:7
|
||||
|
@ -9,7 +9,7 @@ fn foo<T: Default + Clone>(list: &mut Vec<T>) {
|
||||
drop(cloned_items);
|
||||
}
|
||||
fn bar<T: std::fmt::Display + Clone>(x: T) {
|
||||
let a = x.clone();
|
||||
let a = &x;
|
||||
let b = a.clone();
|
||||
drop(x);
|
||||
//~^ ERROR cannot move out of `x` because it is borrowed
|
||||
@ -19,7 +19,7 @@ fn bar<T: std::fmt::Display + Clone>(x: T) {
|
||||
#[derive(Clone)]
|
||||
struct A;
|
||||
fn qux(x: A) {
|
||||
let a = x.clone();
|
||||
let a = &x;
|
||||
let b = a.clone();
|
||||
drop(x);
|
||||
//~^ ERROR cannot move out of `x` because it is borrowed
|
||||
|
@ -36,11 +36,6 @@ help: consider further restricting this bound
|
||||
|
|
||||
LL | fn bar<T: std::fmt::Display + Clone>(x: T) {
|
||||
| +++++++
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL - let a = &x;
|
||||
LL + let a = x.clone();
|
||||
|
|
||||
|
||||
error[E0505]: cannot move out of `x` because it is borrowed
|
||||
--> $DIR/clone-on-ref.rs:23:10
|
||||
@ -62,11 +57,6 @@ help: consider annotating `A` with `#[derive(Clone)]`
|
||||
LL + #[derive(Clone)]
|
||||
LL | struct A;
|
||||
|
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL - let a = &x;
|
||||
LL + let a = x.clone();
|
||||
|
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
@ -13,12 +13,6 @@ LL | println!("child function: {}", fancy_num.num);
|
||||
...
|
||||
LL | println!("main function: {}", fancy_ref.num);
|
||||
| ------------- borrow later used here
|
||||
|
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL - let fancy_ref = &fancy_num;
|
||||
LL + let fancy_ref = fancy_num.clone();
|
||||
|
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
@ -10,12 +10,6 @@ LL | eat(x);
|
||||
| ^ move out of `x` occurs here
|
||||
LL | _ref_to_val.use_ref();
|
||||
| ----------- borrow later used here
|
||||
|
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL - let _ref_to_val: &Value = &x;
|
||||
LL + let _ref_to_val: &Value = x.clone();
|
||||
|
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
@ -109,6 +109,11 @@ LL | || *x = String::new();
|
||||
| ^^ -- borrow occurs due to use in closure
|
||||
| |
|
||||
| value borrowed here after move
|
||||
|
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL | let r = x.clone();
|
||||
| ++++++++
|
||||
|
||||
error[E0382]: use of moved value: `x`
|
||||
--> $DIR/closure-access-spans.rs:50:5
|
||||
@ -121,6 +126,11 @@ LL | || x;
|
||||
| ^^ - use occurs due to use in closure
|
||||
| |
|
||||
| value used here after move
|
||||
|
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL | let r = x.clone();
|
||||
| ++++++++
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
|
||||
|
@ -41,6 +41,10 @@ help: consider borrowing here
|
||||
|
|
||||
LL | let p = &s.url; p
|
||||
| +
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL | let p = s.url.clone(); p
|
||||
| ++++++++
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
@ -27,6 +27,12 @@ LL | let z = x;
|
||||
| ^ move out of `x` occurs here
|
||||
LL | y
|
||||
| - returning this value requires that `*x` is borrowed for `'1`
|
||||
|
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL - let y = &mut *x;
|
||||
LL + let y = x.clone();
|
||||
|
|
||||
|
||||
error[E0505]: cannot move out of `s` because it is borrowed
|
||||
--> $DIR/polonius-smoke-test.rs:42:5
|
||||
@ -40,6 +46,12 @@ LL | s;
|
||||
| ^ move out of `s` occurs here
|
||||
LL | tmp;
|
||||
| --- borrow later used here
|
||||
|
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL - let r = &mut *s;
|
||||
LL + let r = s.clone();
|
||||
|
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
@ -10,12 +10,6 @@ LL | let [ref _x0_hold, _x1, ref xs_hold @ ..] = arr;
|
||||
LL | _x1 = U;
|
||||
LL | drop(hold_all);
|
||||
| -------- borrow later used here
|
||||
|
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL - let hold_all = &arr;
|
||||
LL + let hold_all = arr.clone();
|
||||
|
|
||||
|
||||
error[E0384]: cannot assign twice to immutable variable `_x1`
|
||||
--> $DIR/borrowck-move-ref-pattern.rs:9:5
|
||||
|
@ -34,6 +34,11 @@ LL | Err(k) ?;
|
||||
...
|
||||
LL | ::std::mem::drop(k);
|
||||
| ^ value used here after move
|
||||
|
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL | Err(k.clone()) ?;
|
||||
| ++++++++
|
||||
|
||||
error[E0506]: cannot assign to `i` because it is borrowed
|
||||
--> $DIR/try-block-bad-lifetime.rs:32:9
|
||||
|
@ -33,12 +33,6 @@ LL | !x;
|
||||
...
|
||||
LL | use_mut(n); use_imm(m);
|
||||
| - borrow later used here
|
||||
|
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL - let m = &x;
|
||||
LL + let m = x.clone();
|
||||
|
|
||||
|
||||
error[E0505]: cannot move out of `y` because it is borrowed
|
||||
--> $DIR/unop-move-semantics.rs:17:6
|
||||
|
@ -9,12 +9,6 @@ LL | drop(a);
|
||||
| ^ move out of `a` occurs here
|
||||
LL | drop(x);
|
||||
| - borrow later used here
|
||||
|
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL - let x = foo(&a);
|
||||
LL + let x = foo(a.clone());
|
||||
|
|
||||
|
||||
error[E0505]: cannot move out of `a` because it is borrowed
|
||||
--> $DIR/variance-issue-20533.rs:34:14
|
||||
@ -27,12 +21,6 @@ LL | drop(a);
|
||||
| ^ move out of `a` occurs here
|
||||
LL | drop(x);
|
||||
| - borrow later used here
|
||||
|
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL - let x = bar(&a);
|
||||
LL + let x = bar(a.clone());
|
||||
|
|
||||
|
||||
error[E0505]: cannot move out of `a` because it is borrowed
|
||||
--> $DIR/variance-issue-20533.rs:40:14
|
||||
@ -45,12 +33,6 @@ LL | drop(a);
|
||||
| ^ move out of `a` occurs here
|
||||
LL | drop(x);
|
||||
| - borrow later used here
|
||||
|
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL - let x = baz(&a);
|
||||
LL + let x = baz(a.clone());
|
||||
|
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user