Diverging expression not detected inside a while
condition
#141274
Labels
A-inference
Area: Type inference
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
T-lang
Relevant to the language team
T-types
Relevant to the types team, which will review and decide on the PR/issue.
I tried this code:
I expected the code to compile. Instead, I got the following compile error:
Note that I can use uninitialized variables in the unreachable code, which indicates that the compiler realizes that the expression diverges. For example, this code compiles fine:
Usually, when a diverging expression appears in a block, rust no longer checks if the last expression in the block has the expected type. For example, this code compiles fine:
Although, strangely enough, leaving the
if
as the last expression causes the code to again not compile:All of this seems rather inconsistent.
This was discovered while experimenting with #118673
Meta
Reproducible on the playground with stable rust 1.87.0.
The text was updated successfully, but these errors were encountered: