rustc does not recognize a return inside a break expression for purposes of checking that every code path has the function return type #77156
Labels
A-control-flow
Area: Control flow
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
I tried this code:
I expected that this would compile. Instead rustc says (on 1.48.0 nightly 2020-09-23):
As a sanity check, I also tested this:
This compiles and when run prints
5
, indicating that that expression is indeed the place the function returns. Looking at the function it's also clearly an unconditionally reached return. Comparewhich also compiles and runs without error.
On the same theme, I was worried that this might erroneously typecheck:
but it doesn't, indicating the compiler is quite cognizant that the value returned in this position has to unify with the return type.
The text was updated successfully, but these errors were encountered: