2020-06-11 17:48:46 +00:00
|
|
|
error[E0382]: use of moved value: `val.0`
|
|
|
|
--> $DIR/move-fn-self-receiver.rs:30:5
|
|
|
|
|
|
|
|
|
LL | val.0.into_iter().next();
|
|
|
|
| ----------- `val.0` moved due to this method call
|
|
|
|
LL | val.0;
|
|
|
|
| ^^^^^ value used here after move
|
|
|
|
|
|
2022-12-12 12:07:09 +00:00
|
|
|
note: `into_iter` takes ownership of the receiver `self`, which moves `val.0`
|
2020-06-12 02:31:49 +00:00
|
|
|
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
|
2020-09-02 07:40:56 +00:00
|
|
|
= note: move occurs because `val.0` has type `Vec<bool>`, which does not implement the `Copy` trait
|
2022-12-26 00:51:11 +00:00
|
|
|
help: you can `clone` the value and consume it, but this might not be your desired behavior
|
|
|
|
|
|
|
|
|
LL | val.0.clone().into_iter().next();
|
2023-06-22 20:40:49 +00:00
|
|
|
| ++++++++
|
2020-06-11 17:48:46 +00:00
|
|
|
|
|
|
|
error[E0382]: use of moved value: `foo`
|
|
|
|
--> $DIR/move-fn-self-receiver.rs:34:5
|
|
|
|
|
|
|
|
|
LL | let foo = Foo;
|
|
|
|
| --- move occurs because `foo` has type `Foo`, which does not implement the `Copy` trait
|
|
|
|
LL | foo.use_self();
|
|
|
|
| ---------- `foo` moved due to this method call
|
|
|
|
LL | foo;
|
|
|
|
| ^^^ value used here after move
|
|
|
|
|
|
2022-12-12 12:07:09 +00:00
|
|
|
note: `Foo::use_self` takes ownership of the receiver `self`, which moves `foo`
|
2020-06-11 17:48:46 +00:00
|
|
|
--> $DIR/move-fn-self-receiver.rs:13:17
|
|
|
|
|
|
|
|
|
LL | fn use_self(self) {}
|
|
|
|
| ^^^^
|
|
|
|
|
|
|
|
error[E0382]: use of moved value: `second_foo`
|
|
|
|
--> $DIR/move-fn-self-receiver.rs:38:5
|
|
|
|
|
|
|
|
|
LL | let second_foo = Foo;
|
|
|
|
| ---------- move occurs because `second_foo` has type `Foo`, which does not implement the `Copy` trait
|
|
|
|
LL | second_foo.use_self();
|
|
|
|
| ---------- `second_foo` moved due to this method call
|
|
|
|
LL | second_foo;
|
|
|
|
| ^^^^^^^^^^ value used here after move
|
|
|
|
|
|
|
|
error[E0382]: use of moved value: `boxed_foo`
|
|
|
|
--> $DIR/move-fn-self-receiver.rs:42:5
|
|
|
|
|
|
|
|
|
LL | let boxed_foo = Box::new(Foo);
|
2020-09-02 07:40:56 +00:00
|
|
|
| --------- move occurs because `boxed_foo` has type `Box<Foo>`, which does not implement the `Copy` trait
|
2020-06-11 17:48:46 +00:00
|
|
|
LL | boxed_foo.use_box_self();
|
|
|
|
| -------------- `boxed_foo` moved due to this method call
|
|
|
|
LL | boxed_foo;
|
|
|
|
| ^^^^^^^^^ value used here after move
|
|
|
|
|
|
2022-12-12 12:07:09 +00:00
|
|
|
note: `Foo::use_box_self` takes ownership of the receiver `self`, which moves `boxed_foo`
|
2020-06-11 17:48:46 +00:00
|
|
|
--> $DIR/move-fn-self-receiver.rs:14:21
|
|
|
|
|
|
|
|
|
LL | fn use_box_self(self: Box<Self>) {}
|
|
|
|
| ^^^^
|
2024-01-13 17:09:33 +00:00
|
|
|
help: you could `clone` the value and consume it, if the `Foo: Clone` trait bound could be satisfied
|
Suggest cloning and point out obligation errors on move error
When encountering a move error, look for implementations of `Clone` for
the moved type. If there is one, check if all its obligations are met.
If they are, we suggest cloning without caveats. If they aren't, we
suggest cloning while mentioning the unmet obligations, potentially
suggesting `#[derive(Clone)]` when appropriate.
```
error[E0507]: cannot move out of a shared reference
--> $DIR/suggest-clone-when-some-obligation-is-unmet.rs:20:28
|
LL | let mut copy: Vec<U> = map.clone().into_values().collect();
| ^^^^^^^^^^^ ------------- value moved due to this method call
| |
| move occurs because value has type `HashMap<T, U, Hash128_1>`, which does not implement the `Copy` trait
|
note: `HashMap::<K, V, S>::into_values` takes ownership of the receiver `self`, which moves value
--> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
help: you could `clone` the value and consume it, if the `Hash128_1: Clone` trait bound could be satisfied
|
LL | let mut copy: Vec<U> = <HashMap<T, U, Hash128_1> as Clone>::clone(&map.clone()).into_values().collect();
| ++++++++++++++++++++++++++++++++++++++++++++ +
help: consider annotating `Hash128_1` with `#[derive(Clone)]`
|
LL + #[derive(Clone)]
LL | pub struct Hash128_1;
|
```
Fix #109429.
2023-11-20 22:51:52 +00:00
|
|
|
|
|
|
|
|
LL | boxed_foo.clone().use_box_self();
|
|
|
|
| ++++++++
|
2024-01-13 17:09:33 +00:00
|
|
|
help: consider annotating `Foo` with `#[derive(Clone)]`
|
|
|
|
|
|
|
|
|
LL + #[derive(Clone)]
|
|
|
|
LL | struct Foo;
|
|
|
|
|
|
2020-06-11 17:48:46 +00:00
|
|
|
|
|
|
|
error[E0382]: use of moved value: `pin_box_foo`
|
|
|
|
--> $DIR/move-fn-self-receiver.rs:46:5
|
|
|
|
|
|
|
|
|
LL | let pin_box_foo = Box::pin(Foo);
|
2020-09-02 07:40:56 +00:00
|
|
|
| ----------- move occurs because `pin_box_foo` has type `Pin<Box<Foo>>`, which does not implement the `Copy` trait
|
2020-06-11 17:48:46 +00:00
|
|
|
LL | pin_box_foo.use_pin_box_self();
|
|
|
|
| ------------------ `pin_box_foo` moved due to this method call
|
|
|
|
LL | pin_box_foo;
|
|
|
|
| ^^^^^^^^^^^ value used here after move
|
|
|
|
|
|
2022-12-12 12:07:09 +00:00
|
|
|
note: `Foo::use_pin_box_self` takes ownership of the receiver `self`, which moves `pin_box_foo`
|
2020-06-11 17:48:46 +00:00
|
|
|
--> $DIR/move-fn-self-receiver.rs:15:25
|
|
|
|
|
|
|
|
|
LL | fn use_pin_box_self(self: Pin<Box<Self>>) {}
|
|
|
|
| ^^^^
|
2024-01-13 17:09:33 +00:00
|
|
|
help: you could `clone` the value and consume it, if the `Foo: Clone` trait bound could be satisfied
|
Suggest cloning and point out obligation errors on move error
When encountering a move error, look for implementations of `Clone` for
the moved type. If there is one, check if all its obligations are met.
If they are, we suggest cloning without caveats. If they aren't, we
suggest cloning while mentioning the unmet obligations, potentially
suggesting `#[derive(Clone)]` when appropriate.
```
error[E0507]: cannot move out of a shared reference
--> $DIR/suggest-clone-when-some-obligation-is-unmet.rs:20:28
|
LL | let mut copy: Vec<U> = map.clone().into_values().collect();
| ^^^^^^^^^^^ ------------- value moved due to this method call
| |
| move occurs because value has type `HashMap<T, U, Hash128_1>`, which does not implement the `Copy` trait
|
note: `HashMap::<K, V, S>::into_values` takes ownership of the receiver `self`, which moves value
--> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
help: you could `clone` the value and consume it, if the `Hash128_1: Clone` trait bound could be satisfied
|
LL | let mut copy: Vec<U> = <HashMap<T, U, Hash128_1> as Clone>::clone(&map.clone()).into_values().collect();
| ++++++++++++++++++++++++++++++++++++++++++++ +
help: consider annotating `Hash128_1` with `#[derive(Clone)]`
|
LL + #[derive(Clone)]
LL | pub struct Hash128_1;
|
```
Fix #109429.
2023-11-20 22:51:52 +00:00
|
|
|
|
|
|
|
|
LL | pin_box_foo.clone().use_pin_box_self();
|
|
|
|
| ++++++++
|
2024-01-13 17:09:33 +00:00
|
|
|
help: consider annotating `Foo` with `#[derive(Clone)]`
|
|
|
|
|
|
|
|
|
LL + #[derive(Clone)]
|
|
|
|
LL | struct Foo;
|
|
|
|
|
|
2020-06-11 17:48:46 +00:00
|
|
|
|
|
|
|
error[E0505]: cannot move out of `mut_foo` because it is borrowed
|
|
|
|
--> $DIR/move-fn-self-receiver.rs:50:5
|
|
|
|
|
|
2023-01-17 02:52:43 +00:00
|
|
|
LL | let mut mut_foo = Foo;
|
|
|
|
| ----------- binding `mut_foo` declared here
|
2020-06-11 17:48:46 +00:00
|
|
|
LL | let ret = mut_foo.use_mut_self();
|
2023-06-22 20:30:23 +00:00
|
|
|
| ------- borrow of `mut_foo` occurs here
|
2020-06-11 17:48:46 +00:00
|
|
|
LL | mut_foo;
|
|
|
|
| ^^^^^^^ move out of `mut_foo` occurs here
|
|
|
|
LL | ret;
|
|
|
|
| --- borrow later used here
|
|
|
|
|
|
|
|
error[E0382]: use of moved value: `rc_foo`
|
|
|
|
--> $DIR/move-fn-self-receiver.rs:55:5
|
|
|
|
|
|
|
|
|
LL | let rc_foo = Rc::new(Foo);
|
2020-09-02 07:40:56 +00:00
|
|
|
| ------ move occurs because `rc_foo` has type `Rc<Foo>`, which does not implement the `Copy` trait
|
2020-06-11 17:48:46 +00:00
|
|
|
LL | rc_foo.use_rc_self();
|
|
|
|
| ------------- `rc_foo` moved due to this method call
|
|
|
|
LL | rc_foo;
|
|
|
|
| ^^^^^^ value used here after move
|
|
|
|
|
|
2022-12-12 12:07:09 +00:00
|
|
|
note: `Foo::use_rc_self` takes ownership of the receiver `self`, which moves `rc_foo`
|
2020-06-11 17:48:46 +00:00
|
|
|
--> $DIR/move-fn-self-receiver.rs:16:20
|
|
|
|
|
|
|
|
|
LL | fn use_rc_self(self: Rc<Self>) {}
|
|
|
|
| ^^^^
|
2022-12-26 00:51:11 +00:00
|
|
|
help: you can `clone` the value and consume it, but this might not be your desired behavior
|
|
|
|
|
|
|
|
|
LL | rc_foo.clone().use_rc_self();
|
2023-06-22 20:40:49 +00:00
|
|
|
| ++++++++
|
2020-06-11 17:48:46 +00:00
|
|
|
|
|
|
|
error[E0382]: use of moved value: `foo_add`
|
|
|
|
--> $DIR/move-fn-self-receiver.rs:59:5
|
|
|
|
|
|
|
|
|
LL | let foo_add = Foo;
|
|
|
|
| ------- move occurs because `foo_add` has type `Foo`, which does not implement the `Copy` trait
|
|
|
|
LL | foo_add + Foo;
|
|
|
|
| ------------- `foo_add` moved due to usage in operator
|
|
|
|
LL | foo_add;
|
|
|
|
| ^^^^^^^ value used here after move
|
|
|
|
|
|
2024-03-17 21:25:38 +00:00
|
|
|
note: if `Foo` implemented `Clone`, you could clone the value
|
|
|
|
--> $DIR/move-fn-self-receiver.rs:5:1
|
|
|
|
|
|
|
|
|
LL | struct Foo;
|
Mention when type parameter could be `Clone`
```
error[E0382]: use of moved value: `t`
--> $DIR/use_of_moved_value_copy_suggestions.rs:7:9
|
LL | fn duplicate_t<T>(t: T) -> (T, T) {
| - move occurs because `t` has type `T`, which does not implement the `Copy` trait
...
LL | (t, t)
| - ^ value used here after move
| |
| value moved here
|
help: if `T` implemented `Clone`, you could clone the value
--> $DIR/use_of_moved_value_copy_suggestions.rs:4:16
|
LL | fn duplicate_t<T>(t: T) -> (T, T) {
| ^ consider constraining this type parameter with `Clone`
...
LL | (t, t)
| - you could clone this value
help: consider restricting type parameter `T`
|
LL | fn duplicate_t<T: Copy>(t: T) -> (T, T) {
| ++++++
```
The `help` is new. On ADTs, we also extend the output with span labels:
```
error[E0507]: cannot move out of static item `FOO`
--> $DIR/issue-17718-static-move.rs:6:14
|
LL | let _a = FOO;
| ^^^ move occurs because `FOO` has type `Foo`, which does not implement the `Copy` trait
|
note: if `Foo` implemented `Clone`, you could clone the value
--> $DIR/issue-17718-static-move.rs:1:1
|
LL | struct Foo;
| ^^^^^^^^^^ consider implementing `Clone` for this type
...
LL | let _a = FOO;
| --- you could clone this value
help: consider borrowing here
|
LL | let _a = &FOO;
| +
```
2024-04-18 22:18:19 +00:00
|
|
|
| ^^^^^^^^^^ consider implementing `Clone` for this type
|
|
|
|
...
|
|
|
|
LL | foo_add + Foo;
|
|
|
|
| ------- you could clone this value
|
2020-06-11 17:48:46 +00:00
|
|
|
note: calling this operator moves the left-hand side
|
2022-12-12 15:36:08 +00:00
|
|
|
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
|
2020-06-11 17:48:46 +00:00
|
|
|
|
|
|
|
error[E0382]: use of moved value: `implicit_into_iter`
|
|
|
|
--> $DIR/move-fn-self-receiver.rs:63:5
|
|
|
|
|
|
|
|
|
LL | let implicit_into_iter = vec![true];
|
2020-09-02 07:40:56 +00:00
|
|
|
| ------------------ move occurs because `implicit_into_iter` has type `Vec<bool>`, which does not implement the `Copy` trait
|
2020-06-11 17:48:46 +00:00
|
|
|
LL | for _val in implicit_into_iter {}
|
2022-03-02 04:30:16 +00:00
|
|
|
| ------------------ `implicit_into_iter` moved due to this implicit call to `.into_iter()`
|
2020-06-11 17:48:46 +00:00
|
|
|
LL | implicit_into_iter;
|
|
|
|
| ^^^^^^^^^^^^^^^^^^ value used here after move
|
2022-03-02 04:30:16 +00:00
|
|
|
|
|
|
|
|
help: consider iterating over a slice of the `Vec<bool>`'s content to avoid moving into the `for` loop
|
|
|
|
|
|
|
|
|
LL | for _val in &implicit_into_iter {}
|
|
|
|
| +
|
2020-06-11 17:48:46 +00:00
|
|
|
|
|
|
|
error[E0382]: use of moved value: `explicit_into_iter`
|
|
|
|
--> $DIR/move-fn-self-receiver.rs:67:5
|
|
|
|
|
|
|
|
|
LL | let explicit_into_iter = vec![true];
|
2020-09-02 07:40:56 +00:00
|
|
|
| ------------------ move occurs because `explicit_into_iter` has type `Vec<bool>`, which does not implement the `Copy` trait
|
2020-06-11 17:48:46 +00:00
|
|
|
LL | for _val in explicit_into_iter.into_iter() {}
|
|
|
|
| ----------- `explicit_into_iter` moved due to this method call
|
|
|
|
LL | explicit_into_iter;
|
|
|
|
| ^^^^^^^^^^^^^^^^^^ value used here after move
|
2022-11-03 04:22:24 +00:00
|
|
|
|
|
2022-12-26 00:51:11 +00:00
|
|
|
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() {}
|
2023-06-22 20:40:49 +00:00
|
|
|
| ++++++++
|
2020-06-11 17:48:46 +00:00
|
|
|
|
|
|
|
error[E0382]: use of moved value: `container`
|
|
|
|
--> $DIR/move-fn-self-receiver.rs:71:5
|
|
|
|
|
|
|
|
|
LL | let container = Container(vec![]);
|
|
|
|
| --------- move occurs because `container` has type `Container`, which does not implement the `Copy` trait
|
|
|
|
LL | for _val in container.custom_into_iter() {}
|
|
|
|
| ------------------ `container` moved due to this method call
|
|
|
|
LL | container;
|
|
|
|
| ^^^^^^^^^ value used here after move
|
|
|
|
|
|
2022-12-12 12:07:09 +00:00
|
|
|
note: `Container::custom_into_iter` takes ownership of the receiver `self`, which moves `container`
|
2020-06-11 17:48:46 +00:00
|
|
|
--> $DIR/move-fn-self-receiver.rs:23:25
|
|
|
|
|
|
|
|
|
LL | fn custom_into_iter(self) -> impl Iterator<Item = bool> {
|
|
|
|
| ^^^^
|
|
|
|
|
2020-12-23 03:15:40 +00:00
|
|
|
error[E0382]: use of moved value: `foo2`
|
|
|
|
--> $DIR/move-fn-self-receiver.rs:75:9
|
|
|
|
|
|
|
|
|
LL | let foo2 = Foo;
|
|
|
|
| ---- move occurs because `foo2` has type `Foo`, which does not implement the `Copy` trait
|
|
|
|
LL | loop {
|
2022-11-03 04:22:24 +00:00
|
|
|
| ---- inside of this loop
|
2020-12-23 03:15:40 +00:00
|
|
|
LL | foo2.use_self();
|
|
|
|
| ^^^^ ---------- `foo2` moved due to this method call, in previous iteration of loop
|
|
|
|
|
|
|
|
error: aborting due to 12 previous errors
|
2020-06-11 17:48:46 +00:00
|
|
|
|
|
|
|
Some errors have detailed explanations: E0382, E0505.
|
|
|
|
For more information about an error, try `rustc --explain E0382`.
|