Skip to content

Commit 3a3f4a2

Browse files
Don't use method span on clone suggestion
1 parent fe87042 commit 3a3f4a2

13 files changed

+58
-15
lines changed

compiler/rustc_borrowck/src/diagnostics/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1135,10 +1135,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11351135
&& self.infcx.predicate_must_hold_modulo_regions(&o)
11361136
{
11371137
err.span_suggestion_verbose(
1138-
fn_call_span.shrink_to_lo(),
1138+
move_span.shrink_to_hi(),
11391139
"you can `clone` the value and consume it, but this might not be \
11401140
your desired behavior",
1141-
"clone().".to_string(),
1141+
".clone()".to_string(),
11421142
Applicability::MaybeIncorrect,
11431143
);
11441144
}

tests/ui/async-await/clone-suggestion.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ note: `into_future` takes ownership of the receiver `self`, which moves `f`
1313
help: you can `clone` the value and consume it, but this might not be your desired behavior
1414
|
1515
LL | f.clone().await;
16-
| ++++++++
16+
| ++++++++
1717

1818
error: aborting due to previous error
1919

tests/ui/borrowck/borrowck-move-out-of-overloaded-auto-deref.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ note: `into_iter` takes ownership of the receiver `self`, which moves value
1111
help: you can `clone` the value and consume it, but this might not be your desired behavior
1212
|
1313
LL | let _x = Rc::new(vec![1, 2]).clone().into_iter();
14-
| ++++++++
14+
| ++++++++
1515

1616
error: aborting due to previous error
1717

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// run-rustfix
2+
3+
#[derive(Clone)]
4+
struct Foo;
5+
impl Foo {
6+
fn foo(self) {}
7+
}
8+
fn main() {
9+
let foo = &Foo;
10+
(*foo).clone().foo(); //~ ERROR cannot move out
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// run-rustfix
2+
3+
#[derive(Clone)]
4+
struct Foo;
5+
impl Foo {
6+
fn foo(self) {}
7+
}
8+
fn main() {
9+
let foo = &Foo;
10+
(*foo).foo(); //~ ERROR cannot move out
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0507]: cannot move out of `*foo` which is behind a shared reference
2+
--> $DIR/clone-span-on-try-operator.rs:10:5
3+
|
4+
LL | (*foo).foo();
5+
| ^^^^^^ ----- `*foo` moved due to this method call
6+
| |
7+
| move occurs because `*foo` has type `Foo`, which does not implement the `Copy` trait
8+
|
9+
note: `Foo::foo` takes ownership of the receiver `self`, which moves `*foo`
10+
--> $DIR/clone-span-on-try-operator.rs:6:12
11+
|
12+
LL | fn foo(self) {}
13+
| ^^^^
14+
help: you can `clone` the value and consume it, but this might not be your desired behavior
15+
|
16+
LL | (*foo).clone().foo();
17+
| ++++++++
18+
19+
error: aborting due to previous error
20+
21+
For more information about this error, try `rustc --explain E0507`.

tests/ui/borrowck/unboxed-closures-move-upvar-from-non-once-ref-closure.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ note: `into_iter` takes ownership of the receiver `self`, which moves `y`
1515
help: you can `clone` the value and consume it, but this might not be your desired behavior
1616
|
1717
LL | y.clone().into_iter();
18-
| ++++++++
18+
| ++++++++
1919

2020
error: aborting due to previous error
2121

tests/ui/codemap_tests/tab_3.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ note: `into_iter` takes ownership of the receiver `self`, which moves `some_vec`
1515
help: you can `clone` the value and consume it, but this might not be your desired behavior
1616
|
1717
LL | some_vec.clone().into_iter();
18-
| ++++++++
18+
| ++++++++
1919

2020
error: aborting due to previous error
2121

tests/ui/moves/move-fn-self-receiver.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ note: `into_iter` takes ownership of the receiver `self`, which moves `val.0`
1212
help: you can `clone` the value and consume it, but this might not be your desired behavior
1313
|
1414
LL | val.0.clone().into_iter().next();
15-
| ++++++++
15+
| ++++++++
1616

1717
error[E0382]: use of moved value: `foo`
1818
--> $DIR/move-fn-self-receiver.rs:34:5
@@ -102,7 +102,7 @@ LL | fn use_rc_self(self: Rc<Self>) {}
102102
help: you can `clone` the value and consume it, but this might not be your desired behavior
103103
|
104104
LL | rc_foo.clone().use_rc_self();
105-
| ++++++++
105+
| ++++++++
106106

107107
error[E0382]: use of moved value: `foo_add`
108108
--> $DIR/move-fn-self-receiver.rs:59:5
@@ -145,7 +145,7 @@ LL | explicit_into_iter;
145145
help: you can `clone` the value and consume it, but this might not be your desired behavior
146146
|
147147
LL | for _val in explicit_into_iter.clone().into_iter() {}
148-
| ++++++++
148+
| ++++++++
149149

150150
error[E0382]: use of moved value: `container`
151151
--> $DIR/move-fn-self-receiver.rs:71:5

tests/ui/moves/moves-based-on-type-access-to-field.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ note: `into_iter` takes ownership of the receiver `self`, which moves `x`
1313
help: you can `clone` the value and consume it, but this might not be your desired behavior
1414
|
1515
LL | consume(x.clone().into_iter().next().unwrap());
16-
| ++++++++
16+
| ++++++++
1717

1818
error: aborting due to previous error
1919

tests/ui/moves/moves-based-on-type-exprs.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ note: `into_iter` takes ownership of the receiver `self`, which moves `x`
165165
help: you can `clone` the value and consume it, but this might not be your desired behavior
166166
|
167167
LL | let _y = x.clone().into_iter().next().unwrap();
168-
| ++++++++
168+
| ++++++++
169169

170170
error[E0382]: borrow of moved value: `x`
171171
--> $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`
182182
help: you can `clone` the value and consume it, but this might not be your desired behavior
183183
|
184184
LL | let _y = [x.clone().into_iter().next().unwrap(); 1];
185-
| ++++++++
185+
| ++++++++
186186

187187
error: aborting due to 11 previous errors
188188

tests/ui/moves/suggest-clone.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ LL | fn foo(self) {}
1414
help: you can `clone` the value and consume it, but this might not be your desired behavior
1515
|
1616
LL | foo.clone().foo();
17-
| ++++++++
17+
| ++++++++
1818

1919
error: aborting due to previous error
2020

tests/ui/suggestions/option-content-move.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ note: `Option::<T>::unwrap` takes ownership of the receiver `self`, which moves
1212
help: you can `clone` the value and consume it, but this might not be your desired behavior
1313
|
1414
LL | if selection.1.clone().unwrap().contains(selection.0) {
15-
| ++++++++
15+
| ++++++++
1616

1717
error[E0507]: cannot move out of `selection.1` which is behind a shared reference
1818
--> $DIR/option-content-move.rs:27:20
@@ -28,7 +28,7 @@ note: `Result::<T, E>::unwrap` takes ownership of the receiver `self`, which mov
2828
help: you can `clone` the value and consume it, but this might not be your desired behavior
2929
|
3030
LL | if selection.1.clone().unwrap().contains(selection.0) {
31-
| ++++++++
31+
| ++++++++
3232

3333
error: aborting due to 2 previous errors
3434

0 commit comments

Comments
 (0)