rust/tests/ui/coroutine/dropck.stderr
Esteban Küber 4aba2c55e6 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 } => {},
   |                                         ++++++++
```
2024-04-24 22:21:13 +00:00

41 lines
1.4 KiB
Plaintext

error[E0597]: `*cell` does not live long enough
--> $DIR/dropck.rs:10:40
|
LL | let (mut gen, cell);
| ---- binding `cell` declared here
LL | cell = Box::new(RefCell::new(0));
LL | let ref_ = Box::leak(Box::new(Some(cell.borrow_mut())));
| ^^^^ borrowed value does not live long enough
...
LL | }
| -
| |
| `*cell` dropped here while still borrowed
| borrow might be used here, when `gen` is dropped and runs the destructor for coroutine
|
= note: values in a scope are dropped in the opposite order they are defined
error[E0597]: `ref_` does not live long enough
--> $DIR/dropck.rs:16:18
|
LL | let ref_ = Box::leak(Box::new(Some(cell.borrow_mut())));
| ---- binding `ref_` declared here
...
LL | || {
| -- value captured here by coroutine
LL | // but the coroutine can use it to drop a `Ref<'a, i32>`.
LL | let _d = ref_.take();
| ^^^^ borrowed value does not live long enough
...
LL | }
| -
| |
| `ref_` dropped here while still borrowed
| borrow might be used here, when `gen` is dropped and runs the destructor for coroutine
|
= note: values in a scope are dropped in the opposite order they are defined
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0597`.