-
Notifications
You must be signed in to change notification settings - Fork 14k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
The following code:
#![allow(dead_code)]
fn forgot_to_return() -> usize {
while 4 > 3 {
/* do something */
}
}
fn main() {
let _ = forgot_to_return();
}Gives the error message:
<anon>:4:5: 6:6 error: mismatched types:
expected `usize`,
found `()`
(expected usize,
found ()) [E0308]
<anon>:4 while 4 > 3 {
<anon>:5 /* do something */
<anon>:6 }
error: aborting due to previous error
Playpen: http://is.gd/0sudKI
This is confusing, since it looks like the type of either 4 or 3 is () - it is not clear that the actual error is that the while loop is being treated as the final expression in the function, and its type does match the return type of the function.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.