rust/tests/ui/nll/closure-requirements
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
..
escape-argument-callee.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
escape-argument-callee.stderr update region debug formatting 2024-03-18 16:44:12 +00:00
escape-argument.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
escape-argument.stderr update region debug formatting 2024-03-18 16:44:12 +00:00
escape-upvar-nested.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
escape-upvar-nested.stderr Modify find_expr from Span to better account for closures 2024-04-24 22:21:13 +00:00
escape-upvar-ref.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
escape-upvar-ref.stderr Modify find_expr from Span to better account for closures 2024-04-24 22:21:13 +00:00
issue-58127-mutliple-requirements.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
propagate-approximated-fail-no-postdom.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
propagate-approximated-fail-no-postdom.stderr update region debug formatting 2024-03-18 16:44:12 +00:00
propagate-approximated-ref.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
propagate-approximated-ref.stderr update region debug formatting 2024-03-18 16:44:12 +00:00
propagate-approximated-shorter-to-static-comparing-against-free.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
propagate-approximated-shorter-to-static-comparing-against-free.stderr Stop ConstraintCategory Ord impl from relying on Ty's Ord impl. 2024-03-21 10:45:30 +00:00
propagate-approximated-shorter-to-static-no-bound.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
propagate-approximated-shorter-to-static-no-bound.stderr update region debug formatting 2024-03-18 16:44:12 +00:00
propagate-approximated-shorter-to-static-wrong-bound.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
propagate-approximated-shorter-to-static-wrong-bound.stderr update region debug formatting 2024-03-18 16:44:12 +00:00
propagate-approximated-val.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
propagate-approximated-val.stderr update region debug formatting 2024-03-18 16:44:12 +00:00
propagate-despite-same-free-region.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
propagate-despite-same-free-region.stderr update region debug formatting 2024-03-18 16:44:12 +00:00
propagate-fail-to-approximate-longer-no-bounds.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
propagate-fail-to-approximate-longer-no-bounds.stderr update region debug formatting 2024-03-18 16:44:12 +00:00
propagate-fail-to-approximate-longer-wrong-bounds.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
propagate-fail-to-approximate-longer-wrong-bounds.stderr update region debug formatting 2024-03-18 16:44:12 +00:00
propagate-from-trait-match.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
propagate-from-trait-match.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
propagate-multiple-requirements.rs
propagate-multiple-requirements.stderr Modify find_expr from Span to better account for closures 2024-04-24 22:21:13 +00:00
region-lbr1-does-not-outlive-ebr2.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
region-lbr1-does-not-outlive-ebr2.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
region-lbr1-does-outlive-lbr2-because-implied-bound.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
region-lbr-anon-does-not-outlive-static.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
region-lbr-anon-does-not-outlive-static.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
region-lbr-named-does-not-outlive-static.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
region-lbr-named-does-not-outlive-static.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
return-wrong-bound-region.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
return-wrong-bound-region.stderr update region debug formatting 2024-03-18 16:44:12 +00:00
type-test-subject-non-trivial-region.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
type-test-subject-opaque-1.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
type-test-subject-opaque-2.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
type-test-subject-unnamed-region.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00