diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-07-25 11:16:36 +0200 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-25 11:16:36 +0200 | 
| commit | 33a9e4f8210c97ced94ea93c1ac03cdd7b25e6c3 (patch) | |
| tree | b4378a5c77afd66e3addd1d69d1c224b6c2f540f /tests/codegen-llvm/vec-iter.rs | |
| parent | dfbd0c4e5aa4e2b44620549f73da45d1f16cfd6a (diff) | |
| parent | 6237e735c4dc165b3efec236e11a44bdccf1dfd7 (diff) | |
| download | rust-33a9e4f8210c97ced94ea93c1ac03cdd7b25e6c3.tar.gz rust-33a9e4f8210c97ced94ea93c1ac03cdd7b25e6c3.zip | |
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
```
Diffstat (limited to 'tests/codegen-llvm/vec-iter.rs')
0 files changed, 0 insertions, 0 deletions
