Don't use method span on clone suggestion
This commit is contained in:
parent
fe870424a7
commit
3a3f4a2144
@ -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,
|
||||
);
|
||||
}
|
||||
|
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`.
|
Loading…
x
Reference in New Issue
Block a user