rust/compiler/rustc_borrowck/src
Esteban Küber 78d29ad8d6 Point at continue and break that might be in the wrong place
Sometimes move errors are because of a misplaced `continue`, but we didn't
surface that anywhere. Now when there are more than one set of nested loops
we show them out and point at the `continue` and `break` expressions within
that might need to go elsewhere.

```
error[E0382]: use of moved value: `foo`
  --> $DIR/nested-loop-moved-value-wrong-continue.rs:46:18
   |
LL |     for foo in foos {
   |         ---
   |         |
   |         this reinitialization might get skipped
   |         move occurs because `foo` has type `String`, which does not implement the `Copy` trait
...
LL |         for bar in &bars {
   |         ---------------- inside of this loop
...
LL |                 baz.push(foo);
   |                          --- value moved here, in previous iteration of loop
...
LL |         qux.push(foo);
   |                  ^^^ value used here after move
   |
note: verify that your loop breaking logic is correct
  --> $DIR/nested-loop-moved-value-wrong-continue.rs:41:17
   |
LL |     for foo in foos {
   |     ---------------
...
LL |         for bar in &bars {
   |         ----------------
...
LL |                 continue;
   |                 ^^^^^^^^ this `continue` advances the loop at line 33
help: consider moving the expression out of the loop so it is only moved once
   |
LL ~         let mut value = baz.push(foo);
LL ~         for bar in &bars {
LL |
 ...
LL |             if foo == *bar {
LL ~                 value;
   |
help: consider cloning the value if the performance cost is acceptable
   |
LL |                 baz.push(foo.clone());
   |                             ++++++++
```

Fix #92531.
2024-03-17 21:32:26 +00:00
..
constraints Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
diagnostics Point at continue and break that might be in the wrong place 2024-03-17 21:32:26 +00:00
polonius Implement asm goto in MIR and MIR lowering 2024-02-24 18:50:09 +00:00
region_infer Eliminate DefiningAnchor::Error, it is indistinguishable from DefiningAnchor::Bind with an empty list 2024-03-11 17:19:37 +00:00
type_check Distinguish between library and lang UB in assert_unsafe_precondition 2024-03-08 18:53:58 -05:00
util Move some utils out of rustc_const_eval 2023-04-16 12:05:54 +02:00
borrow_set.rs Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
borrowck_errors.rs Rename DiagnosticBuilder as Diag. 2024-02-28 08:55:35 +11:00
consumers.rs Make DefiningAnchor::Bind only store the opaque types that may be constrained, instead of the current infcx root item. 2024-03-11 17:19:37 +00:00
dataflow.rs Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
def_use.rs Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
facts.rs Move trait into attr so it's greppable 2024-02-16 15:07:37 +00:00
lib.rs Make DefiningAnchor::Bind only store the opaque types that may be constrained, instead of the current infcx root item. 2024-03-11 17:19:37 +00:00
location.rs Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
member_constraints.rs Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
nll.rs Avoid a span_delayed_bug in compute_regions. 2024-02-27 16:40:13 +11:00
path_utils.rs remove a bunch of dead parameters in fn 2024-02-12 09:51:35 +08:00
place_ext.rs Move trait into attr so it's greppable 2024-02-16 15:07:37 +00:00
places_conflict.rs Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
prefixes.rs cleanup prefixes iterator 2024-03-13 12:34:58 -07:00
renumber.rs Invert diagnostic lints. 2024-02-06 13:12:33 +11:00
session_diagnostics.rs Account for UnOps in borrowck message 2024-03-13 23:05:17 +00:00
universal_regions.rs Rename DiagnosticBuilder as Diag. 2024-02-28 08:55:35 +11:00
used_muts.rs Bump indexmap 2024-02-13 21:03:34 +00:00