about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-06-22 20:40:49 +0000
committerMichael Goulet <michael@errs.io>2023-07-10 20:09:28 +0000
commit3a3f4a21445d1175294552fa40446a3116103cef (patch)
tree54373cafd3efe27f636da943111eed5e59c3074b
parentfe870424a75aeb4727f9516808b2f5735d014ab6 (diff)
downloadrust-3a3f4a21445d1175294552fa40446a3116103cef.tar.gz
rust-3a3f4a21445d1175294552fa40446a3116103cef.zip
Don't use method span on clone suggestion
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/mod.rs4
-rw-r--r--tests/ui/async-await/clone-suggestion.stderr2
-rw-r--r--tests/ui/borrowck/borrowck-move-out-of-overloaded-auto-deref.stderr2
-rw-r--r--tests/ui/borrowck/clone-span-on-try-operator.fixed11
-rw-r--r--tests/ui/borrowck/clone-span-on-try-operator.rs11
-rw-r--r--tests/ui/borrowck/clone-span-on-try-operator.stderr21
-rw-r--r--tests/ui/borrowck/unboxed-closures-move-upvar-from-non-once-ref-closure.stderr2
-rw-r--r--tests/ui/codemap_tests/tab_3.stderr2
-rw-r--r--tests/ui/moves/move-fn-self-receiver.stderr6
-rw-r--r--tests/ui/moves/moves-based-on-type-access-to-field.stderr2
-rw-r--r--tests/ui/moves/moves-based-on-type-exprs.stderr4
-rw-r--r--tests/ui/moves/suggest-clone.stderr2
-rw-r--r--tests/ui/suggestions/option-content-move.stderr4
13 files changed, 58 insertions, 15 deletions
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 @@ 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,
                             );
                         }
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<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
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::<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