diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2024-04-18 20:41:43 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2024-04-24 22:21:13 +0000 |
| commit | 4aba2c55e6bbe6c09132ff19360d302269dca775 (patch) | |
| tree | c7d83085f07dbdbc30cb34a437db3f6f85d2c5d7 /tests/ui/span | |
| parent | ef8b9dcf23700f2e2265317611460d3a65c19eff (diff) | |
| download | rust-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/span')
| -rw-r--r-- | tests/ui/span/send-is-not-static-ensures-scoping.stderr | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/tests/ui/span/send-is-not-static-ensures-scoping.stderr b/tests/ui/span/send-is-not-static-ensures-scoping.stderr index bae0befcaca..c15547e8412 100644 --- a/tests/ui/span/send-is-not-static-ensures-scoping.stderr +++ b/tests/ui/span/send-is-not-static-ensures-scoping.stderr @@ -16,6 +16,9 @@ error[E0597]: `y` does not live long enough | LL | let bad = { | --- borrow later stored here +LL | let x = 1; +LL | let y = &x; + | - binding `y` declared here ... LL | scoped(|| { | -- value captured here |
