Closed
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.