os-rust/tests/ui/for-loop-while
Esteban Küber 45efb8e6a6 Provide structured suggestion for type mismatch in loop
We currently provide only a `help` message, this PR introduces the last
two structured suggestions instead:

```
error[E0308]: mismatched types
  --> $DIR/issue-98982.rs:2:5
   |
LL |   fn foo() -> i32 {
   |               --- expected `i32` because of return type
LL | /     for i in 0..0 {
LL | |         return i;
LL | |     }
   | |_____^ expected `i32`, found `()`
   |
note: the function expects a value to always be returned, but loops might run zero times
  --> $DIR/issue-98982.rs:2:5
   |
LL |     for i in 0..0 {
   |     ^^^^^^^^^^^^^ this might have zero elements to iterate on
LL |         return i;
   |         -------- if the loop doesn't execute, this value would never get returned
help: return a value for the case when the loop has zero elements to iterate on
   |
LL ~     }
LL ~     /* `i32` value */
   |
help: otherwise consider changing the return type to account for that possibility
   |
LL ~ fn foo() -> Option<i32> {
LL |     for i in 0..0 {
LL ~         return Some(i);
LL ~     }
LL ~     None
   |
```

Fix #98982.
2023-11-22 19:56:53 +00:00
..
auto-loop.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
break-outside-loop.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
break-outside-loop.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
break-value.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
break-while-condition.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
break-while-condition.stderr Provide structured suggestion for type mismatch in loop 2023-11-22 19:56:53 +00:00
break.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
cleanup-rvalue-during-if-and-while.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
for-destruct.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
for-loop-goofiness.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
for-loop-has-unit-body.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
for-loop-into-iterator.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
for-loop-lifetime-of-unbound-values.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
for-loop-macro.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
for-loop-mut-ref-element.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
for-loop-no-std.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
for-loop-panic.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
for-loop-unconstrained-element-type-i32-fallback.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
foreach-external-iterators-break.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
foreach-external-iterators-hashmap-break-restart.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
foreach-external-iterators-hashmap.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
foreach-external-iterators-loop.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
foreach-external-iterators-nested.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
foreach-external-iterators.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
foreach-nested.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
foreach-put-structured.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
foreach-simple-outer-slot.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-1257.rs Move tests 2023-05-24 19:35:59 -03:00
issue-2216.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-51345.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-69841.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
label_break_value.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
label_break_value_invalid.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
label_break_value_invalid.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
labeled-break.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
linear-for-loop.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
liveness-assign-imm-local-after-loop.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
liveness-loop-break.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
liveness-move-in-loop.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
long-while.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
loop-break-cont-1.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
loop-break-cont.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
loop-break-value.rs Adjust UI tests for unit_bindings 2023-06-12 20:24:48 +08:00
loop-diverges.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
loop-label-shadowing.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
loop-labeled-break-value.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
loop-no-reinit-needed-post-bot.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
loop-scope.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
while-cont.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
while-flow-graph.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
while-label.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
while-let-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
while-let-2.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
while-let.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
while-loop-constraints-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
while-prelude-drop.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
while-with-break.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
while.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00