rust/tests/ui/nll/user-annotations
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
..
adt-brace-enums.rs
adt-brace-enums.stderr
adt-brace-structs.rs
adt-brace-structs.stderr
adt-nullary-enums.rs
adt-nullary-enums.stderr
adt-tuple-enums.rs
adt-tuple-enums.stderr
adt-tuple-struct-calls.rs
adt-tuple-struct-calls.stderr
adt-tuple-struct.rs
adt-tuple-struct.stderr
ascribed-type-wf.rs
ascribed-type-wf.stderr
cast_static_lifetime.rs
cast_static_lifetime.stderr
closure-sig.rs
closure-substs.polonius.stderr
closure-substs.rs
closure-substs.stderr
constant-in-expr-inherent-1.rs
constant-in-expr-inherent-1.stderr
constant-in-expr-inherent-2.rs
constant-in-expr-inherent-2.stderr
constant-in-expr-normalize.rs
constant-in-expr-normalize.stderr
constant-in-expr-trait-item-1.rs
constant-in-expr-trait-item-1.stderr
constant-in-expr-trait-item-2.rs
constant-in-expr-trait-item-2.stderr
constant-in-expr-trait-item-3.rs
constant-in-expr-trait-item-3.stderr
downcast-infer.rs
dump-adt-brace-struct.rs
dump-adt-brace-struct.stderr
dump-fn-method.rs
dump-fn-method.stderr
fns.rs
fns.stderr
inherent-associated-constants.rs
inherent-associated-constants.stderr
issue-54124.rs
issue-54124.stderr
issue-54570-bootstrapping.rs
issue-55219.rs
issue-55241.rs
issue-55748-pat-types-constrain-bindings.rs
issue-55748-pat-types-constrain-bindings.stderr
issue-57731-ascibed-coupled-types.rs
issue-57731-ascibed-coupled-types.stderr
method-call.rs
method-call.stderr
method-ufcs-1.rs
method-ufcs-1.stderr
method-ufcs-2.rs
method-ufcs-2.stderr
method-ufcs-3.rs
method-ufcs-3.stderr
method-ufcs-inherent-1.rs
method-ufcs-inherent-1.stderr
method-ufcs-inherent-2.rs
method-ufcs-inherent-2.stderr
method-ufcs-inherent-3.rs
method-ufcs-inherent-3.stderr
method-ufcs-inherent-4.rs
method-ufcs-inherent-4.stderr
normalization-2.rs
normalization-2.stderr
normalization-default.rs
normalization-default.stderr
normalization-infer.rs
normalization-infer.stderr
normalization-self.rs
normalization-self.stderr
normalization.rs
normalization.stderr
normalize-self-ty.rs
pattern_substs_on_brace_enum_variant.rs
pattern_substs_on_brace_enum_variant.stderr
pattern_substs_on_brace_struct.rs
pattern_substs_on_brace_struct.stderr
pattern_substs_on_tuple_enum_variant.rs
pattern_substs_on_tuple_enum_variant.stderr
pattern_substs_on_tuple_struct.rs
pattern_substs_on_tuple_struct.stderr
patterns.rs
patterns.stderr
promoted-annotation.rs
promoted-annotation.stderr
region-error-ice-109072.rs
region-error-ice-109072.stderr
type_ascription_static_lifetime.rs
type_ascription_static_lifetime.stderr
type-annotation-with-hrtb.rs
wf-self-type.rs
wf-self-type.stderr