Matthias Krüger
33a9e4f821
Rollup merge of #144200 - estebank:dont-point-at-closure, r=lcnr
...
Tweak output for non-`Clone` values moved into closures
When we encounter a non-`Clone` value being moved into a closure, try to find the corresponding type of the binding being moved, if it is a `let`-binding or a function parameter. If any of those cases, we point at them with the note explaining that the type is not `Copy`, instead of giving that label to the place where it is captured. When it is a `let`-binding with no explicit type, we point at the initializer (if it fits in a single line).
```
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>) {
| --- ----------- move occurs because `foo` has type `Option<Foo>`, which does not implement the `Copy` trait
| |
| 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
```
instead of
```
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
```
2025-07-25 11:16:36 +02:00
..
2025-01-14 14:16:12 +01:00
2025-04-08 23:06:31 +03:00
2025-01-31 11:04:50 +00:00
2025-04-22 12:07:53 +02:00
2025-07-04 18:14:22 +00:00
2025-06-24 18:59:42 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2025-04-26 14:48:30 +09:00
2025-07-16 01:44:02 -07:00
2023-11-24 19:15:52 +01:00
2025-04-08 23:06:31 +03:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2024-04-11 16:41:41 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2025-02-11 19:24:07 +00:00
2025-02-11 19:24:07 +00:00
2025-02-11 19:24:07 +00:00
2024-07-26 14:41:56 -04:00
2024-04-24 22:21:13 +00:00
2024-07-04 05:36:34 +00:00
2024-02-16 20:02:50 +00:00
2023-10-05 01:04:41 +00:00
2024-04-12 04:46:31 +00:00
2024-04-12 04:46:31 +00:00
2024-04-12 04:46:31 +00:00
2024-04-12 04:46:31 +00:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2024-02-08 08:10:43 +00:00
2024-02-08 08:10:43 +00:00
2024-04-24 08:05:29 +00:00
2024-04-24 08:05:29 +00:00
2024-07-04 05:36:34 +00:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-04-24 08:05:29 +00:00
2025-01-31 11:04:50 +00:00
2025-01-31 11:04:50 +00:00
2025-01-31 11:04:50 +00:00
2025-01-31 11:04:50 +00:00
2024-03-23 16:14:42 +01:00
2024-03-23 12:50:21 +01:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-04-24 22:21:15 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-07-26 14:41:56 -04:00
2024-07-26 14:41:56 -04:00
2024-07-26 14:41:56 -04:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2024-07-26 14:41:56 -04:00
2024-02-16 20:02:50 +00:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2024-04-07 17:38:07 -03:00
2024-04-07 17:38:07 -03:00
2024-04-07 17:38:07 -03:00
2024-04-07 17:38:07 -03:00
2024-04-07 17:38:07 -03:00
2024-04-07 17:38:07 -03:00
2024-04-24 22:21:13 +00:00
2024-02-16 20:02:50 +00:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-07-04 05:36:34 +00:00
2023-11-24 19:15:52 +01:00
2025-01-31 11:04:50 +00:00
2025-01-31 11:04:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2024-04-24 08:05:29 +00:00
2024-04-24 08:05:29 +00:00
2025-04-08 23:06:31 +03:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2025-07-16 12:35:44 +00:00
2025-07-16 12:35:44 +00:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2025-01-23 20:51:29 +08:00
2024-02-16 20:02:50 +00:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-07-26 14:41:56 -04:00
2024-02-16 20:02:50 +00:00
2024-04-11 16:41:41 +00:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2024-06-18 04:14:43 +08:00
2023-11-24 19:15:52 +01:00
2025-07-21 16:21:23 +00:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2023-11-24 19:15:52 +01:00
2024-03-10 21:18:41 -04:00
2024-02-16 20:02:50 +00:00
2025-06-04 10:40:04 -04:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2024-03-20 13:00:34 -04:00
2024-03-20 13:00:34 -04:00
2023-12-15 06:59:42 +00:00
2023-11-24 19:15:52 +01:00
2024-11-28 14:32:45 -08:00
2025-06-04 10:40:04 -04:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2025-04-08 23:06:31 +03:00
2025-01-06 16:12:11 -08:00
2024-02-16 20:02:50 +00:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2024-05-03 15:56:59 +02:00
2024-05-03 15:56:59 +02:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-04-24 08:05:29 +00:00
2024-07-21 22:32:29 -04:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-04-21 15:43:43 -03:00
2024-04-21 15:43:43 -03:00
2024-04-21 20:10:12 -04:00
2025-05-24 23:31:07 +02:00
2024-04-21 20:10:12 -04:00
2025-05-24 23:31:07 +02:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2023-11-24 19:15:52 +01:00
2025-01-06 16:08:29 -08:00
2025-01-06 16:08:29 -08:00
2024-02-16 20:02:50 +00:00
2025-01-06 16:08:29 -08:00
2025-01-06 16:08:29 -08:00
2023-11-24 19:15:52 +01:00
2024-09-13 14:10:56 +03:00
2024-09-13 14:10:56 +03:00
2023-11-24 19:15:52 +01:00
2024-08-17 12:43:25 -04:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2025-01-06 16:08:29 -08:00
2025-01-06 16:08:29 -08:00
2025-03-06 12:53:35 +01:00
2025-03-06 12:53:35 +01:00
2024-02-16 20:02:50 +00:00
2025-01-06 16:12:11 -08:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2023-11-24 19:15:52 +01:00
2024-04-03 21:02:47 +02:00
2024-04-03 21:02:47 +02:00
2024-04-03 23:16:27 +02:00
2024-04-10 20:36:14 +00:00
2024-07-26 14:41:56 -04:00
2024-07-26 14:41:56 -04:00
2024-04-15 21:36:52 -04:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2024-03-14 17:19:40 +01:00
2024-03-14 17:19:40 +01:00
2024-11-25 20:29:04 -08:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2025-05-02 18:45:28 +00:00
2025-05-02 18:45:28 +00:00
2024-02-14 11:00:30 +00:00
2025-02-15 12:18:30 +08:00
2024-02-16 20:02:50 +00:00
2025-01-06 16:08:29 -08:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2024-12-12 23:36:27 +00:00
2025-05-27 22:19:56 +08:00
2025-05-27 22:19:56 +08:00
2025-05-27 22:19:56 +08:00
2023-12-07 23:00:46 -05:00
2025-01-06 16:12:11 -08:00
2024-03-24 10:05:27 +01:00
2024-02-16 20:02:50 +00:00
2024-02-16 20:02:50 +00:00
2023-11-24 19:15:52 +01:00
2024-02-16 20:02:50 +00:00
2023-11-24 19:15:52 +01:00
2025-01-06 16:08:29 -08:00