rust/tests/ui/moves
Esteban Küber d68f2a6b71 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-24 22:21:15 +00:00
..
assignment-of-clone-call-on-ref-due-to-missing-bound.fixed [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
assignment-of-clone-call-on-ref-due-to-missing-bound.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
assignment-of-clone-call-on-ref-due-to-missing-bound.stderr
borrow-closures-instead-of-move.rs Mention when type parameter could be Clone 2024-04-24 22:21:15 +00:00
borrow-closures-instead-of-move.stderr Mention when type parameter could be Clone 2024-04-24 22:21:15 +00:00
issue-22536-copy-mustnt-zero.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-22536-copy-mustnt-zero.stderr
issue-34721.fixed [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-34721.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-34721.stderr
issue-46099-move-in-macro.rs
issue-46099-move-in-macro.stderr
issue-72649-uninit-in-loop.rs Mention when type parameter could be Clone 2024-04-24 22:21:15 +00:00
issue-72649-uninit-in-loop.stderr Mention when type parameter could be Clone 2024-04-24 22:21:15 +00:00
issue-75904-move-closure-loop.rs
issue-75904-move-closure-loop.stderr Mention when type parameter could be Clone 2024-04-24 22:21:15 +00:00
issue-99470-move-out-of-some.rs
issue-99470-move-out-of-some.stderr
move-1-unique.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
move-2-unique.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
move-2.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
move-3-unique.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
move-4-unique.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
move-4.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
move-arg-2-unique.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
move-arg-2.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
move-arg.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
move-deref-coercion.rs
move-deref-coercion.stderr
move-fn-self-receiver.rs
move-fn-self-receiver.stderr Mention when type parameter could be Clone 2024-04-24 22:21:15 +00:00
move-guard-same-consts.rs
move-guard-same-consts.stderr
move-in-guard-1.rs
move-in-guard-1.stderr
move-in-guard-2.rs
move-in-guard-2.stderr
move-into-dead-array-1.rs
move-into-dead-array-1.stderr Make array suggestions slightly more accurate 2024-04-15 21:45:47 -04:00
move-into-dead-array-2.rs
move-into-dead-array-2.stderr
move-nullary-fn.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
move-of-addr-of-mut.rs
move-of-addr-of-mut.stderr Use /* value */ as a placeholder 2024-04-15 21:36:52 -04:00
move-out-of-array-1.rs
move-out-of-array-1.stderr Mention when type parameter could be Clone 2024-04-24 22:21:15 +00:00
move-out-of-array-ref.rs
move-out-of-array-ref.stderr
move-out-of-field.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
move-out-of-slice-1.rs
move-out-of-slice-1.stderr
move-out-of-slice-2.rs
move-out-of-slice-2.stderr
move-out-of-tuple-field.rs
move-out-of-tuple-field.stderr
move-scalar.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
moves-based-on-type-access-to-field.rs
moves-based-on-type-access-to-field.stderr
moves-based-on-type-block-bad.rs
moves-based-on-type-block-bad.stderr
moves-based-on-type-capture-clause-bad.rs Better account for more cases involving closures 2024-04-12 04:46:31 +00:00
moves-based-on-type-capture-clause-bad.stderr Better account for more cases involving closures 2024-04-12 04:46:31 +00:00
moves-based-on-type-capture-clause.rs compiletest: Add a //@ needs-threads directive 2024-03-06 12:35:07 -08:00
moves-based-on-type-cyclic-types-issue-4821.rs
moves-based-on-type-cyclic-types-issue-4821.stderr
moves-based-on-type-distribute-copy-over-paren.rs
moves-based-on-type-distribute-copy-over-paren.stderr
moves-based-on-type-exprs.rs
moves-based-on-type-exprs.stderr
moves-based-on-type-match-bindings.rs
moves-based-on-type-match-bindings.stderr
moves-based-on-type-move-out-of-closure-env-issue-1965.rs
moves-based-on-type-move-out-of-closure-env-issue-1965.stderr Suggest .clone() in some move errors 2024-04-11 16:41:41 +00:00
moves-based-on-type-no-recursive-stack-closure.rs
moves-based-on-type-no-recursive-stack-closure.stderr Mention when type parameter could be Clone 2024-04-24 22:21:15 +00:00
moves-based-on-type-tuple.rs
moves-based-on-type-tuple.stderr
moves-sru-moved-field.rs
moves-sru-moved-field.stderr
needs-clone-through-deref.fixed Silence redundant clone suggestion 2024-04-11 16:41:41 +00:00
needs-clone-through-deref.rs Silence redundant clone suggestion 2024-04-11 16:41:41 +00:00
needs-clone-through-deref.stderr Silence redundant clone suggestion 2024-04-11 16:41:41 +00:00
nested-loop-moved-value-wrong-continue.rs Point at continue and break that might be in the wrong place 2024-03-17 21:32:26 +00:00
nested-loop-moved-value-wrong-continue.stderr Point at continue and break that might be in the wrong place 2024-03-17 21:32:26 +00:00
pin-mut-reborrow-infer-var-issue-107419.fixed [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
pin-mut-reborrow-infer-var-issue-107419.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
pin-mut-reborrow-infer-var-issue-107419.stderr
pin-mut-reborrow.fixed [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
pin-mut-reborrow.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
pin-mut-reborrow.stderr
recreating-value-in-loop-condition.rs Add HELP to test 2024-03-17 21:45:03 +00:00
recreating-value-in-loop-condition.stderr Add HELP to test 2024-03-17 21:45:03 +00:00
suggest-clone-when-some-obligation-is-unmet.fixed Account for .clone() when suggesting <T as Clone>::clone 2024-04-11 16:41:40 +00:00
suggest-clone-when-some-obligation-is-unmet.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
suggest-clone-when-some-obligation-is-unmet.stderr Account for .clone() when suggesting <T as Clone>::clone 2024-04-11 16:41:40 +00:00
suggest-clone.fixed Suggest .clone() in some move errors 2024-04-11 16:41:41 +00:00
suggest-clone.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
suggest-clone.stderr Suggest .clone() in some move errors 2024-04-11 16:41:41 +00:00
use_of_moved_value_clone_suggestions.rs
use_of_moved_value_clone_suggestions.stderr
use_of_moved_value_copy_suggestions.fixed Mention when type parameter could be Clone 2024-04-24 22:21:15 +00:00
use_of_moved_value_copy_suggestions.rs Mention when type parameter could be Clone 2024-04-24 22:21:15 +00:00
use_of_moved_value_copy_suggestions.stderr Mention when type parameter could be Clone 2024-04-24 22:21:15 +00:00