E0013 — Missing return on a code path
A function with a non-void declared return type has a path that falls off the end without returning a value.
What triggers it
Control-flow analysis over the function body finds at least one
branch (commonly the else-less side of an if) that reaches the
closing } without executing a return.
Minimal example
fn sign(int n) -> int {
if n > 0 {
return 1;
}
}
Output:
scratch.rz:1:1: error[E0013]: missing return in function `sign`
fn sign(int n) -> int {
^^^^^^^^^^^^^^^^^^^^^^^
Fix
Cover every path with an explicit return, including the
fall-through / else case.
fn sign(int n) -> int {
if n > 0 {
return 1;
}
return -1;
}
Source
Emitted from the typechecker’s return-path exhaustiveness check in
resilient/src/typechecker.rs.