rust/tests
bors cb3752d20e Auto merge of #124136 - estebank:clone-o-rama-2, r=nnethercote
Provide more context and suggestions in borrowck errors involving closures

Start pointing to where bindings where 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 } => {},
   |                                         ++++++++
```

Mention when type parameter could be Clone

```
error[E0382]: use of moved value: `t`
  --> $DIR/use_of_moved_value_copy_suggestions.rs:7:9
   |
LL | fn duplicate_t<T>(t: T) -> (T, T) {
   |                   - move occurs because `t` has type `T`, which does not implement the `Copy` trait
...
LL |     (t, t)
   |      -  ^ value used here after move
   |      |
   |      value moved here
   |
help: if `T` implemented `Clone`, you could clone the value
  --> $DIR/use_of_moved_value_copy_suggestions.rs:4:16
   |
LL | fn duplicate_t<T>(t: T) -> (T, T) {
   |                ^ consider constraining this type parameter with `Clone`
...
LL |     (t, t)
   |      - you could clone this value
help: consider restricting type parameter `T`
   |
LL | fn duplicate_t<T: Copy>(t: T) -> (T, T) {
   |                 ++++++
```

The `help` is new. On ADTs, we also extend the output with span labels:

```
error[E0507]: cannot move out of static item `FOO`
  --> $DIR/issue-17718-static-move.rs:6:14
   |
LL |     let _a = FOO;
   |              ^^^ move occurs because `FOO` has type `Foo`, which does not implement the `Copy` trait
   |
note: if `Foo` implemented `Clone`, you could clone the value
  --> $DIR/issue-17718-static-move.rs:1:1
   |
LL | struct Foo;
   | ^^^^^^^^^^ consider implementing `Clone` for this type
...
LL |     let _a = FOO;
   |              --- you could clone this value
help: consider borrowing here
   |
LL |     let _a = &FOO;
   |              +
```

Suggest cloning captured binding in move closure

```
error[E0507]: cannot move out of `bar`, a captured variable in an `FnMut` closure
  --> $DIR/borrowck-move-by-capture.rs:9:29
   |
LL |     let bar: Box<_> = Box::new(3);
   |         --- captured outer variable
LL |     let _g = to_fn_mut(|| {
   |                        -- captured by this `FnMut` closure
LL |         let _h = to_fn_once(move || -> isize { *bar });
   |                             ^^^^^^^^^^^^^^^^   ----
   |                             |                  |
   |                             |                  variable moved due to use in closure
   |                             |                  move occurs because `bar` has type `Box<isize>`, which does not implement the `Copy` trait
   |                             `bar` is moved here
   |
help: clone the value before moving it into the closure 1
   |
LL ~         let value = bar.clone();
LL ~         let _h = to_fn_once(move || -> isize { value });
   |
```
2024-04-25 01:00:41 +00:00
..
assembly also update windows slack-protector tests 2024-04-22 23:45:04 -04:00
auxiliary
codegen Fix tests and bless 2024-04-24 13:12:33 +01:00
codegen-units
coverage Error on using yield without also using #[coroutine] on the closure 2024-04-24 08:05:29 +00:00
coverage-run-rustdoc
crashes Rollup merge of #123993 - compiler-errors:coroutine-obl, r=lcnr 2024-04-23 17:25:16 +02:00
debuginfo Error on using yield without also using #[coroutine] on the closure 2024-04-24 08:05:29 +00:00
incremental
mir-opt Fix tests and bless 2024-04-24 13:12:33 +01:00
pretty Fix tests and bless 2024-04-24 13:12:33 +01:00
run-make Improve diagnostic for unknown --print request 2024-04-24 15:52:01 +02:00
run-make-fulldeps
run-pass-valgrind
rustdoc Auto merge of #118441 - GuillaumeGomez:display-stability-version, r=rustdoc 2024-04-19 14:17:29 +00:00
rustdoc-gui Rollup merge of #124197 - GuillaumeGomez:move-duplicated-code, r=notriddle 2024-04-23 06:24:56 +02:00
rustdoc-js rustdoc-search: single result for items with multiple paths 2024-04-08 17:07:14 -07:00
rustdoc-js-std rustdoc-search: fix description on aliases in results 2024-04-18 22:21:29 -07:00
rustdoc-json
rustdoc-ui Rollup merge of #122591 - gurry:122162-impl-type-binding-suggestion, r=fmease 2024-04-23 17:25:14 +02:00
ui Auto merge of #124136 - estebank:clone-o-rama-2, r=nnethercote 2024-04-25 01:00:41 +00:00
ui-fulldeps Rollup merge of #124218 - Xiretza:subsubdiagnostics, r=davidtwco 2024-04-23 17:25:17 +02:00
COMPILER_TESTS.md