rust/tests/ui/fn
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
..
bad-main.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
bad-main.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
dyn-fn-alignment.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
expr-fn-panic.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
expr-fn.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
fn_def_coercion.rs Add some FnDef LUB coercion tests 2024-04-24 10:05:32 +00:00
fn_def_coercion.stderr Add some FnDef LUB coercion tests 2024-04-24 10:05:32 +00:00
fn_def_opaque_coercion.rs Register hidden types when equating function definitions in coercion 2024-04-24 10:05:33 +00:00
fn-bad-block-type.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
fn-bad-block-type.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
fn-closure-mutable-capture.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
fn-closure-mutable-capture.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
fn-compare-mismatch.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
fn-compare-mismatch.stderr improve fn pointer notes 2023-01-26 05:07:34 +00:00
fn-item-type.rs Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
fn-item-type.stderr Refactored a few bits: 2024-03-15 13:37:41 +00:00
fn-pointer-mismatch.rs recurse into refs when comparing tys for diagnostics 2023-12-07 23:00:46 -05:00
fn-pointer-mismatch.stderr recurse into refs when comparing tys for diagnostics 2023-12-07 23:00:46 -05:00
fn-ptr-trait-int-float-infer-var.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
fn-ptr-trait.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
fn-recover-return-sign2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
fn-recover-return-sign2.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
fn-recover-return-sign.fixed [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
fn-recover-return-sign.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
fn-recover-return-sign.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
fn-trait-formatting.rs Pretty print Fn traits in rustc_on_unimplemented 2023-11-02 20:57:05 +00:00
fn-trait-formatting.stderr Pretty print Fn traits in rustc_on_unimplemented 2023-11-02 20:57:05 +00:00
fun-call-variants.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
implied-bounds-impl-header-projections.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
implied-bounds-unnorm-associated-type-2.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
implied-bounds-unnorm-associated-type-2.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
implied-bounds-unnorm-associated-type-3.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
implied-bounds-unnorm-associated-type-4.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
implied-bounds-unnorm-associated-type-4.stderr Account for unops when suggesting cloning 2024-04-11 16:41:41 +00:00
implied-bounds-unnorm-associated-type-5.rs Continue compilation after check_mod_type_wf errors 2024-02-14 11:00:30 +00:00
implied-bounds-unnorm-associated-type-5.stderr Account for unops when suggesting cloning 2024-04-11 16:41:41 +00:00
implied-bounds-unnorm-associated-type.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
implied-bounds-unnorm-associated-type.stderr Account for unops when suggesting cloning 2024-04-11 16:41:41 +00:00
issue-1451.rs Move some tests 2024-03-31 14:58:17 -03:00
issue-1900.rs Move some tests 2024-03-31 14:58:17 -03:00
issue-1900.stderr Move some tests 2024-03-31 14:58:17 -03:00
issue-3044.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-3044.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-3099.rs Move tests 2023-05-08 17:58:01 -03:00
issue-3099.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-3904.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-39259.rs Avoid silencing relevant follow-up errors 2024-01-09 21:08:16 +00:00
issue-39259.stderr Avoid silencing relevant follow-up errors 2024-01-09 21:08:16 +00:00
issue-80179.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-80179.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
keyword-order.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
keyword-order.stderr Add explanatory note to 'expected item' error 2023-09-06 09:05:07 +05:30
nested-function-names-issue-8587.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
signature-error-reporting-under-verbose.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
signature-error-reporting-under-verbose.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
suggest-return-closure.rs Modify find_expr from Span to better account for closures 2024-04-24 22:21:13 +00:00
suggest-return-closure.stderr Modify find_expr from Span to better account for closures 2024-04-24 22:21:13 +00:00
suggest-return-future.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
suggest-return-future.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00