Closed
Description
fn loop_ending() -> i32 {
loop {
if false { break; }
return 42;
}
}
produces
error[E0308]: mismatched types
--> <anon>:2:5
|
2 | loop {
| _____^ starting here...
3 | | if false { break; }
4 | | return 42;
5 | | }
| |_____^ ...ending here: expected i32, found ()
|
= note: expected type `i32`
= note: found type `()`
error: aborting due to previous error
But the compiler can check that the final expression is a loop and must always evaluate into ()
, so we can recommend more advanced information.
This has caused real confusion.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsCategory: An issue proposing an enhancement or a PR with one.Diagnostics: Confusing error or lint that should be reworked.Diagnostics: An error or lint that needs small tweaks.Relevant to the compiler team, which will review and decide on the PR/issue.Working group: Diagnostics