diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index d292611e6a2..f81c71b7394 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -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, ); } diff --git a/tests/ui/async-await/clone-suggestion.stderr b/tests/ui/async-await/clone-suggestion.stderr index c02206f6f9b..b5c8ef6993d 100644 --- a/tests/ui/async-await/clone-suggestion.stderr +++ b/tests/ui/async-await/clone-suggestion.stderr @@ -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 diff --git a/tests/ui/borrowck/borrowck-move-out-of-overloaded-auto-deref.stderr b/tests/ui/borrowck/borrowck-move-out-of-overloaded-auto-deref.stderr index 15d29039172..934dd8df1d2 100644 --- a/tests/ui/borrowck/borrowck-move-out-of-overloaded-auto-deref.stderr +++ b/tests/ui/borrowck/borrowck-move-out-of-overloaded-auto-deref.stderr @@ -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 diff --git a/tests/ui/borrowck/clone-span-on-try-operator.fixed b/tests/ui/borrowck/clone-span-on-try-operator.fixed new file mode 100644 index 00000000000..52f66e43a93 --- /dev/null +++ b/tests/ui/borrowck/clone-span-on-try-operator.fixed @@ -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 +} diff --git a/tests/ui/borrowck/clone-span-on-try-operator.rs b/tests/ui/borrowck/clone-span-on-try-operator.rs new file mode 100644 index 00000000000..031a35e2026 --- /dev/null +++ b/tests/ui/borrowck/clone-span-on-try-operator.rs @@ -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 +} diff --git a/tests/ui/borrowck/clone-span-on-try-operator.stderr b/tests/ui/borrowck/clone-span-on-try-operator.stderr new file mode 100644 index 00000000000..85785e67072 --- /dev/null +++ b/tests/ui/borrowck/clone-span-on-try-operator.stderr @@ -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`. diff --git a/tests/ui/borrowck/unboxed-closures-move-upvar-from-non-once-ref-closure.stderr b/tests/ui/borrowck/unboxed-closures-move-upvar-from-non-once-ref-closure.stderr index f033d53bf8e..a2f6365b74e 100644 --- a/tests/ui/borrowck/unboxed-closures-move-upvar-from-non-once-ref-closure.stderr +++ b/tests/ui/borrowck/unboxed-closures-move-upvar-from-non-once-ref-closure.stderr @@ -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 diff --git a/tests/ui/codemap_tests/tab_3.stderr b/tests/ui/codemap_tests/tab_3.stderr index 17bea2f366f..b17159be6e0 100644 --- a/tests/ui/codemap_tests/tab_3.stderr +++ b/tests/ui/codemap_tests/tab_3.stderr @@ -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 diff --git a/tests/ui/moves/move-fn-self-receiver.stderr b/tests/ui/moves/move-fn-self-receiver.stderr index d1a208b5fc4..c91a8b5efac 100644 --- a/tests/ui/moves/move-fn-self-receiver.stderr +++ b/tests/ui/moves/move-fn-self-receiver.stderr @@ -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) {} 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 diff --git a/tests/ui/moves/moves-based-on-type-access-to-field.stderr b/tests/ui/moves/moves-based-on-type-access-to-field.stderr index a28f324aafa..73901866396 100644 --- a/tests/ui/moves/moves-based-on-type-access-to-field.stderr +++ b/tests/ui/moves/moves-based-on-type-access-to-field.stderr @@ -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 diff --git a/tests/ui/moves/moves-based-on-type-exprs.stderr b/tests/ui/moves/moves-based-on-type-exprs.stderr index ab7c2745688..45f7d4063a5 100644 --- a/tests/ui/moves/moves-based-on-type-exprs.stderr +++ b/tests/ui/moves/moves-based-on-type-exprs.stderr @@ -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 diff --git a/tests/ui/moves/suggest-clone.stderr b/tests/ui/moves/suggest-clone.stderr index 4b96845f539..065acf904a4 100644 --- a/tests/ui/moves/suggest-clone.stderr +++ b/tests/ui/moves/suggest-clone.stderr @@ -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 diff --git a/tests/ui/suggestions/option-content-move.stderr b/tests/ui/suggestions/option-content-move.stderr index 474a72093c6..5060606d842 100644 --- a/tests/ui/suggestions/option-content-move.stderr +++ b/tests/ui/suggestions/option-content-move.stderr @@ -12,7 +12,7 @@ note: `Option::::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::::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