E0031
Function body without the value it returns
ErrorA function with a return type must produce a value of that type on every path through its body: as the value of the body's last expression, or with return. A body that ends in a statement such as let, or in nothing, and does not return first, has no value.
Why
The value of a block is the value of its last expression. A caller waits for the function's value, so every path to the end of the body must produce one.
Broken
fn five() -> i64 {
let n = 5
}
fn main() {
print(five())
}
What sisu says
error[E0031]: function `five` must return `i64`, but its body has no value --> E0031.sisu:3:1 | 3 | } | ^ sisu: 1 error sisu: for more on a code, run `sisu explain <code>`: E0031
Fixed
fn five() -> i64 {
let n = 5
n
}
fn main() {
print(five())
}
Sisu