about summary refs log tree commit diff
path: root/tests/ui/borrowck/move-error-snippets.stderr
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2024-04-18 20:41:43 +0000
committerEsteban Küber <esteban@kuber.com.ar>2024-04-24 22:21:13 +0000
commit4aba2c55e6bbe6c09132ff19360d302269dca775 (patch)
treec7d83085f07dbdbc30cb34a437db3f6f85d2c5d7 /tests/ui/borrowck/move-error-snippets.stderr
parentef8b9dcf23700f2e2265317611460d3a65c19eff (diff)
downloadrust-4aba2c55e6bbe6c09132ff19360d302269dca775.tar.gz
rust-4aba2c55e6bbe6c09132ff19360d302269dca775.zip
Modify `find_expr` from `Span` to better account for closures
Start pointing to where bindings were declared when they are captured in closures:

```
error[E0597]: `x` does not live long enough
  --> $DIR/suggest-return-closure.rs:23:9
   |
LL |     let x = String::new();
   |         - binding `x` declared here
...
LL |     |c| {
   |     --- value captured here
LL |         x.push(c);
   |         ^ borrowed value does not live long enough
...
LL | }
   | -- borrow later used here
   | |
   | `x` dropped here while still borrowed
```

Suggest cloning in more cases involving closures:

```
error[E0507]: cannot move out of `foo` in pattern guard
  --> $DIR/issue-27282-move-ref-mut-into-guard.rs:11:19
   |
LL |             if { (|| { let mut bar = foo; bar.take() })(); false } => {},
   |                   ^^                 --- move occurs because `foo` has type `&mut Option<&i32>`, which does not implement the `Copy` trait
   |                   |
   |                   `foo` is moved here
   |
   = note: variables bound in patterns cannot be moved from until after the end of the pattern guard
help: consider cloning the value if the performance cost is acceptable
   |
LL |             if { (|| { let mut bar = foo.clone(); bar.take() })(); false } => {},
   |                                         ++++++++
```
Diffstat (limited to 'tests/ui/borrowck/move-error-snippets.stderr')
0 files changed, 0 insertions, 0 deletions