diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-08-11 12:21:08 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-11 12:21:08 +1000 |
| commit | 907076c3dd5dc983df954755ce953725eda159eb (patch) | |
| tree | b7cf4b0f1828e3af23ad9778148f449343dd4c1d /tests/ui/async-await/recursive-async-auto-trait-overflow.rs | |
| parent | 3724e13cc7de90804ff6be508cd47ee8d979feb8 (diff) | |
| parent | 74496bc4d9f64ea01ae3714b9680cc22c1535cb2 (diff) | |
| download | rust-907076c3dd5dc983df954755ce953725eda159eb.tar.gz rust-907076c3dd5dc983df954755ce953725eda159eb.zip | |
Rollup merge of #144558 - estebank:issue-68119, r=lcnr
Point at the `Fn()` or `FnMut()` bound that coerced a closure, which caused a move error
When encountering a move error involving a closure because the captured value isn't `Copy`, and the obligation comes from a bound on a type parameter that requires `Fn` or `FnMut`, we point at it and explain that an `FnOnce` wouldn't cause the move error.
```
error[E0507]: cannot move out of `foo`, a captured variable in an `Fn` closure
--> f111.rs:15:25
|
14 | fn do_stuff(foo: Option<Foo>) {
| --- ----------- move occurs because `foo` has type `Option<Foo>`, which does not implement the `Copy` trait
| |
| captured outer variable
15 | require_fn_trait(|| async {
| -- ^^^^^ `foo` is moved here
| |
| captured by this `Fn` closure
16 | if foo.map_or(false, |f| f.foo()) {
| --- variable moved due to use in coroutine
|
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
--> f111.rs:12:53
|
12 | fn require_fn_trait<F: Future<Output = ()>>(_: impl Fn() -> F) {}
| ^^^^^^^^^
help: consider cloning the value if the performance cost is acceptable
|
16 | if foo.clone().map_or(false, |f| f.foo()) {
| ++++++++
```
Fix rust-lang/rust#68119, by pointing at `Fn` and `FnMut` bounds involved in move errors.
Diffstat (limited to 'tests/ui/async-await/recursive-async-auto-trait-overflow.rs')
0 files changed, 0 insertions, 0 deletions
