-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.T-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
When encountering a function with an explicit return type, but the function body doesn't return anything, we should inspect the body's bindings and point out all that have an appropriate type:
fn foo() -> Option<i32> {
let x: Option<i32> = Some(42);
}
error[E0308]: mismatched types
--> src/lib.rs:1:13
|
1 | fn foo() -> Option<i32> {
| --- ^^^^^^^^^^^ expected enum `Option`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
2 | let x = Some(42);
| - this binding is of the expected return type, you might have meant to `return` it
|
= note: expected enum `Option<i32>`
found unit type `()`
Potentially consider the implications of lifetimes, particularly for bindings that are a borrowed value. Also make an effort not to drown the output if more than N bindings would apply in really big functions.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.T-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.