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
when loop as tail expression for miss match type E0308 error, recursively get
the return statement and add diagnostic information on it
use rustc_hir::intravisit to collect the return expression
modified: compiler/rustc_typeck/src/check/coercion.rs
new file: src/test/ui/typeck/issue-98982.rs
new file: src/test/ui/typeck/issue-98982.stderr
Copy file name to clipboardExpand all lines: src/test/ui/for-loop-while/break-while-condition.stderr
+8
Original file line number
Diff line number
Diff line change
@@ -31,6 +31,14 @@ LL | | }
31
31
|
32
32
= note: expected type `!`
33
33
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
36
+
|
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, or consider changing the return type to account for that possibility
//~| help: return a value for the case when the loop has zero elements to iterate on, or consider changing the return type to account for that possibility
note: the function expects a value to always be returned, but loops might run zero times
13
+
--> $DIR/issue-98982.rs:2:5
14
+
|
15
+
LL | for i in 0..0 {
16
+
| ^^^^^^^^^^^^^ this might have zero elements to iterate on
17
+
LL |
18
+
LL | return i;
19
+
| -------- if the loop doesn't execute, this value would never get returned
20
+
= help: return a value for the case when the loop has zero elements to iterate on, or consider changing the return type to account for that possibility
21
+
22
+
error: aborting due to previous error
23
+
24
+
For more information about this error, try `rustc --explain E0308`.
0 commit comments