Don't use method span on clone suggestion
This commit is contained in:
parent
fe870424a7
commit
3a3f4a2144
@ -1135,10 +1135,10 @@ fn explain_captures(
|
||||
&& self.infcx.predicate_must_hold_modulo_regions(&o)
|
||||
{
|
||||
err.span_suggestion_verbose(
|
||||
fn_call_span.shrink_to_lo(),
|
||||
move_span.shrink_to_hi(),
|
||||
"you can `clone` the value and consume it, but this might not be \
|
||||
your desired behavior",
|
||||
"clone().".to_string(),
|
||||
".clone()".to_string(),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ note: `into_future` takes ownership of the receiver `self`, which moves `f`
|
||||
help: you can `clone` the value and consume it, but this might not be your desired behavior
|
||||
|
|
||||
LL | f.clone().await;
|
||||
| ++++++++
|
||||
| ++++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -11,7 +11,7 @@ note: `into_iter` takes ownership of the receiver `self`, which moves value
|
||||
help: you can `clone` the value and consume it, but this might not be your desired behavior
|
||||
|
|
||||
LL | let _x = Rc::new(vec![1, 2]).clone().into_iter();
|
||||
| ++++++++
|
||||
| ++++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
11
tests/ui/borrowck/clone-span-on-try-operator.fixed
Normal file
11
tests/ui/borrowck/clone-span-on-try-operator.fixed
Normal file
@ -0,0 +1,11 @@
|
||||
// run-rustfix
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Foo;
|
||||
impl Foo {
|
||||
fn foo(self) {}
|
||||
}
|
||||
fn main() {
|
||||
let foo = &Foo;
|
||||
(*foo).clone().foo(); //~ ERROR cannot move out
|
||||
}
|
11
tests/ui/borrowck/clone-span-on-try-operator.rs
Normal file
11
tests/ui/borrowck/clone-span-on-try-operator.rs
Normal file
@ -0,0 +1,11 @@
|
||||
// run-rustfix
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Foo;
|
||||
impl Foo {
|
||||
fn foo(self) {}
|
||||
}
|
||||
fn main() {
|
||||
let foo = &Foo;
|
||||
(*foo).foo(); //~ ERROR cannot move out
|
||||
}
|
21
tests/ui/borrowck/clone-span-on-try-operator.stderr
Normal file
21
tests/ui/borrowck/clone-span-on-try-operator.stderr
Normal file
@ -0,0 +1,21 @@
|
||||
error[E0507]: cannot move out of `*foo` which is behind a shared reference
|
||||
--> $DIR/clone-span-on-try-operator.rs:10:5
|
||||
|
|
||||
LL | (*foo).foo();
|
||||
| ^^^^^^ ----- `*foo` moved due to this method call
|
||||
| |
|
||||
| move occurs because `*foo` has type `Foo`, which does not implement the `Copy` trait
|
||||
|
|
||||
note: `Foo::foo` takes ownership of the receiver `self`, which moves `*foo`
|
||||
--> $DIR/clone-span-on-try-operator.rs:6:12
|
||||
|
|
||||
LL | fn foo(self) {}
|
||||
| ^^^^
|
||||
help: you can `clone` the value and consume it, but this might not be your desired behavior
|
||||
|
|
||||
LL | (*foo).clone().foo();
|
||||
| ++++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0507`.
|
@ -15,7 +15,7 @@ note: `into_iter` takes ownership of the receiver `self`, which moves `y`
|
||||
help: you can `clone` the value and consume it, but this might not be your desired behavior
|
||||
|
|
||||
LL | y.clone().into_iter();
|
||||
| ++++++++
|
||||
| ++++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -15,7 +15,7 @@ note: `into_iter` takes ownership of the receiver `self`, which moves `some_vec`
|
||||
help: you can `clone` the value and consume it, but this might not be your desired behavior
|
||||
|
|
||||
LL | some_vec.clone().into_iter();
|
||||
| ++++++++
|
||||
| ++++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -12,7 +12,7 @@ note: `into_iter` takes ownership of the receiver `self`, which moves `val.0`
|
||||
help: you can `clone` the value and consume it, but this might not be your desired behavior
|
||||
|
|
||||
LL | val.0.clone().into_iter().next();
|
||||
| ++++++++
|
||||
| ++++++++
|
||||
|
||||
error[E0382]: use of moved value: `foo`
|
||||
--> $DIR/move-fn-self-receiver.rs:34:5
|
||||
@ -102,7 +102,7 @@ LL | fn use_rc_self(self: 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();
|
||||
| ++++++++
|
||||
| ++++++++
|
||||
|
||||
error[E0382]: use of moved value: `foo_add`
|
||||
--> $DIR/move-fn-self-receiver.rs:59:5
|
||||
@ -145,7 +145,7 @@ LL | explicit_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() {}
|
||||
| ++++++++
|
||||
| ++++++++
|
||||
|
||||
error[E0382]: use of moved value: `container`
|
||||
--> $DIR/move-fn-self-receiver.rs:71:5
|
||||
|
@ -13,7 +13,7 @@ note: `into_iter` takes ownership of the receiver `self`, which moves `x`
|
||||
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());
|
||||
| ++++++++
|
||||
| ++++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -165,7 +165,7 @@ note: `into_iter` takes ownership of the receiver `self`, which moves `x`
|
||||
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();
|
||||
| ++++++++
|
||||
| ++++++++
|
||||
|
||||
error[E0382]: borrow of moved value: `x`
|
||||
--> $DIR/moves-based-on-type-exprs.rs:83:11
|
||||
@ -182,7 +182,7 @@ note: `into_iter` takes ownership of the receiver `self`, which moves `x`
|
||||
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];
|
||||
| ++++++++
|
||||
| ++++++++
|
||||
|
||||
error: aborting due to 11 previous errors
|
||||
|
||||
|
@ -14,7 +14,7 @@ LL | fn foo(self) {}
|
||||
help: you can `clone` the value and consume it, but this might not be your desired behavior
|
||||
|
|
||||
LL | foo.clone().foo();
|
||||
| ++++++++
|
||||
| ++++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -12,7 +12,7 @@ note: `Option::<T>::unwrap` takes ownership of the receiver `self`, which moves
|
||||
help: you can `clone` the value and consume it, but this might not be your desired behavior
|
||||
|
|
||||
LL | if selection.1.clone().unwrap().contains(selection.0) {
|
||||
| ++++++++
|
||||
| ++++++++
|
||||
|
||||
error[E0507]: cannot move out of `selection.1` which is behind a shared reference
|
||||
--> $DIR/option-content-move.rs:27:20
|
||||
@ -28,7 +28,7 @@ note: `Result::<T, E>::unwrap` takes ownership of the receiver `self`, which mov
|
||||
help: you can `clone` the value and consume it, but this might not be your desired behavior
|
||||
|
|
||||
LL | if selection.1.clone().unwrap().contains(selection.0) {
|
||||
| ++++++++
|
||||
| ++++++++
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user