Don't use method span on clone suggestion

This commit is contained in:
Michael Goulet 2023-06-22 20:40:49 +00:00
parent fe870424a7
commit 3a3f4a2144
13 changed files with 58 additions and 15 deletions

View File

@ -1135,10 +1135,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&& self.infcx.predicate_must_hold_modulo_regions(&o) && self.infcx.predicate_must_hold_modulo_regions(&o)
{ {
err.span_suggestion_verbose( 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 \ "you can `clone` the value and consume it, but this might not be \
your desired behavior", your desired behavior",
"clone().".to_string(), ".clone()".to_string(),
Applicability::MaybeIncorrect, Applicability::MaybeIncorrect,
); );
} }

View File

@ -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 help: you can `clone` the value and consume it, but this might not be your desired behavior
| |
LL | f.clone().await; LL | f.clone().await;
| ++++++++ | ++++++++
error: aborting due to previous error error: aborting due to previous error

View File

@ -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 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(); LL | let _x = Rc::new(vec![1, 2]).clone().into_iter();
| ++++++++ | ++++++++
error: aborting due to previous error error: aborting due to previous error

View 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
}

View 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
}

View 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`.

View File

@ -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 help: you can `clone` the value and consume it, but this might not be your desired behavior
| |
LL | y.clone().into_iter(); LL | y.clone().into_iter();
| ++++++++ | ++++++++
error: aborting due to previous error error: aborting due to previous error

View File

@ -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 help: you can `clone` the value and consume it, but this might not be your desired behavior
| |
LL | some_vec.clone().into_iter(); LL | some_vec.clone().into_iter();
| ++++++++ | ++++++++
error: aborting due to previous error error: aborting due to previous error

View File

@ -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 help: you can `clone` the value and consume it, but this might not be your desired behavior
| |
LL | val.0.clone().into_iter().next(); LL | val.0.clone().into_iter().next();
| ++++++++ | ++++++++
error[E0382]: use of moved value: `foo` error[E0382]: use of moved value: `foo`
--> $DIR/move-fn-self-receiver.rs:34:5 --> $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 help: you can `clone` the value and consume it, but this might not be your desired behavior
| |
LL | rc_foo.clone().use_rc_self(); LL | rc_foo.clone().use_rc_self();
| ++++++++ | ++++++++
error[E0382]: use of moved value: `foo_add` error[E0382]: use of moved value: `foo_add`
--> $DIR/move-fn-self-receiver.rs:59:5 --> $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 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() {} LL | for _val in explicit_into_iter.clone().into_iter() {}
| ++++++++ | ++++++++
error[E0382]: use of moved value: `container` error[E0382]: use of moved value: `container`
--> $DIR/move-fn-self-receiver.rs:71:5 --> $DIR/move-fn-self-receiver.rs:71:5

View File

@ -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 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()); LL | consume(x.clone().into_iter().next().unwrap());
| ++++++++ | ++++++++
error: aborting due to previous error error: aborting due to previous error

View File

@ -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 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(); LL | let _y = x.clone().into_iter().next().unwrap();
| ++++++++ | ++++++++
error[E0382]: borrow of moved value: `x` error[E0382]: borrow of moved value: `x`
--> $DIR/moves-based-on-type-exprs.rs:83:11 --> $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 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]; LL | let _y = [x.clone().into_iter().next().unwrap(); 1];
| ++++++++ | ++++++++
error: aborting due to 11 previous errors error: aborting due to 11 previous errors

View File

@ -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 help: you can `clone` the value and consume it, but this might not be your desired behavior
| |
LL | foo.clone().foo(); LL | foo.clone().foo();
| ++++++++ | ++++++++
error: aborting due to previous error error: aborting due to previous error

View File

@ -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 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) { LL | if selection.1.clone().unwrap().contains(selection.0) {
| ++++++++ | ++++++++
error[E0507]: cannot move out of `selection.1` which is behind a shared reference error[E0507]: cannot move out of `selection.1` which is behind a shared reference
--> $DIR/option-content-move.rs:27:20 --> $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 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) { LL | if selection.1.clone().unwrap().contains(selection.0) {
| ++++++++ | ++++++++
error: aborting due to 2 previous errors error: aborting due to 2 previous errors