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 Extend and use `hir::Node::body_id` 2023-04-19 19:13:45 +00:00
adt-brace-structs.rs
adt-brace-structs.stderr Extend and use `hir::Node::body_id` 2023-04-19 19:13:45 +00:00
adt-nullary-enums.rs
adt-nullary-enums.stderr Stop `ConstraintCategory` `Ord` impl from relying on `Ty`'s `Ord` impl. 2024-03-21 10:45:30 +00:00
adt-tuple-enums.rs
adt-tuple-enums.stderr Extend and use `hir::Node::body_id` 2023-04-19 19:13:45 +00:00
adt-tuple-struct-calls.rs
adt-tuple-struct-calls.stderr Extend and use `hir::Node::body_id` 2023-04-19 19:13:45 +00:00
adt-tuple-struct.rs
adt-tuple-struct.stderr Extend and use `hir::Node::body_id` 2023-04-19 19:13:45 +00:00
ascribed-type-wf.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
ascribed-type-wf.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
cast_static_lifetime.rs
cast_static_lifetime.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
closure-sig.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
closure-substs.polonius.stderr
closure-substs.rs
closure-substs.stderr
constant-in-expr-inherent-1.rs
constant-in-expr-inherent-1.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
constant-in-expr-inherent-2.rs
constant-in-expr-inherent-2.stderr
constant-in-expr-normalize.rs
constant-in-expr-normalize.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
constant-in-expr-trait-item-1.rs
constant-in-expr-trait-item-1.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
constant-in-expr-trait-item-2.rs
constant-in-expr-trait-item-2.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
constant-in-expr-trait-item-3.rs
constant-in-expr-trait-item-3.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
downcast-infer.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
dump-adt-brace-struct.rs update region debug formatting 2024-03-18 16:44:12 +00:00
dump-adt-brace-struct.stderr update region debug formatting 2024-03-18 16:44:12 +00:00
dump-fn-method.rs update region debug formatting 2024-03-18 16:44:12 +00:00
dump-fn-method.stderr update region debug formatting 2024-03-18 16:44:12 +00:00
fns.rs
fns.stderr Extend and use `hir::Node::body_id` 2023-04-19 19:13:45 +00:00
inherent-associated-constants.rs
inherent-associated-constants.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-54124.rs
issue-54124.stderr
issue-54570-bootstrapping.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
issue-55219.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
issue-55241.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
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 Extend and use `hir::Node::body_id` 2023-04-19 19:13:45 +00:00
method-ufcs-1.rs
method-ufcs-1.stderr Modify `find_expr` from `Span` to better account for closures 2024-04-24 22:21:13 +00:00
method-ufcs-2.rs
method-ufcs-2.stderr Modify `find_expr` from `Span` to better account for closures 2024-04-24 22:21:13 +00:00
method-ufcs-3.rs
method-ufcs-3.stderr Extend and use `hir::Node::body_id` 2023-04-19 19:13:45 +00:00
method-ufcs-inherent-1.rs
method-ufcs-inherent-1.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
method-ufcs-inherent-2.rs
method-ufcs-inherent-2.stderr
method-ufcs-inherent-3.rs
method-ufcs-inherent-3.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
method-ufcs-inherent-4.rs
method-ufcs-inherent-4.stderr
normalization-2.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
normalization-2.stderr Add a note to duplicate diagnostics 2023-10-05 01:04:41 +00:00
normalization-default.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
normalization-default.stderr
normalization-infer.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
normalization-infer.stderr remove trailing dots 2023-10-08 10:06:17 +00:00
normalization-self.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
normalization-self.stderr
normalization.rs
normalization.stderr
normalize-self-ty.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
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 Show number in error message even for one error 2023-11-24 19:15:52 +01:00
region-error-ice-109072.rs make `type_flags(ReError) & HAS_ERROR` 2024-03-20 17:29:58 +00:00
region-error-ice-109072.stderr make `type_flags(ReError) & HAS_ERROR` 2024-03-20 17:29:58 +00:00
type-annotation-with-hrtb.rs [AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives 2024-02-16 20:02:50 +00:00
type_ascription_static_lifetime.rs
type_ascription_static_lifetime.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
wf-self-type.rs
wf-self-type.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00