about summary refs log tree commit diff
path: root/tests/ui/span
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2025-07-28 02:01:46 +0000
committerEsteban Küber <esteban@kuber.com.ar>2025-08-10 19:22:49 +0000
commit1aa5668d20d53976860d141a66aa727e425e1079 (patch)
treea03a92171b4937e65ff1c5812163134ab957df59 /tests/ui/span
parent18eeac04fc5c2a4c4a8020dbdf1c652077ad0e4e (diff)
downloadrust-1aa5668d20d53976860d141a66aa727e425e1079.tar.gz
rust-1aa5668d20d53976860d141a66aa727e425e1079.zip
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()) {
   |               ++++++++
```
Diffstat (limited to 'tests/ui/span')
-rw-r--r--tests/ui/span/borrowck-call-is-borrow-issue-12224.stderr1
1 files changed, 1 insertions, 0 deletions
diff --git a/tests/ui/span/borrowck-call-is-borrow-issue-12224.stderr b/tests/ui/span/borrowck-call-is-borrow-issue-12224.stderr
index f37dc320fa3..8081f7b3a8b 100644
--- a/tests/ui/span/borrowck-call-is-borrow-issue-12224.stderr
+++ b/tests/ui/span/borrowck-call-is-borrow-issue-12224.stderr
@@ -44,6 +44,7 @@ LL |
 LL |         foo(f);
    |             ^ move occurs because `f` has type `{closure@$DIR/borrowck-call-is-borrow-issue-12224.rs:52:17: 52:58}`, which does not implement the `Copy` trait
    |
+   = help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
 help: consider cloning the value if the performance cost is acceptable
    |
 LL |         foo(f.clone());