diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2025-07-20 03:15:20 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2025-07-25 18:34:10 +0000 |
| commit | 11061831f703fdb5d05816860368e4b9ab4edee7 (patch) | |
| tree | 9a1519ef8767184a5a4fef79c7f9d87afc2e1ff7 /tests/ui/closures | |
| parent | a955f1cd09a027363729ceed919952d09f76f28e (diff) | |
| download | rust-11061831f703fdb5d05816860368e4b9ab4edee7.tar.gz rust-11061831f703fdb5d05816860368e4b9ab4edee7.zip | |
Mention type that could be `Clone` but isn't in more cases
When encountering a moved value of a type that isn't `Clone` because of unmet obligations, but where all the unmet predicates reference crate-local types, mention them and suggest cloning, as we do in other cases already:
```
error[E0507]: cannot move out of `foo`, a captured variable in an `Fn` closure
--> f111.rs:14:25
|
13 | fn do_stuff(foo: Option<Foo>) {
| --- captured outer variable
14 | require_fn_trait(|| async {
| -- ^^^^^ `foo` is moved here
| |
| captured by this `Fn` closure
15 | if foo.map_or(false, |f| f.foo()) {
| ---
| |
| variable moved due to use in coroutine
| move occurs because `foo` has type `Option<Foo>`, which does not implement the `Copy` trait
|
note: if `Foo` implemented `Clone`, you could clone the value
--> f111.rs:4:1
|
4 | struct Foo;
| ^^^^^^^^^^ consider implementing `Clone` for this type
...
15 | if foo.map_or(false, |f| f.foo()) {
| --- you could clone this value
```
Diffstat (limited to 'tests/ui/closures')
| -rw-r--r-- | tests/ui/closures/2229_closure_analysis/match/if-let-guards-errors.e2018.stderr | 9 | ||||
| -rw-r--r-- | tests/ui/closures/2229_closure_analysis/match/if-let-guards-errors.e2021.stderr | 9 |
2 files changed, 18 insertions, 0 deletions
diff --git a/tests/ui/closures/2229_closure_analysis/match/if-let-guards-errors.e2018.stderr b/tests/ui/closures/2229_closure_analysis/match/if-let-guards-errors.e2018.stderr index 394629c0001..057960ec014 100644 --- a/tests/ui/closures/2229_closure_analysis/match/if-let-guards-errors.e2018.stderr +++ b/tests/ui/closures/2229_closure_analysis/match/if-let-guards-errors.e2018.stderr @@ -26,6 +26,15 @@ LL | E::Number(_) if let E::String(s) = *value => { } ... LL | let x = value; | ^^^^^ value used here after move + | +note: if `E` implemented `Clone`, you could clone the value + --> $DIR/if-let-guards-errors.rs:32:1 + | +LL | E::Number(_) if let E::String(s) = *value => { } + | ------ you could clone this value +... +LL | enum E { + | ^^^^^^ consider implementing `Clone` for this type error: aborting due to 2 previous errors diff --git a/tests/ui/closures/2229_closure_analysis/match/if-let-guards-errors.e2021.stderr b/tests/ui/closures/2229_closure_analysis/match/if-let-guards-errors.e2021.stderr index 5672845019b..4a6e3908827 100644 --- a/tests/ui/closures/2229_closure_analysis/match/if-let-guards-errors.e2021.stderr +++ b/tests/ui/closures/2229_closure_analysis/match/if-let-guards-errors.e2021.stderr @@ -26,6 +26,15 @@ LL | E::Number(_) if let E::String(s) = *value => { } ... LL | let x = value; | ^^^^^ value used here after move + | +note: if `E` implemented `Clone`, you could clone the value + --> $DIR/if-let-guards-errors.rs:32:1 + | +LL | E::Number(_) if let E::String(s) = *value => { } + | ------ you could clone this value +... +LL | enum E { + | ^^^^^^ consider implementing `Clone` for this type error: aborting due to 2 previous errors |
