You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 28, 2025. It is now read-only.
and replace it with a simple note suggesting
returning a value.
The type mismatch error was never due to
how many times the loop iterates. It is more
because of the peculiar structure of what the for
loop desugars to. So the note talking about
iteration count didn't make sense
Copy file name to clipboardExpand all lines: tests/ui/for-loop-while/break-while-condition.stderr
+11-7Lines changed: 11 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,12 @@ LL | | }
20
20
|
21
21
= note: expected type `!`
22
22
found unit type `()`
23
+
= note: `while` loops evaluate to unit type `()`
24
+
help: consider adding a diverging expression here
25
+
|
26
+
LL ~ }
27
+
LL + /* `loop {}` or `panic!("...")` */
28
+
|
23
29
24
30
error[E0308]: mismatched types
25
31
--> $DIR/break-while-condition.rs:24:13
@@ -31,14 +37,12 @@ LL | | }
31
37
|
32
38
= note: expected type `!`
33
39
found unit type `()`
34
-
note: the function expects a value to always be returned, but loops might run zero times
35
-
--> $DIR/break-while-condition.rs:24:13
40
+
= note: `while` loops evaluate to unit type `()`
41
+
help: consider adding a diverging expression here
42
+
|
43
+
LL ~ }
44
+
LL + /* `loop {}` or `panic!("...")` */
36
45
|
37
-
LL | while false {
38
-
| ^^^^^^^^^^^ this might have zero elements to iterate on
39
-
LL | return
40
-
| ------ if the loop doesn't execute, this value would never get returned
41
-
= help: return a value for the case when the loop has zero elements to iterate on, otherwise consider changing the return type to account for that possibility
0 commit comments