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)
{
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,
);
}

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